From c25b9e035373a5f2e4e5c3bfb9ed82ff35805660 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 10 Feb 2022 09:21:52 +0000 Subject: [PATCH] [FIX] account: Default terms and conditions not translated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: William André (wan) --- addons/account/models/account_bank_statement.py | 12 ++++++++---- addons/account/models/account_move.py | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index f6c81bb076a..91f1e7d6b8e 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -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 diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a47de9be67b..3234ccba89e 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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 # ------------------------------------------------------------