From 209e2ebb04f99da2bbdb1ac36f7fbef8ca5c3b27 Mon Sep 17 00:00:00 2001 From: william-andre Date: Mon, 3 Apr 2023 12:22:06 +0000 Subject: [PATCH] [FIX] account: compute of the name issue when no tax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When posting a move without any taxes, and hashing in version 3, as in the test `test_account_move_hash_versioning_3`, there was a case when the move could have its name changed after posting, and so, after hashing. The issue came from the order of computation of the name, as we gave the name in the values when we shouldn't. closes odoo/odoo#115222 Related: odoo/enterprise#38163 Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 6 +----- addons/account/models/account_move_line.py | 11 +++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f0b1f2430a5..5e0166b2874 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1043,8 +1043,7 @@ class AccountMove(models.Model): company=invoice.company_id, sign=sign ) - multiple_installments = len(invoice_payment_terms['line_ids']) > 1 - for i, term_line in enumerate(invoice_payment_terms['line_ids']): + for term_line in invoice_payment_terms['line_ids']: key = frozendict({ 'move_id': invoice.id, 'date_maturity': fields.Date.to_date(term_line.get('date')), @@ -1053,13 +1052,10 @@ class AccountMove(models.Model): values = { 'balance': term_line['company_amount'], 'amount_currency': term_line['foreign_amount'], - 'name': invoice.payment_reference or '', 'discount_date': invoice_payment_terms.get('discount_date'), 'discount_balance': invoice_payment_terms.get('discount_balance') or 0.0, 'discount_amount_currency': invoice_payment_terms.get('discount_amount_currency') or 0.0, } - if multiple_installments: - values['name'] = f'{values["name"]} installment #{i + 1}'.lstrip() if key not in invoice.needed_terms: invoice.needed_terms[key] = values else: diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 00e786bd3f4..5b256cdbc78 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -459,10 +459,13 @@ class AccountMoveLine(models.Model): def _compute_name(self): for line in self: if line.display_type == 'payment_term': - if line.move_id.payment_reference: - line.name = line.move_id.payment_reference - elif not line.name: - line.name = '' + if not line.name: + term_lines = line.move_id.line_ids.filtered(lambda l: l.display_type == 'payment_term') | line + name = line.move_id.payment_reference or '' + if len(term_lines) > 1: + index = term_lines._ids.index(line.id) + 1 + name = _('%s installment #%s', name, index).lstrip() + line.name = name continue if not line.product_id or line.display_type in ('line_section', 'line_note'): continue