From acde911e44ecdef57345e38367adefa3dbf28967 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 25 Sep 2019 09:17:34 +0000 Subject: [PATCH] [FIX] account: invoice, refund in foreign; payment, writeoff in domestic reconcile Have an exchange rate of 1.1106 Have an invoice and a refund in a foreign currency (amounts: 800 and 400) Have a payment and a writeoff in domestic currency (amounts: 200 and 160.16)) Before this commit, the invoice was not fully reconciled even though the whole chain was This was because, when checking if we should fully reconcile we did so by forgetting that some members of the reconciliation chain has a foreign currency So, the exchange rate difference was never posted (which amounts to 0.01 in foreign currency, and 0.00 in domestic) After this commit, all the chain is reconciled, including the invoice OPW 2057845 closes odoo/odoo#37738 X-original-commit: 74fb177c292c156a20818a12b47c53c40f37a2ee Signed-off-by: Lucas Perais (lpe) --- addons/account/tests/test_reconciliation.py | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 91c52a22c85..feb60ab12cd 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -2146,3 +2146,59 @@ class TestReconciliationExec(TestReconciliation): writeoff_line = self.env['account.move.line'].search([('name', '=', 'writeoff')]) self.assertEquals(writeoff_line.credit, 15.0) + + def test_inv_refund_foreign_payment_writeoff_domestic2(self): + company = self.env.ref('base.main_company') + self.env['res.currency.rate'].search([]).unlink() + self.env['res.currency.rate'].create({ + 'name': time.strftime('%Y') + '-07-01', + 'rate': 1.0, + 'currency_id': self.currency_euro_id, + 'company_id': company.id + }) + self.env['res.currency.rate'].create({ + 'name': time.strftime('%Y') + '-07-01', + 'rate': 1.110600, # Don't change this ! + 'currency_id': self.currency_usd_id, + 'company_id': self.env.ref('base.main_company').id + }) + inv1 = self.create_invoice(invoice_amount=800, currency_id=self.currency_usd_id) + inv2 = self.create_invoice(type="out_refund", invoice_amount=400, currency_id=self.currency_usd_id) + + payment = self.env['account.payment'].create({ + 'payment_method_id': self.inbound_payment_method.id, + 'payment_type': 'inbound', + 'partner_type': 'customer', + 'partner_id': inv1.partner_id.id, + 'amount': 200.00, + 'journal_id': self.bank_journal_euro.id, + 'company_id': company.id, + }) + payment.post() + + inv1_receivable = inv1.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + inv2_receivable = inv2.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + pay_receivable = payment.move_line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + + move_balance = self.env['account.move'].create({ + 'partner_id': inv1.partner_id.id, + 'date': time.strftime('%Y') + '-07-01', + 'journal_id': self.bank_journal_euro.id, + 'line_ids': [ + (0, False, {'credit': 160.16, 'account_id': inv1_receivable.account_id.id, 'name': 'Balance WriteOff'}), + (0, False, {'debit': 160.16, 'account_id': self.diff_expense_account.id, 'name': 'Balance WriteOff'}), + ] + }) + + move_balance.post() + move_balance_receiv = move_balance.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable') + + (inv1_receivable + inv2_receivable + pay_receivable + move_balance_receiv).reconcile() + + self.assertTrue(inv1_receivable.full_reconcile_id.exists()) + self.assertEquals(inv1_receivable.full_reconcile_id, inv2_receivable.full_reconcile_id) + self.assertEquals(inv1_receivable.full_reconcile_id, pay_receivable.full_reconcile_id) + self.assertEquals(inv1_receivable.full_reconcile_id, move_balance_receiv.full_reconcile_id) + + self.assertEquals(inv1.invoice_payment_state, 'paid') + self.assertEquals(inv2.invoice_payment_state, 'paid')