From 33e76acab662cf35bfd512b2bd4c5531f5f07238 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Mon, 6 Feb 2023 10:32:23 +0000 Subject: [PATCH] [IMP] account: Remove 'move_id.state' dependency of _compute_amount_residual The reconciliation fields of account.move.line should be independent of the move's state. closes odoo/odoo#112251 Co-author: Habib (ayh) X-original-commit: 00aadcb65ab1b05b390840acc02d5012a0fed893 Related: odoo/enterprise#36843 Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move_line.py | 3 +-- .../tests/test_account_move_reconcile.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index e70750e170f..341063fd3c0 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -682,7 +682,7 @@ class AccountMoveLine(models.Model): for record in self: record.cumulated_balance = result[record.id] - @api.depends('debit', 'credit', 'amount_currency', 'account_id', 'currency_id', 'move_id.state', 'company_id', + @api.depends('debit', 'credit', 'amount_currency', 'account_id', 'currency_id', 'company_id', 'matched_debit_ids', 'matched_credit_ids') def _compute_amount_residual(self): """ Computes the residual amount of a move line from a reconcilable account in the company currency and the line's currency. @@ -746,7 +746,6 @@ class AccountMoveLine(models.Model): line.reconciled = ( comp_curr.is_zero(line.amount_residual) and foreign_curr.is_zero(line.amount_residual_currency) - and line.move_id.state not in ('draft', 'cancel') ) @api.depends('move_id.move_type', 'tax_ids', 'tax_repartition_line_id', 'debit', 'credit', 'tax_tag_ids', 'is_refund') diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 8b980da3a7f..fb4ec206cc9 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -330,6 +330,29 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): {'reconciled': False}, ]) + def test_invoice_draft_fully_paid_if_zero(self): + """ Tests that Invoices with zero balance are marked as paid and reconciled + """ + zero_invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': fields.Date.from_string('2019-01-01'), + }) + self.assertRecordValues(zero_invoice, [{ + 'state': 'draft', + 'payment_state': 'not_paid', + 'amount_total': 0.0, + }]) + self.assertTrue(zero_invoice.line_ids.reconciled) + + zero_invoice.action_post() + self.assertRecordValues(zero_invoice, [{ + 'state': 'posted', + 'payment_state': 'paid', + 'amount_total': 0.0, + }]) + self.assertTrue(zero_invoice.line_ids.reconciled) + def test_reconcile_lines_corner_case_1_zero_balance_same_foreign_currency(self): """ Test the reconciliation of lines having a zero balance in different currencies. In that case, the reconciliation should not be full until an additional move is added with the right foreign currency amount. """