From 63d44ffd3532287c2c26a14db0312c2ccb75375c Mon Sep 17 00:00:00 2001 From: "Guillaume (guva)" Date: Fri, 3 Jun 2022 05:00:22 +0000 Subject: [PATCH] [FIX] account: keep statement line note We keep the statement line note when changing the partner in reconciliation widget Steps: - Create a Bank Statement, a Bank Statement Line BSL with a note (field narration) - Save, edit, change partner on statement line and save. -> The note on BSL is empty With this commit we allow narration computation only for sale documents. opw-2832287 closes odoo/odoo#97125 X-original-commit: 19394d1971259933c5158139c56344c9c35bdaed Signed-off-by: Laurent Smet Signed-off-by: Guillaume Vanleynseele (guva) --- addons/account/models/account_move.py | 4 ++- .../tests/test_account_bank_statement.py | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ba6750ac563..1ef3e9d413b 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3515,7 +3515,9 @@ class AccountMove(models.Model): def _compute_narration(self): use_invoice_terms = self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms') for move in self: - if not use_invoice_terms or not move.is_sale_document(include_receipts=True): + if not move.is_sale_document(include_receipts=True): + continue + if not use_invoice_terms: move.narration = False else: lang = move.partner_id.lang or self.env.user.lang diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index e200c8224d2..8589cf00b7c 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -927,3 +927,30 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): statement_line = statement.line_ids self.assertRecordValues(statement_line, [{'is_reconciled': True, 'amount_residual': 0.0}]) + + def test_statement_line_note_onchange_partner(self): + """ + Check if narration field stays as it is when changing the partner + in reconciliation widget. + """ + bank_stmt = self.env['account.bank.statement'].create({ + 'company_id': self.env.company.id, + 'journal_id': self.bank_journal_1.id, + 'name': 'test', + }) + + bank_stmt_line = self.env['account.bank.statement.line'].create({ + 'payment_ref': 'testLine', + 'statement_id': bank_stmt.id, + 'narration': 'This is a note', + 'amount': 100, + }) + + bank_stmt_line.partner_id = self.partner_b + + self.assertRecordValues(bank_stmt_line, [{ + 'payment_ref': 'testLine', + 'statement_id': bank_stmt.id, + 'narration': '

This is a note

', + 'amount': 100, + }])