Skip to content

Commit

Permalink
[FIX] account: Fix analytic lines when reconciling a statement line
Browse files Browse the repository at this point in the history
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#66850

Opw: 2466236
X-original-commit: 2c38dc6
Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
  • Loading branch information
smetl committed Feb 25, 2021
1 parent 2cf7c7f commit bbc6ed0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/account/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -------------------------------------------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions addons/account/tests/test_account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
])

0 comments on commit bbc6ed0

Please sign in to comment.