[FIX] account: compute of the name issue when no tax

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) <wan@odoo.com>
This commit is contained in:
william-andre
2023-05-02 14:47:02 +02:00
committed by gawa-odoo
parent 15b2c690e1
commit 209e2ebb04
2 changed files with 8 additions and 9 deletions
+1 -5
View File
@@ -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:
+7 -4
View File
@@ -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