From 50deb5ae0d26d6112c50c8b9c1d24eeb0ede1be6 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 28 Oct 2021 18:08:40 +0200 Subject: [PATCH 1/3] Do not set external_name as related to allow customization --- .../models/account_move.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From cab74030dd961d00c518311caab1e232fe3cdd95 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 28 Oct 2021 18:09:00 +0200 Subject: [PATCH 2/3] Refactor test to be able to track issue --- .../test_account_move_line_description.py | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) 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..c14f3c2a524 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,19 @@ 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") - ) - invoice_form_no_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_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.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.product_id = self.product_with_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 +45,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 ) From f3a39ca2126b5c2fd92cfdb549302865e8ecd13e Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Thu, 28 Oct 2021 18:17:45 +0200 Subject: [PATCH 3/3] Add external_name to account.move.line_ids view We need to display the field as invisible here although it is already defined on invoice_line_ids tree above. Having it defined only there would only set the external_name key with its value inside the invoice_line_ids key of the values dictionary that is passed to create function. However, this invoice_line_ids key is popped in account.move._move_autocomplete_invoice_lines_create function to keep only the line_ids to create the account.move and avoid duplicated account.move.line records. --- .../views/account_move.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 @@ + + + +