From 60be9f2c098cfead8a5e3fd23453b7e93243e0c5 Mon Sep 17 00:00:00 2001 From: Goaman Date: Wed, 22 May 2019 15:42:36 +0000 Subject: [PATCH] [IMP] account: add test for writeoff in the reconciliation widget Test that there is no conversion of debit/credit when creating a writeoff with the method process_move_lines of the model 'account.reconciliation.widget'. See 7b636f33423fedfec29861c0ad5d3a9b4346994d closes odoo/odoo#33588 Signed-off-by: Cedric Snauwaert (csn) --- addons/account/tests/test_reconciliation.py | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 3e4e2f0650c..8571ec138c7 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -2055,3 +2055,83 @@ class TestReconciliationExec(TestReconciliation): pay_receivable_line1 = payment1.move_line_ids.filtered(lambda l: l.account_id == self.account_rcv) self.assertTrue(pay_receivable_line1.reconciled) self.assertEqual(pay_receivable_line1.matched_debit_ids, move_caba1.tax_cash_basis_rec_id) + + def test_reconciliation_process_move_lines_with_mixed_currencies(self): + # Delete any old rate - to make sure that we use the ones we need. + old_rates = self.env['res.currency.rate'].search( + [('currency_id', '=', self.currency_usd_id)]) + old_rates.unlink() + + self.env['res.currency.rate'].create({ + 'currency_id': self.currency_usd_id, + 'name': time.strftime('%Y') + '-01-01', + 'rate': 2, + }) + + move_product = self.env['account.move'].create({ + 'ref': 'move product', + }) + move_product_lines = self.env['account.move.line'].create([ + { + 'name': 'line product', + 'move_id': move_product.id, + 'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id, + 'debit': 20, + 'credit': 0, + }, + { + 'name': 'line receivable', + 'move_id': move_product.id, + 'account_id': self.account_rcv.id, + 'debit': 0, + 'credit': 20, + } + ]) + move_product.post() + + move_payment = self.env['account.move'].create({ + 'ref': 'move payment', + }) + liquidity_account = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_liquidity').id)], limit=1) + move_payment_lines = self.env['account.move.line'].create([ + { + 'name': 'line product', + 'move_id': move_payment.id, + 'account_id': liquidity_account.id, + 'debit': 10.0, + 'credit': 0, + 'amount_currency': 20, + 'currency_id': self.currency_usd_id, + }, + { + 'name': 'line product', + 'move_id': move_payment.id, + 'account_id': self.account_rcv.id, + 'debit': 0, + 'credit': 10.0, + 'amount_currency': -20, + 'currency_id': self.currency_usd_id, + } + ]) + move_product.post() + + # We are reconciling a move line in currency A with a move line in currency B and putting + # the rest in a writeoff, this test ensure that the debit/credit value of the writeoff is + # correctly computed in company currency. + self.env['account.reconciliation.widget'].process_move_lines([{ + 'id': False, + 'type': False, + 'mv_line_ids': [move_payment_lines[1].id, move_product_lines[1].id], + 'new_mv_line_dicts': [{ + 'account_id': liquidity_account.id, + 'analytic_tag_ids': [6, None, []], + 'credit': 0, + 'date': time.strftime('%Y') + '-01-01', + 'debit': 15.0, + 'journal_id': self.env['account.journal'].search([('type', '=', 'sale')], limit=1).id, + 'name': 'writeoff', + }], + }]) + + writeoff_line = self.env['account.move.line'].search([('name', '=', 'writeoff')]) + self.assertEquals(writeoff_line.credit, 15.0) \ No newline at end of file