From 59ccb8091848ace79026af20ba818a9d7d04fea2 Mon Sep 17 00:00:00 2001 From: william-andre Date: Wed, 13 Sep 2023 16:07:44 +0000 Subject: [PATCH] [FIX] account: keep receivable account on duplicate invoice Steps to reproduce: * create an invoice with a line * change the receivable account * duplicate the invoice Result: the receivable account is recomputed to the default one. Expected: we should keep it. task-3504443 closes odoo/odoo#135723 X-original-commit: 1043d2b790a625590ca21f8e0d6560ceba3d6a84 Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move.py | 1 - addons/account/models/account_move_line.py | 1 - .../tests/test_account_move_out_invoice.py | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b74c83d637c..8a539d8c315 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2363,7 +2363,6 @@ class AccountMove(models.Model): (command, _id, line_vals) for command, _id, line_vals in data['line_ids'] if command == Command.CREATE - and line_vals.get('display_type') not in ('payment_term', 'tax', 'rounding') ] elif move.move_type == 'entry': if 'partner_id' not in data: diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 31fd9d76390..baf779c2fd4 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -496,7 +496,6 @@ class AccountMoveLine(models.Model): values.append(product.description_purchase) line.name = '\n'.join(values) - @api.depends('display_type', 'company_id') def _compute_account_id(self): term_lines = self.filtered(lambda line: line.display_type == 'payment_term') if term_lines: diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 88ad7352da5..896df22586e 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3746,3 +3746,28 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'credit': 0.0, }, ]) + + def test_keep_receivable(self): + """Duplicating an invoice with a different receivable account should keep the account.""" + receivable_account = self.partner_a.property_account_receivable_id + other_receivable_account = receivable_account.copy() + + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_line_ids': [ + Command.create({ + 'name': 'test line', + 'quantity': 1, + 'price_unit': 100, + }) + ], + }) + + invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').account_id = other_receivable_account + duplicate_invoice = invoice.copy() + + self.assertEqual( + duplicate_invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').account_id, + other_receivable_account + )