summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2021-02-25 09:53:30 +0000
committerLaurent Smet <las@odoo.com>2021-02-25 09:53:30 +0000
commit2c38dc6e34ebb8d4590adead74ebf02fee40d66a (patch)
tree6b9cb8963660d8c6d7fe6f37ce9fb9dbfb28f352
parent1c45685922b5561b8bce1c91b158184837391089 (diff)
[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#66800 Opw: 2466236 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
-rw-r--r--addons/account/models/account_bank_statement.py4
-rw-r--r--addons/account/tests/test_account_bank_statement.py36
2 files changed, 40 insertions, 0 deletions
diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index 4ae695fd687..56f0cca3b2f 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -1268,6 +1268,10 @@ class AccountBankStatementLine(models.Model):
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 db6dfc83d49..10ec0aba2c9 100644
--- a/addons/account/tests/test_account_bank_statement.py
+++ b/addons/account/tests/test_account_bank_statement.py
@@ -1556,3 +1556,39 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon):
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},
+ ])