From 6a0d99cde92866bbf5dd8a82a9515c20eb6f1e66 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 19:00:29 +0200 Subject: [PATCH] [IMP] account_voucher: added case2_usd_eur_debtor_in_eur.yml bzr revid: qdp-launchpad@openerp.com-20111013170029-337fw976foqdkfzb --- addons/account_voucher/__openerp__.py | 2 +- ...ur.yml => case2_usd_eur_debtor_in_eur.yml} | 120 ++++++++---------- 2 files changed, 51 insertions(+), 71 deletions(-) rename addons/account_voucher/test/{case2_usd_eur.yml => case2_usd_eur_debtor_in_eur.yml} (75%) diff --git a/addons/account_voucher/__openerp__.py b/addons/account_voucher/__openerp__.py index 82516a0113f..07f6372e8b9 100644 --- a/addons/account_voucher/__openerp__.py +++ b/addons/account_voucher/__openerp__.py @@ -62,7 +62,7 @@ Account Voucher module includes all the basic requirements of Voucher Entries fo "test/account_voucher_report.yml", "test/case1_usd_usd.yml", #"test/case2_suppl_usd_eur.yml", - #"test/case2_usd_eur.yml", + "test/case2_usd_eur_debtor_in_eur.yml", #"test/case3_eur_eur.yml", #"test/case4_cad_chf.yml", ], diff --git a/addons/account_voucher/test/case2_usd_eur.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml similarity index 75% rename from addons/account_voucher/test/case2_usd_eur.yml rename to addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml index ded95095e5a..b872a54561d 100644 --- a/addons/account_voucher/test/case2_usd_eur.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml @@ -1,12 +1,19 @@ - In order to check the Account_voucher module with multi-currency in OpenERP, I create 2 Invoices in USD and make 2 Payments one in USD and another in EUR, based on the currency rating on that particular date +- + I modify the debtor account in order to make sure there is no currency_id linked +- + !python {model: account.account}: | + from datetime import datetime + ids = self.search(cr, uid, [('name', 'ilike', 'debtor')]) + self.write(cr, uid, ids, {'currency_id': False}) - I create currency USD in OpenERP for January of 1.333333 Rate - !python {model: res.currency.rate}: | from datetime import datetime - curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')]) + curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0] date = '%s-01-01' %(datetime.now().year) ids = self.search(cr, uid, [('currency_id', '=', curr_id), ('name', '=', date)]) self.write(cr, uid, ids, {'rate': 1.333333}) @@ -59,12 +66,6 @@ currency: base.USD company_id: base.main_company view_id: account.account_journal_bank_view -- - I set up some accounts for currency rate expense/income in my company -- - !record {model: res.company, id: base.main_company}: - property_expense_currency_exchange: account.o_expense - property_income_currency_exchange: account.o_income - I create a new partner Michael Geller - @@ -149,7 +150,7 @@ assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account" - I create the first voucher of payment - + - !python {model: account.voucher}: | import netsvc, time @@ -157,7 +158,7 @@ res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michael0"), ref('bank_journal_EUR'), 240.0, 2, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), - 'amount': 240.0, + 'amount': 200.0, 'company_id': ref('base.main_company'), 'currency_id': ref('base.EUR'), 'journal_id': ref('bank_journal_EUR'), @@ -173,28 +174,14 @@ if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: - if item['amount_unreconciled'] == 200.00: - item['amount'] = 180.00 + if item['amount_unreconciled'] == 150.00: + item['amount'] = 130.00 else: item['amount'] = 70.00 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']] id = self.create(cr, uid, vals) voucher_id = self.browse(cr, uid, id) assert (voucher_id.state=='draft'), "Voucher is not in draft state" -- - I check that writeoff amount computed is 15.0 -- - !python {model: account.voucher}: | - voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michael0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 15.0), "Writeoff amount is not 15.0" -- - I check that currency rate difference is -34.0 -- - !python {model: account.voucher}: | - voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michael0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == -34.0), "Currency rate difference is not -34.0" - I confirm the voucher - @@ -216,11 +203,7 @@ - I check that my debtor account is correct - - I check that the debtor account has 2 new lines with -180 and -70 in amount_currency columns and their credit columns are respectively 135 and 56 and currency is USD($). -- - I check that my currency rate difference is correct. 34 in credit with no amount_currency -- - I check that my writeoff is correct. 15 in credit with no amount_currency + I check that the debtor account has 2 new lines with 0 in amount_currency columns and their credit columns are 130 and 70 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michael0'))]) @@ -228,43 +211,36 @@ move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -180.00: - assert move_line.credit == 135.00, "Debtor account has wrong entry." - elif move_line.amount_currency == -70.00: - assert move_line.credit == 56.00, "Debtor account has wrong entry." - elif move_line.credit == 34.00: - assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." - elif move_line.credit == 15.00: - assert move_line.amount_currency == 0.00, "Writeoff amount is wrong." + assert move_line.amount_currency == 0.00, "A line has the 'amount_currency' column filled" - - I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual + I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual - !python {model: account.invoice}: | invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice" -- - I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual + assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice" +- toto + I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual - !python {model: account.invoice}: | invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice" + assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice" - I create the second voucher of payment - + - !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michael0"), ref('bank_journal_EUR'), 45.0, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michael0"), ref('bank_journal_USD'), 80.0, 2, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), - 'amount': 45.0, + 'amount': 80.0, 'company_id': ref('base.main_company'), 'currency_id': ref('base.USD'), 'journal_id': ref('bank_journal_USD'), @@ -274,34 +250,28 @@ 'date': time.strftime("%Y-04-01"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), + 'exchange_acc_id': ref('account.o_expense'), 'comment': 'Write Off', 'name': 'Second payment', } if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: - if item['amount_unreconciled'] == 20.00: - item['amount'] = 20.00 + if item['amount_unreconciled'] == 55.56: + item['amount'] = 55.56 else: - item['amount'] = 30.00 + item['amount'] = 22.22 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']] id = self.create(cr, uid, vals) voucher_id = self.browse(cr, uid, id) assert (voucher_id.state=='draft'), "Voucher is not in draft state" - - I check that writeoff amount computed is -5.0 + I check that writeoff amount computed is 2.22 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michael0'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0" -- - I check that currency rate difference is -8.50 -- - !python {model: account.voucher}: | - voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michael0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == -8.50), "Currency rate difference is not -8.50" + assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$" - I confirm the voucher - @@ -320,26 +290,36 @@ - I check that my debtor account is correct - - I check that the debtor account has 2 new lines with -20 and -30 in amount_currency columns and their credit columns are respectively 15 and 24 and currency is USD($). + I check that the debtor account has 2 new lines with -55.56 and -22.22 in amount_currency columns and their credit columns are respectively 52.78 and 21.11 and currency is USD($). - - I check that my currency rate difference is correct. 8.50 in credit with no amount_currency + I check that my currency rate difference is correct. - - I check that my writeoff is correct. 4.75 in debit and 5 in amount_currency + I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michael0'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) + reconcile_a = reconcile_b = False for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -20.00: - assert move_line.credit == 15.00, "Debtor account has wrong entry." - elif move_line.amount_currency == -30.00: - assert move_line.credit == 24.00, "Debtor account has wrong entry." - elif move_line.credit == 8.50: - assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." - elif move_line.amount_currency == 5.00: - assert move_line.debit == 4.75, "Writeoff amount is wrong." + if move_line.amount_currency == -22.22: + assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled" + reconcile_b = move_line.reconcile_id.id + elif move_line.amount_currency == -55.56: + assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled" + reconcile_a = move_line.reconcile_id.id + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.amount_currency == -55.56: + assert move_line.credit == 52.78, "Debtor account has wrong entry." + elif move_line.amount_currency == -22.22: + assert move_line.credit == 21.11, "Debtor account has wrong entry." + elif move_line.credit == 11.11 and move_line.account_id.reconcile: + assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference." + elif move_line.credit == 32.78 and move_line.account_id.reconcile: + assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference." + elif move_line.amount_currency == 2.22: + assert move_line.credit == 2.11, "Writeoff amount is wrong." - I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid - @@ -357,4 +337,4 @@ move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" \ No newline at end of file + assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice"