From bbc6ed03232f18bd9c68873813943dc5080afccb Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Thu, 25 Feb 2021 09:53:30 +0000 Subject: [PATCH] [FIX] account: Fix analytic lines when reconciling a statement line When reconciling a statement line from the bank reconciliation widget, the journal entry of the statement line is already posted and then, the analytic lines was never created. This commit fixes the issue by refreshing the analytic lines at the end of the statement line's reconciliation. closes odoo/odoo#66850 Opw: 2466236 X-original-commit: 2c38dc6e34ebb8d4590adead74ebf02fee40d66a Signed-off-by: Quentin De Paoli (qdp) Signed-off-by: Laurent Smet --- .../account/models/account_bank_statement.py | 4 +++ .../tests/test_account_bank_statement.py | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 1d1dcde51d9f3..cb72f528b8053 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -1272,6 +1272,10 @@ def reconcile(self, lines_vals_list, to_check=False): if len(rec_overview_partners) == 1: self.line_ids.write({'partner_id': rec_overview_partners.pop()}) + # Refresh analytic lines. + self.move_id.line_ids.analytic_line_ids.unlink() + self.move_id.line_ids.create_analytic_lines() + # ------------------------------------------------------------------------- # BUSINESS METHODS # ------------------------------------------------------------------------- diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index db6dfc83d492c..35419a674c8d3 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -1556,3 +1556,39 @@ def test_zero_amount_statement_line(self): statement_line = statement.line_ids self.assertRecordValues(statement_line, [{'is_reconciled': True, 'amount_residual': 0.0}]) + + def test_bank_statement_line_analytic(self): + ''' Ensure the analytic lines are generated during the reconciliation. ''' + analytic_account = self.env['account.analytic.account'].create({'name': 'analytic_account'}) + + statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + 'name': 'test_statement', + 'date': '2017-01-01', + 'journal_id': self.bank_journal_2.id, + 'line_ids': [ + (0, 0, { + 'date': '2019-01-01', + 'payment_ref': "line", + 'amount': 100.0, + }), + ], + }) + statement_line = statement.line_ids + + statement_line.reconcile([{ + 'balance': -100.0, + 'account_id': self.company_data['default_account_revenue'].id, + 'name': "write-off", + 'analytic_account_id': analytic_account.id, + }]) + + # Check the analytic account is there. + self.assertRecordValues(statement_line.line_ids.sorted('balance'), [ + {'balance': -100.0, 'analytic_account_id': analytic_account.id}, + {'balance': 100.0, 'analytic_account_id': False}, + ]) + + # Check the analytic lines. + self.assertRecordValues(statement_line.line_ids.analytic_line_ids, [ + {'amount': 100.0, 'account_id': analytic_account.id}, + ])