diff --git a/account_move_line_accounting_description/models/account_move.py b/account_move_line_accounting_description/models/account_move.py index 318af17e7d3..3de12c5679a 100644 --- a/account_move_line_accounting_description/models/account_move.py +++ b/account_move_line_accounting_description/models/account_move.py @@ -7,11 +7,12 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" - external_name = fields.Char(string="External Name", related="product_id.name") + external_name = fields.Char(string="External Name") @api.onchange("product_id") def _onchange_product_id(self): super()._onchange_product_id() for line in self: + line.external_name = line.name if line.product_id.accounting_description: line.name = line.product_id.accounting_description diff --git a/account_move_line_accounting_description/tests/test_account_move_line_description.py b/account_move_line_accounting_description/tests/test_account_move_line_description.py index 16fcc5daf14..0e9c410eccb 100644 --- a/account_move_line_accounting_description/tests/test_account_move_line_description.py +++ b/account_move_line_accounting_description/tests/test_account_move_line_description.py @@ -24,32 +24,18 @@ def setUpClass(cls): cls.account_move = cls.env["account.move"] + def test_invoice_line_with_accounting_description(self): invoice_form_acc_desc = Form( - cls.account_move.with_context(default_move_type="out_invoice") + self.account_move.with_context(default_move_type="out_invoice") ) - invoice_form_no_acc_desc = Form( - cls.account_move.with_context(default_move_type="out_invoice") - ) - - invoice_form_acc_desc.partner_id = ( - invoice_form_no_acc_desc.partner_id - ) = cls.partner_1 + invoice_form_acc_desc.partner_id = self.partner_1 with invoice_form_acc_desc.invoice_line_ids.new() as line_form: - line_form.product_id = cls.product_with_acc_desc + line_form.product_id = self.product_with_acc_desc line_form.quantity = 1 line_form.price_unit = 2.99 - cls.invoice_acc_desc = invoice_form_acc_desc.save() - - with invoice_form_no_acc_desc.invoice_line_ids.new() as line_form: - line_form.product_id = cls.product_without_acc_desc - line_form.quantity = 1 - line_form.price_unit = 2.99 - - cls.invoice_no_acc_desc = invoice_form_no_acc_desc.save() - - def test_invoice_line_description(self): + self.invoice_acc_desc = invoice_form_acc_desc.save() inv_line_with_product = self.invoice_acc_desc.invoice_line_ids.filtered( lambda x: x.product_id ) @@ -58,11 +44,23 @@ def test_invoice_line_description(self): inv_line_with_product.name, self.product_with_acc_desc.accounting_description, ) - self.assertEqual( inv_line_with_product.product_id.name, inv_line_with_product.external_name ) + def test_invoice_line_without_accounting_description(self): + invoice_form_no_acc_desc = Form( + self.account_move.with_context(default_move_type="out_invoice") + ) + + invoice_form_no_acc_desc.partner_id = self.partner_1 + + with invoice_form_no_acc_desc.invoice_line_ids.new() as line_form: + line_form.product_id = self.product_without_acc_desc + line_form.quantity = 1 + line_form.price_unit = 2.99 + + self.invoice_no_acc_desc = invoice_form_no_acc_desc.save() inv_line_with_product = self.invoice_no_acc_desc.invoice_line_ids.filtered( lambda x: x.product_id ) diff --git a/account_move_line_accounting_description/views/account_move.xml b/account_move_line_accounting_description/views/account_move.xml index e8216658a35..65508de75ae 100644 --- a/account_move_line_accounting_description/views/account_move.xml +++ b/account_move_line_accounting_description/views/account_move.xml @@ -17,6 +17,18 @@ + + + +