[FIX] account_move_template: fix JS crash in analytic distribution
Add _check_company_auto = True where relevant Fix layout of account.move.template form view Code cleanup
This commit is contained in:
parent
e85ddb6842
commit
35e45894ec
@ -9,6 +9,7 @@ from odoo.tools.safe_eval import safe_eval
|
|||||||
class AccountMoveTemplate(models.Model):
|
class AccountMoveTemplate(models.Model):
|
||||||
_name = "account.move.template"
|
_name = "account.move.template"
|
||||||
_description = "Journal Entry Template"
|
_description = "Journal Entry Template"
|
||||||
|
_check_company_auto = True
|
||||||
|
|
||||||
name = fields.Char(required=True)
|
name = fields.Char(required=True)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
@ -18,7 +19,13 @@ class AccountMoveTemplate(models.Model):
|
|||||||
ondelete="cascade",
|
ondelete="cascade",
|
||||||
default=lambda self: self.env.company,
|
default=lambda self: self.env.company,
|
||||||
)
|
)
|
||||||
journal_id = fields.Many2one("account.journal", string="Journal", required=True)
|
journal_id = fields.Many2one(
|
||||||
|
"account.journal",
|
||||||
|
string="Journal",
|
||||||
|
required=True,
|
||||||
|
check_company=True,
|
||||||
|
domain="[('company_id', '=', company_id)]",
|
||||||
|
)
|
||||||
ref = fields.Char(string="Reference", copy=False)
|
ref = fields.Char(string="Reference", copy=False)
|
||||||
line_ids = fields.One2many(
|
line_ids = fields.One2many(
|
||||||
"account.move.template.line", inverse_name="template_id", string="Lines"
|
"account.move.template.line", inverse_name="template_id", string="Lines"
|
||||||
@ -106,27 +113,29 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
_name = "account.move.template.line"
|
_name = "account.move.template.line"
|
||||||
_description = "Journal Item Template"
|
_description = "Journal Item Template"
|
||||||
_order = "sequence, id"
|
_order = "sequence, id"
|
||||||
|
_inherit = "analytic.mixin"
|
||||||
|
_check_company_auto = True
|
||||||
|
|
||||||
template_id = fields.Many2one(
|
template_id = fields.Many2one(
|
||||||
"account.move.template", string="Move Template", ondelete="cascade"
|
"account.move.template", string="Move Template", ondelete="cascade"
|
||||||
)
|
)
|
||||||
name = fields.Char(string="Label", required=True)
|
name = fields.Char(string="Label")
|
||||||
sequence = fields.Integer(required=True)
|
sequence = fields.Integer(required=True)
|
||||||
account_id = fields.Many2one(
|
account_id = fields.Many2one(
|
||||||
"account.account",
|
"account.account",
|
||||||
string="Account",
|
string="Account",
|
||||||
required=True,
|
required=True,
|
||||||
domain=[("deprecated", "=", False)],
|
domain="[('company_id', '=', company_id), ('deprecated', '=', False)]",
|
||||||
|
check_company=True,
|
||||||
)
|
)
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
"res.partner",
|
"res.partner",
|
||||||
string="Partner",
|
string="Partner",
|
||||||
domain=["|", ("parent_id", "=", False), ("is_company", "=", True)],
|
domain=["|", ("parent_id", "=", False), ("is_company", "=", True)],
|
||||||
)
|
)
|
||||||
analytic_distribution = fields.Json(string="New Analytic Distribution")
|
tax_ids = fields.Many2many("account.tax", string="Taxes", check_company=True)
|
||||||
tax_ids = fields.Many2many("account.tax", string="Taxes")
|
|
||||||
tax_line_id = fields.Many2one(
|
tax_line_id = fields.Many2one(
|
||||||
"account.tax", string="Originator Tax", ondelete="restrict"
|
"account.tax", string="Originator Tax", ondelete="restrict", check_company=True
|
||||||
)
|
)
|
||||||
company_id = fields.Many2one(related="template_id.company_id", store=True)
|
company_id = fields.Many2one(related="template_id.company_id", store=True)
|
||||||
company_currency_id = fields.Many2one(
|
company_currency_id = fields.Many2one(
|
||||||
@ -136,11 +145,14 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
)
|
)
|
||||||
note = fields.Char()
|
note = fields.Char()
|
||||||
type = fields.Selection(
|
type = fields.Selection(
|
||||||
[("computed", "Computed"), ("input", "User input")],
|
[
|
||||||
|
("input", "User input"),
|
||||||
|
("computed", "Computed"),
|
||||||
|
],
|
||||||
required=True,
|
required=True,
|
||||||
default="input",
|
default="input",
|
||||||
)
|
)
|
||||||
python_code = fields.Text()
|
python_code = fields.Text(string="Formula")
|
||||||
move_line_type = fields.Selection(
|
move_line_type = fields.Selection(
|
||||||
[("cr", "Credit"), ("dr", "Debit")], required=True, string="Direction"
|
[("cr", "Credit"), ("dr", "Debit")], required=True, string="Direction"
|
||||||
)
|
)
|
||||||
@ -158,12 +170,12 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
string="Tax Repartition Line",
|
string="Tax Repartition Line",
|
||||||
compute="_compute_tax_repartition_line_id",
|
compute="_compute_tax_repartition_line_id",
|
||||||
store=True,
|
store=True,
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
opt_account_id = fields.Many2one(
|
opt_account_id = fields.Many2one(
|
||||||
"account.account",
|
"account.account",
|
||||||
string="Account Opt.",
|
string="Account Opt.",
|
||||||
domain=[("deprecated", "=", False)],
|
domain="[('company_id', '=', company_id), ('deprecated', '=', False)]",
|
||||||
|
check_company=True,
|
||||||
help="When amount is negative, use this account instead",
|
help="When amount is negative, use this account instead",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -181,6 +193,23 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
limit=1,
|
limit=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.depends("account_id", "partner_id")
|
||||||
|
def _compute_analytic_distribution(self):
|
||||||
|
for line in self:
|
||||||
|
distribution = self.env[
|
||||||
|
"account.analytic.distribution.model"
|
||||||
|
]._get_distribution(
|
||||||
|
{
|
||||||
|
"partner_id": line.partner_id.id,
|
||||||
|
"partner_category_id": line.partner_id.category_id.ids,
|
||||||
|
"product_id": False,
|
||||||
|
"product_categ_id": False,
|
||||||
|
"account_prefix": line.account_id.code,
|
||||||
|
"company_id": line.template_id.company_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
line.analytic_distribution = distribution or line.analytic_distribution
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
(
|
(
|
||||||
"sequence_template_uniq",
|
"sequence_template_uniq",
|
||||||
@ -194,6 +223,6 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
for line in self:
|
for line in self:
|
||||||
if line.type == "computed" and not line.python_code:
|
if line.type == "computed" and not line.python_code:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Python Code must be set for computed line with " "sequence %d.")
|
_("Python Code must be set for computed line with sequence %d.")
|
||||||
% line.sequence
|
% line.sequence
|
||||||
)
|
)
|
||||||
|
@ -6,11 +6,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree>
|
<tree>
|
||||||
<field name="sequence" />
|
<field name="sequence" />
|
||||||
<field name="account_id" domain="[('company_id', '=', company_id)]" />
|
<field name="account_id" />
|
||||||
<field
|
<field name="opt_account_id" />
|
||||||
name="opt_account_id"
|
|
||||||
domain="[('company_id', '=', company_id)]"
|
|
||||||
/>
|
|
||||||
<field name="partner_id" />
|
<field name="partner_id" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field
|
<field
|
||||||
@ -40,38 +37,20 @@
|
|||||||
<form string="Journal Entry Template Line">
|
<form string="Journal Entry Template Line">
|
||||||
<sheet>
|
<sheet>
|
||||||
<group name="main">
|
<group name="main">
|
||||||
<group name="account">
|
<group name="main-left">
|
||||||
<field name="sequence" />
|
<field name="sequence" />
|
||||||
<field name="name" />
|
<field name="account_id" />
|
||||||
<field
|
<field name="opt_account_id" />
|
||||||
name="account_id"
|
|
||||||
domain="[('company_id', '=', company_id)]"
|
|
||||||
/>
|
|
||||||
<field
|
|
||||||
name="opt_account_id"
|
|
||||||
domain="[('company_id', '=', company_id)]"
|
|
||||||
/>
|
|
||||||
<field name="partner_id" />
|
<field name="partner_id" />
|
||||||
<field name="payment_term_id" />
|
<field name="name" />
|
||||||
<field name="company_id" invisible="1" />
|
|
||||||
</group>
|
|
||||||
<group
|
|
||||||
groups="analytic.group_analytic_accounting"
|
|
||||||
string="Analytic"
|
|
||||||
name="analytic"
|
|
||||||
>
|
|
||||||
<field
|
<field
|
||||||
name="analytic_distribution"
|
name="analytic_distribution"
|
||||||
widget="analytic_distribution"
|
widget="analytic_distribution"
|
||||||
groups="analytic.group_analytic_accounting"
|
groups="analytic.group_analytic_accounting"
|
||||||
|
options="{'account_field': 'account_id'}"
|
||||||
/>
|
/>
|
||||||
</group>
|
|
||||||
<group name="amount" string="Amount">
|
<field name="payment_term_id" />
|
||||||
<field name="move_line_type" />
|
|
||||||
<field name="type" />
|
|
||||||
<field name="note" />
|
|
||||||
</group>
|
|
||||||
<group string="Taxes" name="tax">
|
|
||||||
<field name="is_refund" />
|
<field name="is_refund" />
|
||||||
<field name="tax_line_id" />
|
<field name="tax_line_id" />
|
||||||
<field
|
<field
|
||||||
@ -79,15 +58,19 @@
|
|||||||
attrs="{'invisible': [('tax_line_id','=',False)]}"
|
attrs="{'invisible': [('tax_line_id','=',False)]}"
|
||||||
/>
|
/>
|
||||||
<field name="tax_ids" widget="many2many_tags" />
|
<field name="tax_ids" widget="many2many_tags" />
|
||||||
|
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
<group name="main-right">
|
||||||
<group
|
<field name="move_line_type" />
|
||||||
name="python_code"
|
<field name="type" widget="radio" />
|
||||||
attrs="{'invisible': [('type', '!=', 'computed')]}"
|
<field name="note" />
|
||||||
col="1"
|
>
|
||||||
string="Compute Formula"
|
<div
|
||||||
|
name="python_code_help"
|
||||||
|
colspan="2"
|
||||||
|
attrs="{'invisible': [('type', '!=', 'computed')]}"
|
||||||
>
|
>
|
||||||
<div class="oe_account_help">
|
|
||||||
<p
|
<p
|
||||||
>You can refer to other lines using their sequence number e.g. <i
|
>You can refer to other lines using their sequence number e.g. <i
|
||||||
>L1</i> for line with sequence = 1. Examples:</p>
|
>L1</i> for line with sequence = 1. Examples:</p>
|
||||||
@ -100,10 +83,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<field
|
<field
|
||||||
name="python_code"
|
name="python_code"
|
||||||
nolabel="1"
|
attrs="{'invisible': [('type', '!=', 'computed')], 'required': [('type', '=', 'computed')]}"
|
||||||
attrs="{'required': [('type', '=', 'computed')]}"
|
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
@ -9,8 +9,14 @@ from odoo.exceptions import UserError, ValidationError
|
|||||||
class AccountMoveTemplateRun(models.TransientModel):
|
class AccountMoveTemplateRun(models.TransientModel):
|
||||||
_name = "account.move.template.run"
|
_name = "account.move.template.run"
|
||||||
_description = "Wizard to generate move from template"
|
_description = "Wizard to generate move from template"
|
||||||
|
_check_company_auto = True
|
||||||
|
|
||||||
template_id = fields.Many2one("account.move.template", required=True)
|
template_id = fields.Many2one(
|
||||||
|
"account.move.template",
|
||||||
|
required=True,
|
||||||
|
check_company=True,
|
||||||
|
domain="[('company_id', '=', company_id)]",
|
||||||
|
)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
"res.company",
|
"res.company",
|
||||||
required=True,
|
required=True,
|
||||||
@ -66,16 +72,6 @@ Valid dictionary to overwrite template lines:
|
|||||||
# Verify and get overwrite dict
|
# Verify and get overwrite dict
|
||||||
overwrite_vals = self._get_overwrite_vals()
|
overwrite_vals = self._get_overwrite_vals()
|
||||||
amtlro = self.env["account.move.template.line.run"]
|
amtlro = self.env["account.move.template.line.run"]
|
||||||
if self.company_id != self.template_id.company_id:
|
|
||||||
raise UserError(
|
|
||||||
_(
|
|
||||||
"The selected template (%(template)s) is not in the same company "
|
|
||||||
"(%(company)s) as the current user (%(user_company)s).",
|
|
||||||
template=self.template_id.name,
|
|
||||||
company=self.template_id.company_id.display_name,
|
|
||||||
user_company=self.company_id.display_name,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
tmpl_lines = self.template_id.line_ids
|
tmpl_lines = self.template_id.line_ids
|
||||||
for tmpl_line in tmpl_lines.filtered(lambda l: l.type == "input"):
|
for tmpl_line in tmpl_lines.filtered(lambda l: l.type == "input"):
|
||||||
vals = self._prepare_wizard_line(tmpl_line)
|
vals = self._prepare_wizard_line(tmpl_line)
|
||||||
@ -89,8 +85,9 @@ Valid dictionary to overwrite template lines:
|
|||||||
)
|
)
|
||||||
if not self.line_ids:
|
if not self.line_ids:
|
||||||
return self.generate_move()
|
return self.generate_move()
|
||||||
action = self.env.ref("account_move_template.account_move_template_run_action")
|
result = self.env["ir.actions.actions"]._for_xml_id(
|
||||||
result = action.sudo().read()[0]
|
"account_move_template.account_move_template_run_action"
|
||||||
|
)
|
||||||
result.update({"res_id": self.id, "context": self.env.context})
|
result.update({"res_id": self.id, "context": self.env.context})
|
||||||
|
|
||||||
# Overwrite self.line_ids to show overwrite values
|
# Overwrite self.line_ids to show overwrite values
|
||||||
@ -98,9 +95,7 @@ Valid dictionary to overwrite template lines:
|
|||||||
# Pass context furtner to generate_move function, only readonly field
|
# Pass context furtner to generate_move function, only readonly field
|
||||||
for key in overwrite_vals.keys():
|
for key in overwrite_vals.keys():
|
||||||
overwrite_vals[key].pop("amount", None)
|
overwrite_vals[key].pop("amount", None)
|
||||||
context = result.get("context", {}).copy()
|
result["context"] = dict(result.get("context", {}), overwrite=overwrite_vals)
|
||||||
context.update({"overwrite": overwrite_vals})
|
|
||||||
result["context"] = context
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_valid_keys(self):
|
def _get_valid_keys(self):
|
||||||
@ -187,8 +182,9 @@ Valid dictionary to overwrite template lines:
|
|||||||
Command.create(self._prepare_move_line(line, amount))
|
Command.create(self._prepare_move_line(line, amount))
|
||||||
)
|
)
|
||||||
move = self.env["account.move"].create(move_vals)
|
move = self.env["account.move"].create(move_vals)
|
||||||
action = self.env.ref("account.action_move_journal_line")
|
result = self.env["ir.actions.actions"]._for_xml_id(
|
||||||
result = action.sudo().read()[0]
|
"account.action_move_journal_line"
|
||||||
|
)
|
||||||
result.update(
|
result.update(
|
||||||
{
|
{
|
||||||
"name": _("Entry from template %s") % self.template_id.name,
|
"name": _("Entry from template %s") % self.template_id.name,
|
||||||
@ -225,9 +221,8 @@ Valid dictionary to overwrite template lines:
|
|||||||
"partner_id": self.partner_id.id or line.partner_id.id,
|
"partner_id": self.partner_id.id or line.partner_id.id,
|
||||||
"date_maturity": date_maturity or self.date,
|
"date_maturity": date_maturity or self.date,
|
||||||
"tax_repartition_line_id": line.tax_repartition_line_id.id or False,
|
"tax_repartition_line_id": line.tax_repartition_line_id.id or False,
|
||||||
|
"analytic_distribution": line.analytic_distribution,
|
||||||
}
|
}
|
||||||
if line.analytic_distribution:
|
|
||||||
values["analytic_distribution"] = line.analytic_distribution
|
|
||||||
if line.tax_ids:
|
if line.tax_ids:
|
||||||
values["tax_ids"] = [Command.set(line.tax_ids.ids)]
|
values["tax_ids"] = [Command.set(line.tax_ids.ids)]
|
||||||
tax_repartition = "refund_tax_id" if line.is_refund else "invoice_tax_id"
|
tax_repartition = "refund_tax_id" if line.is_refund else "invoice_tax_id"
|
||||||
@ -264,6 +259,7 @@ Valid dictionary to overwrite template lines:
|
|||||||
class AccountMoveTemplateLineRun(models.TransientModel):
|
class AccountMoveTemplateLineRun(models.TransientModel):
|
||||||
_name = "account.move.template.line.run"
|
_name = "account.move.template.line.run"
|
||||||
_description = "Wizard Lines to generate move from template"
|
_description = "Wizard Lines to generate move from template"
|
||||||
|
_inherit = "analytic.mixin"
|
||||||
|
|
||||||
wizard_id = fields.Many2one("account.move.template.run", ondelete="cascade")
|
wizard_id = fields.Many2one("account.move.template.run", ondelete="cascade")
|
||||||
company_id = fields.Many2one(related="wizard_id.company_id")
|
company_id = fields.Many2one(related="wizard_id.company_id")
|
||||||
@ -273,7 +269,6 @@ class AccountMoveTemplateLineRun(models.TransientModel):
|
|||||||
sequence = fields.Integer(required=True)
|
sequence = fields.Integer(required=True)
|
||||||
name = fields.Char(readonly=True)
|
name = fields.Char(readonly=True)
|
||||||
account_id = fields.Many2one("account.account", required=True, readonly=True)
|
account_id = fields.Many2one("account.account", required=True, readonly=True)
|
||||||
analytic_distribution = fields.Json(string="New Analytic Distribution")
|
|
||||||
tax_ids = fields.Many2many("account.tax", string="Taxes", readonly=True)
|
tax_ids = fields.Many2many("account.tax", string="Taxes", readonly=True)
|
||||||
tax_line_id = fields.Many2one(
|
tax_line_id = fields.Many2one(
|
||||||
"account.tax", string="Originator Tax", ondelete="restrict", readonly=True
|
"account.tax", string="Originator Tax", ondelete="restrict", readonly=True
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
<field
|
<field
|
||||||
name="template_id"
|
name="template_id"
|
||||||
widget="selection"
|
widget="selection"
|
||||||
domain="[('company_id', '=', company_id)]"
|
|
||||||
attrs="{'readonly': [('state', '=', 'set_lines')]}"
|
attrs="{'readonly': [('state', '=', 'set_lines')]}"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
|
Loading…
Reference in New Issue
Block a user