[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) <ayh@odoo.com>
X-original-commit: 00aadcb65ab1b05b390840acc02d5012a0fed893
Related: odoo/enterprise#36843
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Laurent Smet
2023-02-08 20:34:12 +01:00
parent 6bd3ab1504
commit 33e76acab6
2 changed files with 24 additions and 2 deletions
+1 -2
View File
@@ -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')
@@ -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. """