[FIX] account: Default terms and conditions not translated

As in 13.0, the default terms and conditions must be translated in the lang of the partner

PS: In the first computation, narration will be equal to the narration in the lang of the user.
So it was not changed when setting a partner.

The narration must be computed in the lang of the partner.

Writing on payment_ref triggers function _synchronize_to_moves and a write on partner_id was made.

In the write function, function modified was called

https://github.com/odoo/odoo/blob/15.0/odoo/models.py#L3850

And it lead to add the field narration in self.all.tocompute

https://github.com/odoo/odoo/blob/15.0/odoo/api.py#L758

Meaning that the next time it read the field narration, the function _compute_narration was called.
So it reset narration to False

opw:2726012

closes odoo/odoo#85775

X-original-commit: 6d9745e63fec20a7e967f00a428db9109c992bcf
Signed-off-by: Simon Goffin <sig@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Goffin Simon
2022-03-03 16:18:07 +00:00
parent 36bd5b1699
commit c25b9e0353
2 changed files with 13 additions and 6 deletions
@@ -863,12 +863,14 @@ class AccountBankStatementLine(models.Model):
for i, st_line in enumerate(st_lines):
counterpart_account_id = counterpart_account_ids[i]
to_write = {'statement_line_id': st_line.id}
to_write = {'statement_line_id': st_line.id, 'narration': st_line.narration}
if 'line_ids' not in vals_list[i]:
to_write['line_ids'] = [(0, 0, line_vals) for line_vals in st_line._prepare_move_line_default_vals(counterpart_account_id=counterpart_account_id)]
st_line.move_id.write(to_write)
# Otherwise field narration will be recomputed silently (at next flush) when writing on partner_id
self.env.remove_to_compute(st_line.move_id._fields['narration'], st_line.move_id)
return st_lines
def write(self, vals):
@@ -1003,11 +1005,13 @@ class AccountBankStatementLine(models.Model):
for line in other_lines:
line_ids_commands.append((2, line.id))
st_line.move_id.write({
'partner_id': st_line.partner_id.id,
st_line_vals = {
'currency_id': (st_line.foreign_currency_id or journal_currency or company_currency).id,
'line_ids': line_ids_commands,
})
}
if st_line.move_id.partner_id != st_line.partner_id:
st_line_vals['partner_id'] = st_line.partner_id.id
st_line.move_id.write(st_line_vals)
# -------------------------------------------------------------------------
# RECONCILIATION METHODS
+5 -2
View File
@@ -3417,15 +3417,18 @@ class AccountMove(models.Model):
@api.depends('move_type', 'partner_id', 'company_id')
def _compute_narration(self):
use_invoice_terms = self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms')
for move in self.filtered(lambda am: not am.narration):
for move in self:
if not use_invoice_terms or not move.is_sale_document(include_receipts=True):
move.narration = False
else:
lang = move.partner_id.lang or self.env.user.lang
if not move.company_id.terms_type == 'html':
narration = move.company_id.invoice_terms if not is_html_empty(move.company_id.invoice_terms) else ''
narration = move.company_id.with_context(lang=lang).invoice_terms if not is_html_empty(move.company_id.invoice_terms) else ''
else:
baseurl = self.env.company.get_base_url() + '/terms'
context = {'lang': lang}
narration = _('Terms & Conditions: %s', baseurl)
del context
move.narration = narration or False
# ------------------------------------------------------------