From 14ba370293cf418a2553fb106c1592d80464c2d4 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Tue, 27 Sep 2011 18:37:09 +0200 Subject: [PATCH 01/31] account_voucher multicurrency scenario bzr revid: al@openerp.com-20110927163709-08ja2ruir230c6hu --- addons/account_voucher/test/case1_usd_usd.yml | 355 +++++++++++++++++ .../test/case2_suppl_usd_eur.yml | 328 ++++++++++++++++ addons/account_voucher/test/case2_usd_eur.yml | 360 ++++++++++++++++++ addons/account_voucher/test/case3_eur_eur.yml | 331 ++++++++++++++++ addons/account_voucher/test/case4_cad_chf.yml | 194 ++++++++++ 5 files changed, 1568 insertions(+) create mode 100644 addons/account_voucher/test/case1_usd_usd.yml create mode 100644 addons/account_voucher/test/case2_suppl_usd_eur.yml create mode 100644 addons/account_voucher/test/case2_usd_eur.yml create mode 100644 addons/account_voucher/test/case3_eur_eur.yml create mode 100644 addons/account_voucher/test/case4_cad_chf.yml diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml new file mode 100644 index 00000000000..dc7654ab9c3 --- /dev/null +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -0,0 +1,355 @@ +- + In order to check the Account_voucher module with multi-currency in OpenERP, + I create 2 Invoices in USD and make 2 Payments in USD based on the currency rating on that particular date +- + 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')]) + 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}) +- + I create currency USD in OpenERP for February of 1.250000 Rate +- + !record {model: res.currency.rate, id: feb_usd}: + currency_id: base.USD + name: !eval "'%s-02-01' %(datetime.now().year)" + rate: 1.250000 + +- + I create currency USD in OpenERP for March of 1.111111 Rate +- + !record {model: res.currency.rate, id: mar_usd}: + currency_id: base.USD + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 1.111111 + +- + I create currency USD in OpenERP for April of 1.052632 Rate +- + !record {model: res.currency.rate, id: apr_usd}: + currency_id: base.USD + name: !eval "'%s-04-01' %(datetime.now().year)" + rate: 1.052632 + +- + I create a bank journal with USD as currency +- + !record {model: account.journal, id: bank_journal_USD}: + name: Bank Journal(USD) + code: BUSD + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + 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 new partner Mark Strauss. +- + !record {model: res.partner, id: res_partner_strauss0}: + address: + - city: paris + country_id: base.fr + name: Mark Strauss + street: 1 rue Rockfeller + type: invoice + zip: '75016' + name: Mr. Mark Strauss +- + I create the first invoice on 1st January for 200 USD +- + !record {model: account.invoice, id: account_invoice_jan}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 200.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_strauss0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan} +- + I check that first invoice move is correct for debtor account (debit - credit == 150.0) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_invoice_jan")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account" +- + I create the second invoice on 1st February for 100 USD +- + !record {model: account.invoice, id: account_invoice_feb}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-02-01' %(datetime.now().year)" + period_id: account.period_2 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 100.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_strauss0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb} +- + I check that second invoice move is correct for debtor account (debit - credit == 80) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_invoice_feb")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account" + +- + I create the first voucher of payment + +- + !python {model: account.voucher}: | + import netsvc, time + vals = {} + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 240.00, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.USD'), + 'journal_id': ref('bank_journal_USD'), + 'partner_id': ref('res_partner_strauss0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First 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'] == 200.00: + item['amount'] = 180.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 -10.0 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.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_strauss0'))]) + 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 +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my first voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my debtor account is correct +- + I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 135 and 56 +- + I check that my currency rate difference is correct. 34 in credit with no amount_currency +- + I check that my write-off is correct. 9 debit and 10 amount_currency +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + 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)]) + 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 rate difference." + elif move_line.amount_currency == 10.00: + assert move_line.debit == 9.00, "Writeoff amount is wrong." +- + I check the residual amount of Invoice1, should be 20 in amount_currency and 15 in company currency +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_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.0) , "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 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_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.0 and move_line.amount_residual == 24.0) , "Residual amount is not correct for first 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_strauss0"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 45.00, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.USD'), + 'journal_id': ref('bank_journal_USD'), + 'partner_id': ref('res_partner_strauss0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-04-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_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 + else: + item['amount'] = 30.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 -5.0 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + 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_strauss0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.currency_rate_difference == -8.50), "Currency rate difference is not -8.50" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my second voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my debtor account is correct +- + I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 15 and 24. +- + I check that my currency rate difference is correct. 8.5 in credit with no amount_currency +- + I check that my writeoff is correct. 4.75 debit and 5 amount_currency +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) + 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)]) + 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." +- + I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_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 == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" +- + I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_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 == 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 diff --git a/addons/account_voucher/test/case2_suppl_usd_eur.yml b/addons/account_voucher/test/case2_suppl_usd_eur.yml new file mode 100644 index 00000000000..31e756d5355 --- /dev/null +++ b/addons/account_voucher/test/case2_suppl_usd_eur.yml @@ -0,0 +1,328 @@ +- + 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 create a bank journal with EUR as currency +- + !record {model: account.journal, id: bank_journal_EUR}: + name: Bank Journal(EUR) + code: BEUR + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.EUR + company_id: base.main_company + view_id: account.account_journal_bank_view +- + I create a bank journal with USD as currency +- + !record {model: account.journal, id: bank_journal_USD}: + name: Bank Journal(USD) + code: BUSD + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.USD + company_id: base.main_company + view_id: account.account_journal_bank_view +- + I create a new partner Robert Clements +- + !record {model: res.partner, id: res_partner_clements0}: + address: + - city: marseille + country_id: base.fr + name: Robert + street: 1 rue Rockfeller + type: invoice + zip: '13016' + name: Mr.Robert Clements +- + I create the first invoice on 1st January for 200 USD +- + !record {model: account.invoice, id: account_first_invoice_jan_suppl}: + account_id: account.a_pay + type : in_invoice + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_expense + name: '[PC1] Basic PC' + price_unit: 200.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_clements0 + reference_type: none + check_total : 200 +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_suppl} +- + I check that first invoice move is correct for debtor account(debit - credit == -150) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == -150.00), "Invoice move is incorrect for debtors account" +- + I create the second invoice on 1st February for 100 USD +- + !record {model: account.invoice, id: account_second_invoice_feb_suppl}: + account_id: account.a_pay + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-02-01' %(datetime.now().year)" + period_id: account.period_2 + type : in_invoice + invoice_line: + - account_id: account.a_expense + name: '[PC1] Basic PC' + price_unit: 100.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_clements0 + reference_type: none + check_total : 100.0 +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_suppl} +- + I check that second invoice move is correct for debtor account (debit - credit == -80) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + 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 + vals = {} + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_clements0"), ref('bank_journal_EUR'), 240.0, 2, ttype='payment', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 240.0, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.EUR'), + 'journal_id': ref('bank_journal_EUR'), + 'partner_id': ref('res_partner_clements0'), + 'period_id': ref('account.period_3'), + 'type': 'payment', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First payment', + } + if not res['value']['line_dr_ids']: + res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}] + for item in res['value']['line_dr_ids']: + if item['amount_unreconciled'] == 200.00: + item['amount'] = 180.00 + else: + item['amount'] = 70.00 + vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_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_clements0'))]) + 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_clements0'))]) + 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 +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my creditor account is correct +- + I check that the creditor account has 2 new lines with 180 and 70 in amount_currency columns and their debit 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 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.amount_currency == 180.00: + assert move_line.debit == 135.00, "Creditor account has wrong entry." + elif move_line.amount_currency == 70.00: + assert move_line.debit == 56.00, "Debtor account has wrong entry." + elif move_line.debit == 34.00: + assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." + elif move_line.debit == 15.00: + assert move_line.amount_currency == 0.00, "Writeoff amount is wrong." +- + I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) + 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 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) + 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" +- + 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_clements0"), ref('bank_journal_EUR'), 45.0, 2, ttype='payment', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 45.0, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.USD'), + 'journal_id': ref('bank_journal_USD'), + 'partner_id': ref('res_partner_clements0'), + 'period_id': ref('account.period_3'), + 'type': 'payment', + 'date': time.strftime("%Y-04-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'Second payment', + } + if not res['value']['line_dr_ids']: + res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}] + for item in res['value']['line_dr_ids']: + if item['amount_unreconciled'] == 20.00: + item['amount'] = 20.00 + else: + item['amount'] = 30.00 + vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_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 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + 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_clements0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.currency_rate_difference == 8.50), "Currency rate difference is not 8.50" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that my voucher state is posted +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert voucher_id.state == 'posted', "Voucher state is not posted" +- + I check that my creditor account is correct +- + I check that the creditor account has 2 new lines with 20 and 30 in amount_currency columns and their debit columns are respectively 15 and 24 and currency is USD($). +- + I check that my currency rate difference is correct. 8.50 in debit with no amount_currency +- + I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_clements0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.amount_currency == 20.00: + assert move_line.debit == 15.00, "Debtor account has wrong entry." + elif move_line.amount_currency == 30.00: + assert move_line.debit == 24.00, "Debtor account has wrong entry." + elif move_line.debit == 8.50: + assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." + elif move_line.amount_currency == -5.00: + assert move_line.credit == 4.75, "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 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) + 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 first Invoice" +- + I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) + 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" diff --git a/addons/account_voucher/test/case2_usd_eur.yml b/addons/account_voucher/test/case2_usd_eur.yml new file mode 100644 index 00000000000..ded95095e5a --- /dev/null +++ b/addons/account_voucher/test/case2_usd_eur.yml @@ -0,0 +1,360 @@ +- + 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 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')]) + 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}) +- + I create currency USD in OpenERP for February of 1.250000 Rate +- + !record {model: res.currency.rate, id: febr_usd}: + currency_id: base.USD + name: !eval "'%s-02-01' %(datetime.now().year)" + rate: 1.250000 +- + I create currency USD in OpenERP for March of 1.111111 Rate +- + !record {model: res.currency.rate, id: marc_usd}: + currency_id: base.USD + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 1.111111 +- + I create currency USD in OpenERP for April of 1.052632 Rate +- + !record {model: res.currency.rate, id: apri_usd}: + currency_id: base.USD + name: !eval "'%s-04-01' %(datetime.now().year)" + rate: 1.052632 +- + I create a bank journal with EUR as currency +- + !record {model: account.journal, id: bank_journal_EUR}: + name: Bank Journal(EUR) + code: BEUR + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.EUR + company_id: base.main_company + view_id: account.account_journal_bank_view +- + I create a bank journal with USD as currency +- + !record {model: account.journal, id: bank_journal_USD}: + name: Bank Journal(USD) + code: BUSD + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + 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 +- + !record {model: res.partner, id: res_partner_michael0}: + address: + - city: paris + country_id: base.fr + name: Michael + street: 1 rue Rockfeller + type: invoice + zip: '75016' + name: Mr.Michael Geller +- + I create the first invoice on 1st January for 200 USD +- + !record {model: account.invoice, id: account_first_invoice_jan}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 200.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_michael0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan} +- + I check that first invoice move is correct for debtor account(debit - credit == 150) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" +- + I create the second invoice on 1st February for 100 USD +- + !record {model: account.invoice, id: account_second_invoice_feb}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-02-01' %(datetime.now().year)" + period_id: account.period_2 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 100.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_michael0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb} +- + I check that second invoice move is correct for debtor account (debit - credit == 80) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + 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 + vals = {} + 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, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.EUR'), + 'journal_id': ref('bank_journal_EUR'), + 'partner_id': ref('res_partner_michael0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First 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'] == 200.00: + item['amount'] = 180.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 +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michael0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my voucher is valid +- + !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]) + 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): + assert move_line.state == 'valid', "Voucher move is not valid" +- + 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 +- + !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]) + 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." +- + I check the residual amount of Invoice1, should be 20 in residual currency and 15 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 +- + !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" +- + 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) + vals = { + 'account_id': ref('account.cash'), + 'amount': 45.0, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.USD'), + 'journal_id': ref('bank_journal_USD'), + 'partner_id': ref('res_partner_michael0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-04-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_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 + else: + item['amount'] = 30.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 -5.0 +- + !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" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michael0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that my voucher state is posted +- + !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.state == 'posted', "Voucher state is not posted" +- + 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 my currency rate difference is correct. 8.50 in credit with no amount_currency +- + I check that my writeoff is correct. 4.75 in debit and 5 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)]) + 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." +- + I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid +- + !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 == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" +- + I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid +- + !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 == 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 diff --git a/addons/account_voucher/test/case3_eur_eur.yml b/addons/account_voucher/test/case3_eur_eur.yml new file mode 100644 index 00000000000..b35daf49402 --- /dev/null +++ b/addons/account_voucher/test/case3_eur_eur.yml @@ -0,0 +1,331 @@ +- + In order to check the Account_voucher module with multi-currency in OpenERP, + I create 2 Invoices in EUR and make 2 Payments in EUR based on the currency rating on that particular date. +- + I create currency EUR in OpenERP for January of 1.000000 Rate +- + !record {model: res.currency.rate, id: jan_eur}: + currency_id: base.EUR + name: !eval "'%s-01-01' %(datetime.now().year)" + rate: 1.000000 +- + I create currency EUR in OpenERP for February of 1.000000 Rate +- + !record {model: res.currency.rate, id: feb_eur}: + currency_id: base.EUR + name: !eval "'%s-02-01' %(datetime.now().year)" + rate: 1.000000 +- + I create currency EUR in OpenERP for March of 1.000000 Rate +- + !record {model: res.currency.rate, id: mar_eur}: + currency_id: base.EUR + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 1.000000 +- + I create currency EUR in OpenERP for April of 1.000000 Rate +- + !record {model: res.currency.rate, id: apr_eur}: + currency_id: base.EUR + name: !eval "'%s-04-01' %(datetime.now().year)" + rate: 1.000000 +- + I create a bank journal with EUR as currency +- + !record {model: account.journal, id: bank_journal_EUR}: + name: Bank Journal(EUR) + code: BEUR + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.EUR + 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 Peter Lawson. +- + !record {model: res.partner, id: res_partner_peter0}: + address: + - city: paris + country_id: base.fr + name: Peter + street: 1 rue Rockfeller + type: invoice + zip: '75016' + name: Mr.Peter Lawson +- + I create the first invoice on 1st January for 150 EUR +- + !record {model: account.invoice, id: account_first_invoice_jan_eur}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.EUR + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 150.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_peter0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_eur} +- + I check that first invoice move is correct for debtor account(debit - credit == 150) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" +- + I create the second invoice on 1st February for 80 EUR +- + !record {model: account.invoice, id: account_second_invoice_feb_eur}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.EUR + date_invoice: !eval "'%s-02-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 80.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_peter0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_eur} +- + I check that second invoice move is correct for debtor account (debit - credit == 80) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 80.00), "Invoice move is incorrect for debtors account" +- + I create the first voucher of payment + +- + !python {model: account.voucher}: | + import netsvc, time + vals = {} + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 120.00, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.EUR'), + 'journal_id': ref('bank_journal_EUR'), + 'partner_id': ref('res_partner_peter0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First 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'] == 150.00: + item['amount'] = 100.00 + else: + item['amount'] = 20.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 0.00 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0.00" +- + I check that currency rate difference is 0.00 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.currency_rate_difference == 0.00), "Currency rate difference is not 0.00" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my first voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my debtor account is correct +- + I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 20 and 100 respectively +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.credit == 20.00: + assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." + elif move_line.credit == 100.00: + assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." +- + I check the residual amount of Invoice1 is 50 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) + 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 == 50.0 and move_line.amount_residual == 50.0) , "Residual amount is not correct for first Invoice" +- + I check the residual amuont of Invoice2 is 60 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) + 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 == 60.0 and move_line.amount_residual == 60.0) , "Residual amount is not correct for second Invoice" +- + I create the second voucher of payment and check to let open the debtor overpaid amount. + +- + !python {model: account.voucher}: | + import netsvc, time + vals = {} + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 120.00, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.EUR'), + 'journal_id': ref('bank_journal_EUR'), + 'partner_id': ref('res_partner_peter0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-04-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_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'] == 50.00: + item['amount'] = 50.00 + elif item['amount_unreconciled'] == 60.00: + 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 0.00 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'),('partner_id', '=', ref('res_partner_peter0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0" +- + I check that currency rate difference is 0.00 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_peter0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.currency_rate_difference == 0.00), "Currency rate difference is not 0" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_peter0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my second voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_peter0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my debtor account is correct +- + I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 70 and 50 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_peter0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.credit == 70.00: + assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." + elif move_line.credit == 50.00: + assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." +- + I check the residual amount of Invoice1 is 0 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) + 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 and move_line.amount_residual == 0) , "Residual amount is not correct for first Invoice" +- + I check the residual amuont of Invoice2 is -10 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) + 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 == -10.0 and move_line.amount_residual == -10.0) , "Residual amount is not correct for second Invoice" \ No newline at end of file diff --git a/addons/account_voucher/test/case4_cad_chf.yml b/addons/account_voucher/test/case4_cad_chf.yml new file mode 100644 index 00000000000..b6ed790dffb --- /dev/null +++ b/addons/account_voucher/test/case4_cad_chf.yml @@ -0,0 +1,194 @@ +- + In order to check the Account_voucher module with multi-currency in OpenERP, + I create an invoice in CAD and make its Payment in CHF based on the currency rating on that particular date. +- + I create currency CAD in OpenERP for January of 1.338800 Rate +- + !record {model: res.currency.rate, id: jan_cad}: + currency_id: base.CAD + name: !eval "'%s-01-01' %(datetime.now().year)" + rate: 1.338800 +- + I create currency CAD in OpenERP for March of 2.000000 Rate +- + !record {model: res.currency.rate, id: mar_cad}: + currency_id: base.CAD + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 2.000000 +- + I create currency CHF in OpenERP for January of 1.308600 Rate +- + !record {model: res.currency.rate, id: jan_chf}: + currency_id: base.CHF + name: !eval "'%s-01-01' %(datetime.now().year)" + rate: 1.308600 +- + I create currency CHF in OpenERP for March of 1.250000 Rate +- + !record {model: res.currency.rate, id: mar_chf}: + currency_id: base.CHF + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 1.250000 +- + I create a bank journal with CHF as currency +- + !record {model: account.journal, id: bank_journal_CHF}: + name: Bank Journal(CHF) + code: BCHF + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.CHF + 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 John Armani. +- + !record {model: res.partner, id: res_partner_john0}: + address: + - city: paris + country_id: base.fr + name: John + street: 1 rue Rockfeller + type: invoice + zip: '75016' + name: Mr.John Armani +- + I create the first invoice on 1st January for 200 CAD +- + !record {model: account.invoice, id: account_first_invoice_jan_cad}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.CAD + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 200.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_john0 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_cad} +- + I check that first invoice move is correct for debtor account (debit - credit == 149.39) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 149.39), "Invoice move is incorrect for debtors account" +- + I create the first voucher of payment + +- + !python {model: account.voucher}: | + import netsvc, time + vals = {} + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_john0"), ref('bank_journal_CHF'), 300.00, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 300.00, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.CHF'), + 'journal_id': ref('bank_journal_CHF'), + 'partner_id': ref('res_partner_john0'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First 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'] == 200.00: + item['amount'] = 200.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 175.0 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_john0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (voucher_id.writeoff_amount == 175.0), "Writeoff amount is not 175.0" +- + I check that currency rate difference is 49.39 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_john0'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + curr_diff = float(str(voucher_id.currency_rate_difference)) + assert (curr_diff == 49.39), "Currency rate difference is not 49.39" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_john0'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_john0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" + assert voucher_id.state == 'posted', "Voucher state is not posted" +- + I check that my debtor account is correct +- + I check that the debtor account has 1 new line with -200 as amount_currency columns and 149.39 of credit and currency is CAD($). +- + I check that my currency rate difference is correct. 49.39 in debit with no amount_currency +- + I check that my writeoff is correct. 140 credit and -175 amount_currency +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_john0'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.amount_currency == -200: + assert move_line.credit == 149.39, "Debtor account has wrong entry." + elif move_line.debit == 49.39: + assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." + elif move_line.credit == 140.00: + assert move_line.amount_currency == -175.00, "Writeoff amount is wrong." +- + I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad")) + 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 first Invoice" From 7555b99e19f373b79875cdcfb22c90773836bc49 Mon Sep 17 00:00:00 2001 From: Nhomar Hernandez Date: Sat, 8 Oct 2011 18:46:41 -0400 Subject: [PATCH 02/31] [REF] Deleted unused method _get_payment_term_lines on account_voucher, avoiding noise and so much lines in this code. bzr revid: openerp@cl-t076-283cl-20111008224641-omo5xikllr1xryg7 --- addons/account_voucher/account_voucher.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 005e5d9ab46..772c988c18a 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -652,12 +652,10 @@ class account_voucher(osv.osv): return {'value':res} def action_move_line_create(self, cr, uid, ids, context=None): - def _get_payment_term_lines(term_id, amount): - term_pool = self.pool.get('account.payment.term') - if term_id and amount: - terms = term_pool.compute(cr, uid, term_id, amount) - return terms - return False + ''' + This method create account move from voucher. + Method refactored by Vauxoo. + ''' if context is None: context = {} move_pool = self.pool.get('account.move') From 95384a0c97c06371d9d5fe16bb17801088ca8eb6 Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Sat, 8 Oct 2011 18:58:14 -0400 Subject: [PATCH 03/31] [REF] Moved variables to be initialized in the correct place bzr revid: info@vauxoo.com-20111008225814-0wzdey6gnb36tmyz --- addons/account_voucher/account_voucher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 772c988c18a..5458469220d 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -664,11 +664,14 @@ class account_voucher(osv.osv): tax_obj = self.pool.get('account.tax') seq_obj = self.pool.get('ir.sequence') for inv in self.browse(cr, uid, ids, context=context): + if inv.move_id: continue context_multi_currency = context.copy() context_multi_currency.update({'date': inv.date}) - + company_currency = inv.journal_id.company_id.currency_id.id + current_currency = inv.currency_id.id or company_currency + current_currency_obj = inv.currency_id or inv.journal_id.company_id.currency_id if inv.number: name = inv.number elif inv.journal_id.sequence_id: @@ -691,9 +694,6 @@ class account_voucher(osv.osv): move_id = move_pool.create(cr, uid, move) #create the first line manually - company_currency = inv.journal_id.company_id.currency_id.id - current_currency = inv.currency_id.id or company_currency - current_currency_obj = inv.currency_id or inv.journal_id.company_id.currency_id debit = 0.0 credit = 0.0 # TODO: is there any other alternative then the voucher type ?? From 560bab4062c1a95e87c76df8e40370b91b6545ca Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Sat, 8 Oct 2011 19:06:26 -0400 Subject: [PATCH 04/31] [REF] The method call the voucher as 'inv' it is confusing whe you are reading a lot of lines and you are refering to something called diferently bzr revid: info@vauxoo.com-20111008230626-g196xminfyudvnk6 --- addons/account_voucher/account_voucher.py | 122 +++++++++++----------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 5458469220d..4b022c1af18 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -663,33 +663,33 @@ class account_voucher(osv.osv): currency_pool = self.pool.get('res.currency') tax_obj = self.pool.get('account.tax') seq_obj = self.pool.get('ir.sequence') - for inv in self.browse(cr, uid, ids, context=context): + for voucher in self.browse(cr, uid, ids, context=context): - if inv.move_id: + if voucher.move_id: continue context_multi_currency = context.copy() - context_multi_currency.update({'date': inv.date}) - company_currency = inv.journal_id.company_id.currency_id.id - current_currency = inv.currency_id.id or company_currency - current_currency_obj = inv.currency_id or inv.journal_id.company_id.currency_id - if inv.number: - name = inv.number - elif inv.journal_id.sequence_id: - name = seq_obj.next_by_id(cr, uid, inv.journal_id.sequence_id.id) + context_multi_currency.update({'date': voucher.date}) + company_currency = voucher.journal_id.company_id.currency_id.id + current_currency = voucher.currency_id.id or company_currency + current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id + if voucher.number: + name = voucher.number + elif voucher.journal_id.sequence_id: + name = seq_obj.next_by_id(cr, uid, voucher.journal_id.sequence_id.id) else: raise osv.except_osv(_('Error !'), _('Please define a sequence on the journal !')) - if not inv.reference: + if not voucher.reference: ref = name.replace('/','') else: - ref = inv.reference + ref = voucher.reference move = { 'name': name, - 'journal_id': inv.journal_id.id, - 'narration': inv.narration, - 'date': inv.date, + 'journal_id': voucher.journal_id.id, + 'narration': voucher.narration, + 'date': voucher.date, 'ref': ref, - 'period_id': inv.period_id and inv.period_id.id or False + 'period_id': voucher.period_id and voucher.period_id.id or False } move_id = move_pool.create(cr, uid, move) @@ -698,10 +698,10 @@ class account_voucher(osv.osv): credit = 0.0 # TODO: is there any other alternative then the voucher type ?? # -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt - if inv.type in ('purchase', 'payment'): - credit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount, context=context_multi_currency) - elif inv.type in ('sale', 'receipt'): - debit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount, context=context_multi_currency) + if voucher.type in ('purchase', 'payment'): + credit = currency_pool.compute(cr, uid, current_currency, company_currency, voucher.amount, context=context_multi_currency) + elif voucher.type in ('sale', 'receipt'): + debit = currency_pool.compute(cr, uid, current_currency, company_currency, voucher.amount, context=context_multi_currency) if debit < 0: credit = -debit debit = 0.0 @@ -711,32 +711,32 @@ class account_voucher(osv.osv): sign = debit - credit < 0 and -1 or 1 #create the first line of the voucher, the payment made move_line = { - 'name': inv.name or '/', + 'name': voucher.name or '/', 'debit': debit, 'credit': credit, - 'account_id': inv.account_id.id, + 'account_id': voucher.account_id.id, 'move_id': move_id, - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, - 'partner_id': inv.partner_id.id, + 'journal_id': voucher.journal_id.id, + 'period_id': voucher.period_id.id, + 'partner_id': voucher.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, - 'amount_currency': company_currency <> current_currency and sign * inv.amount or 0.0, - 'date': inv.date, - 'date_maturity': inv.date_due + 'amount_currency': company_currency <> current_currency and sign * voucher.amount or 0.0, + 'date': voucher.date, + 'date_maturity': voucher.date_due } move_line_pool.create(cr, uid, move_line) rec_list_ids = [] line_total = debit - credit - if inv.type == 'sale': - line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, inv.tax_amount, context=context_multi_currency) - elif inv.type == 'purchase': - line_total = line_total + currency_pool.compute(cr, uid, current_currency, company_currency, inv.tax_amount, context=context_multi_currency) + if voucher.type == 'sale': + line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) + elif voucher.type == 'purchase': + line_total = line_total + currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) - for line in inv.line_ids: + for line in voucher.line_ids: #create one move line per voucher line where amount is not 0.0 if not line.amount: continue - #we check if the voucher line is fully paid or not and create a move line to balance the payment and initial invoice if needed + #we check if the voucher line is fully paid or not and create a move line to balance the payment and initial voucheroice if needed if line.amount == line.amount_unreconciled: amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context_multi_currency) amount_residual = line.move_line_id.amount_residual - amount #residual amount in company currency @@ -744,18 +744,18 @@ class account_voucher(osv.osv): amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context_multi_currency) amount_residual = 0.0 move_line = { - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, + 'journal_id': voucher.journal_id.id, + 'period_id': voucher.period_id.id, 'name': line.name or '/', 'account_id': line.account_id.id, 'move_id': move_id, - 'partner_id': inv.partner_id.id, + 'partner_id': voucher.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False, 'quantity': 1, 'credit': 0.0, 'debit': 0.0, - 'date': inv.date + 'date': voucher.date } if amount < 0: amount = -amount @@ -770,9 +770,9 @@ class account_voucher(osv.osv): line_total -= amount move_line['credit'] = amount - if inv.tax_id and inv.type in ('sale', 'purchase'): + if voucher.tax_id and voucher.type in ('sale', 'purchase'): move_line.update({ - 'account_tax_id': inv.tax_id.id, + 'account_tax_id': voucher.tax_id.id, }) if move_line.get('account_tax_id', False): tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0] @@ -785,36 +785,36 @@ class account_voucher(osv.osv): # Change difference entry if amount_residual: - if not inv.exchange_acc_id.id: + if not voucher.exchange_acc_id.id: raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) move_line = { - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, + 'journal_id': voucher.journal_id.id, + 'period_id': voucher.period_id.id, 'name': _('change')+': '+(line.name or '/'), 'account_id': line.account_id.id, 'move_id': move_id, - 'partner_id': inv.partner_id.id, + 'partner_id': voucher.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, 'amount_currency': 0.0, 'quantity': 1, 'credit': amount_residual > 0 and amount_residual or 0.0, 'debit': amount_residual < 0 and -amount_residual or 0.0, - 'date': inv.date + 'date': voucher.date } new_id = move_line_pool.create(cr, uid, move_line) move_line = { - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, + 'journal_id': voucher.journal_id.id, + 'period_id': voucher.period_id.id, 'name': _('change')+': '+(line.name or '/'), - 'account_id': inv.exchange_acc_id.id, + 'account_id': voucher.exchange_acc_id.id, 'move_id': move_id, 'amount_currency': 0.0, - 'partner_id': inv.partner_id.id, + 'partner_id': voucher.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, 'quantity': 1, 'debit': amount_residual > 0 and amount_residual or 0.0, 'credit': amount_residual < 0 and -amount_residual or 0.0, - 'date': inv.date + 'date': voucher.date } move_line_pool.create(cr, uid, move_line) rec_ids.append(new_id) @@ -826,35 +826,35 @@ class account_voucher(osv.osv): diff = line_total account_id = False write_off_name = '' - if inv.payment_option == 'with_writeoff': - account_id = inv.writeoff_acc_id.id - write_off_name = inv.comment - elif inv.type in ('sale', 'receipt'): - account_id = inv.partner_id.property_account_receivable.id + if voucher.payment_option == 'with_writeoff': + account_id = voucher.writeoff_acc_id.id + write_off_name = voucher.comment + elif voucher.type in ('sale', 'receipt'): + account_id = voucher.partner_id.property_account_receivable.id else: - account_id = inv.partner_id.property_account_payable.id + account_id = voucher.partner_id.property_account_payable.id move_line = { 'name': write_off_name or name, 'account_id': account_id, 'move_id': move_id, - 'partner_id': inv.partner_id.id, - 'date': inv.date, + 'partner_id': voucher.partner_id.id, + 'date': voucher.date, 'credit': diff > 0 and diff or 0.0, 'debit': diff < 0 and -diff or 0.0, #'amount_currency': company_currency <> current_currency and currency_pool.compute(cr, uid, company_currency, current_currency, diff * -1, context=context_multi_currency) or 0.0, #'currency_id': company_currency <> current_currency and current_currency or False, } move_line_pool.create(cr, uid, move_line) - self.write(cr, uid, [inv.id], { + self.write(cr, uid, [voucher.id], { 'move_id': move_id, 'state': 'posted', 'number': name, }) - if inv.journal_id.entry_posted: + if voucher.journal_id.entry_posted: move_pool.post(cr, uid, [move_id], context={}) for rec_ids in rec_list_ids: if len(rec_ids) >= 2: - move_line_pool.reconcile_partial(cr, uid, rec_ids, writeoff_acc_id=inv.exchange_acc_id.id, writeoff_period_id=inv.period_id.id, writeoff_journal_id=inv.journal_id.id) + move_line_pool.reconcile_partial(cr, uid, rec_ids, writeoff_acc_id=voucher.exchange_acc_id.id, writeoff_period_id=voucher.period_id.id, writeoff_journal_id=voucher.journal_id.id) return True def copy(self, cr, uid, id, default={}, context=None): From 81b73777fad5b719513f3698e8d39e71174a3a74 Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Sat, 8 Oct 2011 20:31:19 -0400 Subject: [PATCH 05/31] [REF] Send outside action_move_line_create the process to create the account_move record bzr revid: info@vauxoo.com-20111009003119-q3ab9jg72m4tpjvc --- addons/account_voucher/account_voucher.py | 55 ++++++++++++++--------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 4b022c1af18..ed4f9d221e9 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -651,6 +651,37 @@ class account_voucher(osv.osv): res['account_id'] = account_id return {'value':res} + def action_move_create(self, cr, uid, voucher_id, context=None): + ''' + This method create the account move related to voucher. + @voucher_id: voucher_id what we are creating account_move. + ''' + move_obj = self.pool.get('account.move') + seq_obj = self.pool.get('ir.sequence') + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + if voucher_brw.number: + name = voucher_brw.number + elif voucher_brw.journal_id.sequence_id: + name = seq_obj.next_by_id(cr, uid, voucher_brw.journal_id.sequence_id.id) + else: + raise osv.except_osv(_('Error !'), + _('Please define a sequence on the journal !')) + if not voucher_brw.reference: + ref = name.replace('/','') + else: + ref = voucher_brw.reference + + move = { + 'name': name, + 'journal_id': voucher_brw.journal_id.id, + 'narration': voucher_brw.narration, + 'date': voucher_brw.date, + 'ref': ref, + 'period_id': voucher_brw.period_id and voucher_brw.period_id.id or False + } + move_id = move_obj.create(cr, uid, move) + return move_id + def action_move_line_create(self, cr, uid, ids, context=None): ''' This method create account move from voucher. @@ -672,27 +703,9 @@ class account_voucher(osv.osv): company_currency = voucher.journal_id.company_id.currency_id.id current_currency = voucher.currency_id.id or company_currency current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id - if voucher.number: - name = voucher.number - elif voucher.journal_id.sequence_id: - name = seq_obj.next_by_id(cr, uid, voucher.journal_id.sequence_id.id) - else: - raise osv.except_osv(_('Error !'), _('Please define a sequence on the journal !')) - if not voucher.reference: - ref = name.replace('/','') - else: - ref = voucher.reference - - move = { - 'name': name, - 'journal_id': voucher.journal_id.id, - 'narration': voucher.narration, - 'date': voucher.date, - 'ref': ref, - 'period_id': voucher.period_id and voucher.period_id.id or False - } - move_id = move_pool.create(cr, uid, move) - + #Create the account move record. + move_id = self.action_move_create(cr,uid,voucher.id) + name = move_pool.browse(cr, uid, move_id, context=context).name #create the first line manually debit = 0.0 credit = 0.0 From af970c6babd3ed4b9493e6dfc60e5eea7efbf48d Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Sat, 8 Oct 2011 22:43:46 -0400 Subject: [PATCH 06/31] [REF] Creation of the first line in an external method call first_move_line_create bzr revid: info@vauxoo.com-20111009024346-ertt0atg17d8t827 --- addons/account_voucher/account_voucher.py | 87 +++++++++++++---------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index ed4f9d221e9..d6a7e4f78d1 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -651,12 +651,56 @@ class account_voucher(osv.osv): res['account_id'] = account_id return {'value':res} + def first_move_line_create(self, cr, uid, voucher_id, move_id, context=None): + ''' + Creation of first line in a voucher with fixed partner. + @voucher_id: id of the voucher. + @move_id: account move where this line will be added. + ''' + move_line_obj = self.pool.get('account.move.line') + currency_obj = self.pool.get('res.currency') + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + company_currency = voucher_brw.journal_id.company_id.currency_id.id + current_currency = voucher_brw.currency_id.id + context_multi_currency = context.copy() + context_multi_currency.update({'date': voucher.date}) + if current_currency <> company_currency: context = context_multi_currency + debit = 0.0 + credit = 0.0 + # TODO: is there any other alternative then the voucher type ?? + # ANSWER: We can have payment and receipt "In Advance". + # TODO: Make this logic available. + # -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt + if voucher_brw.type in ('purchase', 'payment'): + credit = currency_obj.compute(cr, uid, current_currency, company_currency, voucher_brw.amount, context) + elif voucher_brw.type in ('sale', 'receipt'): + debit = currency_obj.compute(cr, uid, current_currency, company_currency, voucher_brw.amount, context) + if debit < 0: credit = -debit; debit = 0.0 + if credit < 0: debit = -credit; credit = 0.0 + sign = debit - credit < 0 and -1 or 1 + #create the first line of the voucher + move_line = { + 'name': voucher_brw.name or '/', + 'debit': debit, + 'credit': credit, + 'account_id': voucher_brw.account_id.id, + 'move_id': move_id, + 'journal_id': voucher_brw.journal_id.id, + 'period_id': voucher_brw.period_id.id, + 'partner_id': voucher_brw.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'amount_currency': company_currency <> current_currency and sign * voucher_brw.amount or 0.0, + 'date': voucher_brw.date, + 'date_maturity': voucher_brw.date_due + } + return move_line_obj.create(cr, uid, move_line, context) + def action_move_create(self, cr, uid, voucher_id, context=None): ''' This method create the account move related to voucher. @voucher_id: voucher_id what we are creating account_move. ''' - move_obj = self.pool.get('account.move') + move_obj = self.pool.get('account.move') seq_obj = self.pool.get('ir.sequence') voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) if voucher_brw.number: @@ -698,48 +742,19 @@ class account_voucher(osv.osv): if voucher.move_id: continue - context_multi_currency = context.copy() - context_multi_currency.update({'date': voucher.date}) company_currency = voucher.journal_id.company_id.currency_id.id current_currency = voucher.currency_id.id or company_currency current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id #Create the account move record. move_id = self.action_move_create(cr,uid,voucher.id) + # Get the name of the acc_move just created name = move_pool.browse(cr, uid, move_id, context=context).name - #create the first line manually - debit = 0.0 - credit = 0.0 - # TODO: is there any other alternative then the voucher type ?? - # -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt - if voucher.type in ('purchase', 'payment'): - credit = currency_pool.compute(cr, uid, current_currency, company_currency, voucher.amount, context=context_multi_currency) - elif voucher.type in ('sale', 'receipt'): - debit = currency_pool.compute(cr, uid, current_currency, company_currency, voucher.amount, context=context_multi_currency) - if debit < 0: - credit = -debit - debit = 0.0 - if credit < 0: - debit = -credit - credit = 0.0 - sign = debit - credit < 0 and -1 or 1 - #create the first line of the voucher, the payment made - move_line = { - 'name': voucher.name or '/', - 'debit': debit, - 'credit': credit, - 'account_id': voucher.account_id.id, - 'move_id': move_id, - 'journal_id': voucher.journal_id.id, - 'period_id': voucher.period_id.id, - 'partner_id': voucher.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'amount_currency': company_currency <> current_currency and sign * voucher.amount or 0.0, - 'date': voucher.date, - 'date_maturity': voucher.date_due - } - move_line_pool.create(cr, uid, move_line) + #Create the first line of the voucher, the payment made + c + move_line_id = self.first_move_line_create(cr,uid,voucher.id, move_id, context) + move_line_brw = move_line_pool.browse(cr,uid,move_line_id, context) + line_total = move_line_brw.debit - move_line_brw.credit rec_list_ids = [] - line_total = debit - credit if voucher.type == 'sale': line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) elif voucher.type == 'purchase': From 451de7a5ca38eaa1997711bc366ef834afba7230 Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Sat, 8 Oct 2011 23:41:02 -0400 Subject: [PATCH 07/31] [REF] voucher_move_line_create was created to generate all lines of acc move in an external method in this way in localization envoroment we can override just this method. bzr revid: info@vauxoo.com-20111009034102-oqss5lzmh2vcbx0k --- addons/account_voucher/account_voucher.py | 208 ++++++++++++---------- 1 file changed, 114 insertions(+), 94 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index d6a7e4f78d1..30166503466 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -663,10 +663,9 @@ class account_voucher(osv.osv): company_currency = voucher_brw.journal_id.company_id.currency_id.id current_currency = voucher_brw.currency_id.id context_multi_currency = context.copy() - context_multi_currency.update({'date': voucher.date}) + context_multi_currency.update({'date': voucher_brw.date}) if current_currency <> company_currency: context = context_multi_currency - debit = 0.0 - credit = 0.0 + debit = credit = 0.0 # TODO: is there any other alternative then the voucher type ?? # ANSWER: We can have payment and receipt "In Advance". # TODO: Make this logic available. @@ -726,6 +725,115 @@ class account_voucher(osv.osv): move_id = move_obj.create(cr, uid, move) return move_id + def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, context=None): + ''' + Create all ther rest of account move lines on accout move object. + @voucher_id: Voucher id what we are working with + @line_total: Total of the first line. + @move_id: Account move wher this lines will be joined. + ''' + move_line_obj = self.pool.get('account.move.line') + currency_obj = self.pool.get('res.currency') + tot_line = line_total + rec_lst_ids = [] + + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + company_currency = voucher_brw.journal_id.company_id.currency_id.id + current_currency = voucher_brw.currency_id.id + context_multi_currency = context.copy() + context_multi_currency.update({'date': voucher_brw.date}) + if current_currency <> company_currency: context = context_multi_currency + for line in voucher_brw.line_ids: + #create one move line per voucher line where amount is not 0.0 + if not line.amount: + continue + #we check if the voucher line is fully paid or not and create a move line to balance the payment and initial invoice if needed + if line.amount == line.amount_unreconciled: + amount = currency_obj.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context) + amount_residual = line.move_line_id.amount_residual - amount #residual amount in company currency + else: + amount = currency_obj.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context) + amount_residual = 0.0 + move_line = { + 'journal_id': voucher_brw.journal_id.id, + 'period_id': voucher_brw.period_id.id, + 'name': line.name or '/', + 'account_id': line.account_id.id, + 'move_id': move_id, + 'partner_id': voucher_brw.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False, + 'quantity': 1, + 'credit': 0.0, + 'debit': 0.0, + 'date': voucher_brw.date + } + if amount < 0: + amount = -amount + if line.type == 'dr': line.type = 'cr' else: line.type = 'dr' + + if (line.type=='dr'): + tot_line += amount + move_line['debit'] = amount + else: + tot_line -= amount + move_line['credit'] = amount + + if voucher_brw.tax_id and voucher_brw.type in ('sale', 'purchase'): + move_line.update({ + 'account_tax_id': voucher_brw.tax_id.id, + }) + + if move_line.get('account_tax_id', False): + tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0] + if not (tax_data.base_code_id and tax_data.tax_code_id): + raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name)) + + sign = (move_line['debit'] - move_line['credit']) < 0 and -1 or 1 + move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0 + voucher_line = move_line_obj.create(cr, uid, move_line) + rec_ids = [voucher_line, line.move_line_id.id] + + if amount_residual: # Change difference entry + if not inv.exchange_acc_id.id: + raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) + move_line = { + 'journal_id': inv.journal_id.id, + 'period_id': inv.period_id.id, + 'name': _('change')+': '+(line.name or '/'), + 'account_id': line.account_id.id, + 'move_id': move_id, + 'partner_id': inv.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'amount_currency': 0.0, + 'quantity': 1, + 'credit': amount_residual > 0 and amount_residual or 0.0, + 'debit': amount_residual < 0 and -amount_residual or 0.0, + 'date': inv.date + } + new_id = move_line_pool.create(cr, uid, move_line) + move_line = { + 'journal_id': inv.journal_id.id, + 'period_id': inv.period_id.id, + 'name': _('change')+': '+(line.name or '/'), + 'account_id': inv.exchange_acc_id.id, + 'move_id': move_id, + 'amount_currency': 0.0, + 'partner_id': inv.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'quantity': 1, + 'debit': amount_residual > 0 and amount_residual or 0.0, + 'credit': amount_residual < 0 and -amount_residual or 0.0, + 'date': inv.date + } + move_line_pool.create(cr, uid, move_line) + rec_ids.append(new_id) + + if line.move_line_id.id: + rec_lst_ids.append(rec_ids) + + return (tot_line, rec_lst_ids) + def action_move_line_create(self, cr, uid, ids, context=None): ''' This method create account move from voucher. @@ -750,7 +858,6 @@ class account_voucher(osv.osv): # Get the name of the acc_move just created name = move_pool.browse(cr, uid, move_id, context=context).name #Create the first line of the voucher, the payment made - c move_line_id = self.first_move_line_create(cr,uid,voucher.id, move_id, context) move_line_brw = move_line_pool.browse(cr,uid,move_line_id, context) line_total = move_line_brw.debit - move_line_brw.credit @@ -759,96 +866,9 @@ class account_voucher(osv.osv): line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) elif voucher.type == 'purchase': line_total = line_total + currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) - - for line in voucher.line_ids: - #create one move line per voucher line where amount is not 0.0 - if not line.amount: - continue - #we check if the voucher line is fully paid or not and create a move line to balance the payment and initial voucheroice if needed - if line.amount == line.amount_unreconciled: - amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context_multi_currency) - amount_residual = line.move_line_id.amount_residual - amount #residual amount in company currency - else: - amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context_multi_currency) - amount_residual = 0.0 - move_line = { - 'journal_id': voucher.journal_id.id, - 'period_id': voucher.period_id.id, - 'name': line.name or '/', - 'account_id': line.account_id.id, - 'move_id': move_id, - 'partner_id': voucher.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False, - 'quantity': 1, - 'credit': 0.0, - 'debit': 0.0, - 'date': voucher.date - } - if amount < 0: - amount = -amount - if line.type == 'dr': - line.type = 'cr' - else: - line.type = 'dr' - if (line.type=='dr'): - line_total += amount - move_line['debit'] = amount - else: - line_total -= amount - move_line['credit'] = amount - - if voucher.tax_id and voucher.type in ('sale', 'purchase'): - move_line.update({ - 'account_tax_id': voucher.tax_id.id, - }) - if move_line.get('account_tax_id', False): - tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0] - if not (tax_data.base_code_id and tax_data.tax_code_id): - raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name)) - sign = (move_line['debit'] - move_line['credit']) < 0 and -1 or 1 - move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0 - voucher_line = move_line_pool.create(cr, uid, move_line) - rec_ids = [voucher_line, line.move_line_id.id] - - # Change difference entry - if amount_residual: - if not voucher.exchange_acc_id.id: - raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) - move_line = { - 'journal_id': voucher.journal_id.id, - 'period_id': voucher.period_id.id, - 'name': _('change')+': '+(line.name or '/'), - 'account_id': line.account_id.id, - 'move_id': move_id, - 'partner_id': voucher.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'amount_currency': 0.0, - 'quantity': 1, - 'credit': amount_residual > 0 and amount_residual or 0.0, - 'debit': amount_residual < 0 and -amount_residual or 0.0, - 'date': voucher.date - } - new_id = move_line_pool.create(cr, uid, move_line) - move_line = { - 'journal_id': voucher.journal_id.id, - 'period_id': voucher.period_id.id, - 'name': _('change')+': '+(line.name or '/'), - 'account_id': voucher.exchange_acc_id.id, - 'move_id': move_id, - 'amount_currency': 0.0, - 'partner_id': voucher.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'quantity': 1, - 'debit': amount_residual > 0 and amount_residual or 0.0, - 'credit': amount_residual < 0 and -amount_residual or 0.0, - 'date': voucher.date - } - move_line_pool.create(cr, uid, move_line) - rec_ids.append(new_id) - - if line.move_line_id.id: - rec_list_ids.append(rec_ids) + ############################################################ + #create one move line per voucher line where amount is not 0.0 + line_total, rec_list_ids = self.voucher_move_line_create(cr, uid, voucher.id, line_total, move_id, context) if not currency_pool.is_zero(cr, uid, current_currency_obj, line_total): diff = line_total From 14b8b8d52b918974f22d0ad66762a09088b365b5 Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Sun, 9 Oct 2011 00:08:36 -0400 Subject: [PATCH 08/31] [REF] writeoff_move_line_create We put in an external methos the writeoff process bzr revid: info@vauxoo.com-20111009040836-tqy6erz2qu6ih3uw --- addons/account_voucher/account_voucher.py | 78 ++++++++++++++++------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 30166503466..4187337a103 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -770,7 +770,10 @@ class account_voucher(osv.osv): } if amount < 0: amount = -amount - if line.type == 'dr': line.type = 'cr' else: line.type = 'dr' + if line.type == 'dr': + line.type = 'cr' + else: + line.type = 'dr' if (line.type=='dr'): tot_line += amount @@ -834,6 +837,54 @@ class account_voucher(osv.osv): return (tot_line, rec_lst_ids) + + def writeoff_move_line_create(self, cr, uid, voucher_id, line_total, move_id, name, context= None): + ''' + Create the writeoff move line + @voucher_id: Voucher id what we are working with + @line_total: Total of the first line. + @move_id: Account move wher this lines will be joined. + ''' + move_line_obj = self.pool.get('account.move.line') + currency_obj = self.pool.get('res.currency') + move_line_id = False + + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + company_currency = voucher_brw.journal_id.company_id.currency_id.id + current_currency = voucher_brw.currency_id.id + context_multi_currency = context.copy() + context_multi_currency.update({'date': voucher_brw.date}) + if current_currency <> company_currency: context = context_multi_currency + + current_currency_obj = voucher_brw.currency_id or voucher_brw.journal_id.company_id.currency_id + + if not currency_obj.is_zero(cr, uid, current_currency_obj, line_total): + diff = line_total + account_id = False + write_off_name = '' + if voucher_brw.payment_option == 'with_writeoff': + account_id = voucher_brw.writeoff_acc_id.id + write_off_name = voucher_brw.comment + elif voucher_brw.type in ('sale', 'receipt'): + account_id = voucher_brw.partner_id.property_account_receivable.id + else: + account_id = voucher_brw.partner_id.property_account_payable.id + move_line = { + 'name': write_off_name or name, + 'account_id': account_id, + 'move_id': move_id, + 'partner_id': voucher_brw.partner_id.id, + 'date': voucher_brw.date, + 'credit': diff > 0 and diff or 0.0, + 'debit': diff < 0 and -diff or 0.0, + #'amount_currency': company_currency <> current_currency and currency_obj.compute(cr, uid, company_currency, current_currency, diff * -1, context=context_multi_currency) or 0.0, + #'currency_id': company_currency <> current_currency and current_currency or False, + } + move_line_id = move_line_obj.create(cr, uid, move_line) + + return move_line_id + + def action_move_line_create(self, cr, uid, ids, context=None): ''' This method create account move from voucher. @@ -870,29 +921,8 @@ class account_voucher(osv.osv): #create one move line per voucher line where amount is not 0.0 line_total, rec_list_ids = self.voucher_move_line_create(cr, uid, voucher.id, line_total, move_id, context) - if not currency_pool.is_zero(cr, uid, current_currency_obj, line_total): - diff = line_total - account_id = False - write_off_name = '' - if voucher.payment_option == 'with_writeoff': - account_id = voucher.writeoff_acc_id.id - write_off_name = voucher.comment - elif voucher.type in ('sale', 'receipt'): - account_id = voucher.partner_id.property_account_receivable.id - else: - account_id = voucher.partner_id.property_account_payable.id - move_line = { - 'name': write_off_name or name, - 'account_id': account_id, - 'move_id': move_id, - 'partner_id': voucher.partner_id.id, - 'date': voucher.date, - 'credit': diff > 0 and diff or 0.0, - 'debit': diff < 0 and -diff or 0.0, - #'amount_currency': company_currency <> current_currency and currency_pool.compute(cr, uid, company_currency, current_currency, diff * -1, context=context_multi_currency) or 0.0, - #'currency_id': company_currency <> current_currency and current_currency or False, - } - move_line_pool.create(cr, uid, move_line) + #create the writeoff line if needed + ml_writeoff_id = self.writeoff_move_line_create(cr, uid, voucher.id, line_total, move_id, name, context) self.write(cr, uid, [voucher.id], { 'move_id': move_id, 'state': 'posted', From dbc307b540957392f827bcdfb8847fbe4493558a Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Sun, 9 Oct 2011 00:15:19 -0400 Subject: [PATCH 09/31] [REF] Just added a final comment bzr revid: info@vauxoo.com-20111009041519-10ab4qb46w8sc65k --- addons/account_voucher/account_voucher.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 4187337a103..998b5291d2b 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -923,6 +923,7 @@ class account_voucher(osv.osv): #create the writeoff line if needed ml_writeoff_id = self.writeoff_move_line_create(cr, uid, voucher.id, line_total, move_id, name, context) + #We put posted the account move. self.write(cr, uid, [voucher.id], { 'move_id': move_id, 'state': 'posted', @@ -930,6 +931,7 @@ class account_voucher(osv.osv): }) if voucher.journal_id.entry_posted: move_pool.post(cr, uid, [move_id], context={}) + #We automatically reconcile the account move lines. for rec_ids in rec_list_ids: if len(rec_ids) >= 2: move_line_pool.reconcile_partial(cr, uid, rec_ids, writeoff_acc_id=voucher.exchange_acc_id.id, writeoff_period_id=voucher.period_id.id, writeoff_journal_id=voucher.journal_id.id) From 4a58b3e8d363c2441fe0e3499ffa2e651dcad15e Mon Sep 17 00:00:00 2001 From: "javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 15:39:34 -0400 Subject: [PATCH 10/31] [REF] Modifying action_move_create method to return a dict, rename action_move_create method to account_move_get, added docstring of account_move_get, methods follows the guideline. bzr revid: javier@vauxoo.com-20111010193934-cnwxv0j63tln8gro --- addons/account_voucher/account_voucher.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 998b5291d2b..bfb0e5c29b2 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -694,10 +694,15 @@ class account_voucher(osv.osv): } return move_line_obj.create(cr, uid, move_line, context) - def action_move_create(self, cr, uid, voucher_id, context=None): + def account_move_get(self, cr, uid, voucher_id, context=None): ''' This method create the account move related to voucher. - @voucher_id: voucher_id what we are creating account_move. + + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param voucher_id: Id of voucher what we are creating account_move. + @param context: optional context dictionary + @return: dictionary which contains information regarding account move ''' move_obj = self.pool.get('account.move') seq_obj = self.pool.get('ir.sequence') @@ -722,8 +727,7 @@ class account_voucher(osv.osv): 'ref': ref, 'period_id': voucher_brw.period_id and voucher_brw.period_id.id or False } - move_id = move_obj.create(cr, uid, move) - return move_id + return move def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, context=None): ''' @@ -905,7 +909,7 @@ class account_voucher(osv.osv): current_currency = voucher.currency_id.id or company_currency current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id #Create the account move record. - move_id = self.action_move_create(cr,uid,voucher.id) + move_id = move_pool.create(cr, uid, self.account_move_get(cr,uid,voucher.id)) # Get the name of the acc_move just created name = move_pool.browse(cr, uid, move_id, context=context).name #Create the first line of the voucher, the payment made From 5141bf3d8821942b4653f0931366e5d280bb2386 Mon Sep 17 00:00:00 2001 From: "javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 17:08:06 -0400 Subject: [PATCH 11/31] [REF] Modifying first_move_line_create method to return a dict, rename first_move_line_create method to first_move_line_get added docstring of first_move_line_get method follows the guideline. bzr revid: javier@vauxoo.com-20111010210806-5b4zh7gb3hdabq6k --- addons/account_voucher/account_voucher.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index bfb0e5c29b2..ae216c3a8ed 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -651,11 +651,16 @@ class account_voucher(osv.osv): res['account_id'] = account_id return {'value':res} - def first_move_line_create(self, cr, uid, voucher_id, move_id, context=None): + def first_move_line_get(self, cr, uid, voucher_id, move_id, context=None): ''' - Creation of first line in a voucher with fixed partner. - @voucher_id: id of the voucher. - @move_id: account move where this line will be added. + Set a dict to be use to create the first account move line of voucher. + + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param voucher_id: Id of voucher what we are creating account_move. + @param move_id: Id of account move where this line will be added. + @param context: optional context dictionary + @return: dictionary which contains information regarding account move line ''' move_line_obj = self.pool.get('account.move.line') currency_obj = self.pool.get('res.currency') @@ -677,7 +682,7 @@ class account_voucher(osv.osv): if debit < 0: credit = -debit; debit = 0.0 if credit < 0: debit = -credit; credit = 0.0 sign = debit - credit < 0 and -1 or 1 - #create the first line of the voucher + #set the first line of the voucher move_line = { 'name': voucher_brw.name or '/', 'debit': debit, @@ -692,7 +697,7 @@ class account_voucher(osv.osv): 'date': voucher_brw.date, 'date_maturity': voucher_brw.date_due } - return move_line_obj.create(cr, uid, move_line, context) + return move_line def account_move_get(self, cr, uid, voucher_id, context=None): ''' @@ -913,7 +918,7 @@ class account_voucher(osv.osv): # Get the name of the acc_move just created name = move_pool.browse(cr, uid, move_id, context=context).name #Create the first line of the voucher, the payment made - move_line_id = self.first_move_line_create(cr,uid,voucher.id, move_id, context) + move_line_id = move_line_pool.create(cr, uid, self.first_move_line_get(cr,uid,voucher.id, move_id, context), context) move_line_brw = move_line_pool.browse(cr,uid,move_line_id, context) line_total = move_line_brw.debit - move_line_brw.credit rec_list_ids = [] From 8a8f4923e0668d03849ad95ba6c6ac74ce1d0ae7 Mon Sep 17 00:00:00 2001 From: "javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 18:19:15 -0400 Subject: [PATCH 12/31] [REF] Modifying writeoff_move_line_create method to return a dict, rename writeoff_move_line_create method to writeoff_move_line_get, added docstring of writeoff_move_line_get methods follows the guideline. bzr revid: javier@vauxoo.com-20111010221915-crmjncln12cnjpwv --- addons/account_voucher/account_voucher.py | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index ae216c3a8ed..8f9ed49529c 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -847,16 +847,22 @@ class account_voucher(osv.osv): return (tot_line, rec_lst_ids) - def writeoff_move_line_create(self, cr, uid, voucher_id, line_total, move_id, name, context= None): + def writeoff_move_line_get(self, cr, uid, voucher_id, line_total, move_id, name, context= None): ''' - Create the writeoff move line - @voucher_id: Voucher id what we are working with - @line_total: Total of the first line. - @move_id: Account move wher this lines will be joined. + Set a dict to be use to create the writeoff move line. + + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param voucher_id: Id of voucher what we are creating account_move. + @param line_total: Amount total of the first account move line of the voucher. + @param move_id: Id of account move where this line will be added. + @param name: Description of account move line. + @param context: optional context dictionary + @return: dictionary which contains information regarding account move line ''' move_line_obj = self.pool.get('account.move.line') currency_obj = self.pool.get('res.currency') - move_line_id = False + move_line = {} voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) company_currency = voucher_brw.journal_id.company_id.currency_id.id @@ -889,9 +895,8 @@ class account_voucher(osv.osv): #'amount_currency': company_currency <> current_currency and currency_obj.compute(cr, uid, company_currency, current_currency, diff * -1, context=context_multi_currency) or 0.0, #'currency_id': company_currency <> current_currency and current_currency or False, } - move_line_id = move_line_obj.create(cr, uid, move_line) - - return move_line_id + + return move_line def action_move_line_create(self, cr, uid, ids, context=None): @@ -931,8 +936,10 @@ class account_voucher(osv.osv): line_total, rec_list_ids = self.voucher_move_line_create(cr, uid, voucher.id, line_total, move_id, context) #create the writeoff line if needed - ml_writeoff_id = self.writeoff_move_line_create(cr, uid, voucher.id, line_total, move_id, name, context) - #We put posted the account move. + ml_writeoff = self.writeoff_move_line_get(cr, uid, voucher.id, line_total, move_id, name, context) + if ml_writeoff: + ml_writeoff_id = move_line_pool.create(cr, uid, ml_writeoff, context) + #We put posted the voucher. self.write(cr, uid, [voucher.id], { 'move_id': move_id, 'state': 'posted', From a864b4715674cd9909d7c24c4b3b8fa9ec9426b0 Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 19:10:46 -0400 Subject: [PATCH 13/31] [REF] Changing to an external method curr currency and comp currency renaming a method from create to get bzr revid: javier@vauxoo.com-20111010231046-f6j4us30lscj65lz --- addons/account_voucher/account_voucher.py | 33 +++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 8f9ed49529c..1a34103fdc4 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -665,8 +665,8 @@ class account_voucher(osv.osv): move_line_obj = self.pool.get('account.move.line') currency_obj = self.pool.get('res.currency') voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = voucher_brw.journal_id.company_id.currency_id.id - current_currency = voucher_brw.currency_id.id + company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) context_multi_currency = context.copy() context_multi_currency.update({'date': voucher_brw.date}) if current_currency <> company_currency: context = context_multi_currency @@ -747,8 +747,8 @@ class account_voucher(osv.osv): rec_lst_ids = [] voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = voucher_brw.journal_id.company_id.currency_id.id - current_currency = voucher_brw.currency_id.id + company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) context_multi_currency = context.copy() context_multi_currency.update({'date': voucher_brw.date}) if current_currency <> company_currency: context = context_multi_currency @@ -865,8 +865,8 @@ class account_voucher(osv.osv): move_line = {} voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = voucher_brw.journal_id.company_id.currency_id.id - current_currency = voucher_brw.currency_id.id + company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) context_multi_currency = context.copy() context_multi_currency.update({'date': voucher_brw.date}) if current_currency <> company_currency: context = context_multi_currency @@ -898,11 +898,22 @@ class account_voucher(osv.osv): return move_line - + def _get_company_currency(self, cr, uid, voucher_id, context=None): + ''' + @voucher_id: Id of the voucher what i want to obtain company currency. + ''' + return self.pool.get('account.voucher').browse(cr,uid,voucher_id,context).journal_id.company_id.currency_id.id + + def _get_current_currency(self, cr, uid, voucher_id, context=None): + ''' + @voucher_id: Id of the voucher what i want to obtain current currency. + ''' + voucher = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + return voucher.currency_id.id or _get_company_currency(voucher.id) + def action_move_line_create(self, cr, uid, ids, context=None): ''' - This method create account move from voucher. - Method refactored by Vauxoo. + Create account move for account voucher. ''' if context is None: context = {} @@ -915,8 +926,8 @@ class account_voucher(osv.osv): if voucher.move_id: continue - company_currency = voucher.journal_id.company_id.currency_id.id - current_currency = voucher.currency_id.id or company_currency + company_currency = _get_company_currency(cr, uid, voucher.id, context) + current_currency = _get_current_currency(cr, uid, voucher.id, context) current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id #Create the account move record. move_id = move_pool.create(cr, uid, self.account_move_get(cr,uid,voucher.id)) From fd04f1bb9bf147c2291520b77d5c7687087dae71 Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 22:44:14 -0400 Subject: [PATCH 14/31] [REF] All the context_multicurrency logic pushed in an external method it is called 3 times bzr revid: javier@vauxoo.com-20111011024414-l78qdz3d3lv3eygg --- addons/account_voucher/account_voucher.py | 74 +++++++++++++---------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 1a34103fdc4..f678f5f2f43 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -651,6 +651,19 @@ class account_voucher(osv.osv): res['account_id'] = account_id return {'value':res} + def _sel_context(self, cr, uid, voucher_id,context=None): + """ + Select if context will be multicurrency or not. + + :param voucher_id: Id of the actual voucher + :return Dict with new context + """ + context_multi_currency = context.copy() + voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) + context_multi_currency.update({'date': voucher_brw.date}) + if current_currency <> company_currency: context = context_multi_currency + return context + def first_move_line_get(self, cr, uid, voucher_id, move_id, context=None): ''' Set a dict to be use to create the first account move line of voucher. @@ -665,11 +678,9 @@ class account_voucher(osv.osv): move_line_obj = self.pool.get('account.move.line') currency_obj = self.pool.get('res.currency') voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) - current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) - context_multi_currency = context.copy() - context_multi_currency.update({'date': voucher_brw.date}) - if current_currency <> company_currency: context = context_multi_currency + company_currency = self._get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = self._get_current_currency(cr, uid, voucher_brw.id, context) + context = self._sel_context(cr,uid,voucher_brw.id,context) debit = credit = 0.0 # TODO: is there any other alternative then the voucher type ?? # ANSWER: We can have payment and receipt "In Advance". @@ -737,9 +748,13 @@ class account_voucher(osv.osv): def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, context=None): ''' Create all ther rest of account move lines on accout move object. - @voucher_id: Voucher id what we are working with - @line_total: Total of the first line. - @move_id: Account move wher this lines will be joined. + It returns Tuple with tot_line what is total of difference between debit and credit and + a list of lists with ids to be reconciled with this format (total_deb_cred,list_of_lists). + + @param voucher_id: Voucher id what we are working with + @param line_total: Total of the first line. + @param move_id: Account move wher this lines will be joined. + @return Tuple with data to evaluate reconcilation process. ''' move_line_obj = self.pool.get('account.move.line') currency_obj = self.pool.get('res.currency') @@ -747,11 +762,9 @@ class account_voucher(osv.osv): rec_lst_ids = [] voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) - current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) - context_multi_currency = context.copy() - context_multi_currency.update({'date': voucher_brw.date}) - if current_currency <> company_currency: context = context_multi_currency + company_currency = self._get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = self._get_current_currency(cr, uid, voucher_brw.id, context) + context = self._sel_context(cr,uid,voucher_brw.id,context) for line in voucher_brw.line_ids: #create one move line per voucher line where amount is not 0.0 if not line.amount: @@ -807,36 +820,36 @@ class account_voucher(osv.osv): rec_ids = [voucher_line, line.move_line_id.id] if amount_residual: # Change difference entry - if not inv.exchange_acc_id.id: + if not voucher_brw.exchange_acc_id.id: raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) move_line = { - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, + 'journal_id': voucher_brw.journal_id.id, + 'period_id': voucher_brw.period_id.id, 'name': _('change')+': '+(line.name or '/'), 'account_id': line.account_id.id, 'move_id': move_id, - 'partner_id': inv.partner_id.id, + 'partner_id': voucher_brw.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, 'amount_currency': 0.0, 'quantity': 1, 'credit': amount_residual > 0 and amount_residual or 0.0, 'debit': amount_residual < 0 and -amount_residual or 0.0, - 'date': inv.date + 'date': voucher_brw.date, } new_id = move_line_pool.create(cr, uid, move_line) move_line = { - 'journal_id': inv.journal_id.id, - 'period_id': inv.period_id.id, + 'journal_id': voucher_brw.journal_id.id, + 'period_id': voucher_brw.period_id.id, 'name': _('change')+': '+(line.name or '/'), - 'account_id': inv.exchange_acc_id.id, + 'account_id': voucher_brw.exchange_acc_id.id, 'move_id': move_id, 'amount_currency': 0.0, - 'partner_id': inv.partner_id.id, + 'partner_id': voucher_brw.partner_id.id, 'currency_id': company_currency <> current_currency and current_currency or False, 'quantity': 1, 'debit': amount_residual > 0 and amount_residual or 0.0, 'credit': amount_residual < 0 and -amount_residual or 0.0, - 'date': inv.date + 'date': voucher_brw.date, } move_line_pool.create(cr, uid, move_line) rec_ids.append(new_id) @@ -865,12 +878,9 @@ class account_voucher(osv.osv): move_line = {} voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - company_currency = _get_company_currency(cr, uid, voucher_brw.id, context) - current_currency = _get_current_currency(cr, uid, voucher_brw.id, context) - context_multi_currency = context.copy() - context_multi_currency.update({'date': voucher_brw.date}) - if current_currency <> company_currency: context = context_multi_currency - + company_currency = self._get_company_currency(cr, uid, voucher_brw.id, context) + current_currency = self._get_current_currency(cr, uid, voucher_brw.id, context) + context = self._sel_context(cr,uid,voucher_brw.id,context) current_currency_obj = voucher_brw.currency_id or voucher_brw.journal_id.company_id.currency_id if not currency_obj.is_zero(cr, uid, current_currency_obj, line_total): @@ -909,7 +919,7 @@ class account_voucher(osv.osv): @voucher_id: Id of the voucher what i want to obtain current currency. ''' voucher = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) - return voucher.currency_id.id or _get_company_currency(voucher.id) + return voucher.currency_id.id or self._get_company_currency(cr,uid,voucher.id,context) def action_move_line_create(self, cr, uid, ids, context=None): ''' @@ -926,8 +936,8 @@ class account_voucher(osv.osv): if voucher.move_id: continue - company_currency = _get_company_currency(cr, uid, voucher.id, context) - current_currency = _get_current_currency(cr, uid, voucher.id, context) + company_currency = self._get_company_currency(cr, uid, voucher.id, context) + current_currency = self._get_current_currency(cr, uid, voucher.id, context) current_currency_obj = voucher.currency_id or voucher.journal_id.company_id.currency_id #Create the account move record. move_id = move_pool.create(cr, uid, self.account_move_get(cr,uid,voucher.id)) From cb6892b20bcd9702616b1a1de10f33ace702e96d Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 23:32:33 -0400 Subject: [PATCH 15/31] [REF] Exchange difference move lines was pushed to an external method. In this way calculation of this type of rounding method can be managed diferently from a law to another. bzr revid: javier@vauxoo.com-20111011033233-ijbfcnp7f0tlcw2x --- addons/account_voucher/account_voucher.py | 96 ++++++++++++++--------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index f678f5f2f43..3e782b88f26 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -658,6 +658,8 @@ class account_voucher(osv.osv): :param voucher_id: Id of the actual voucher :return Dict with new context """ + company_currency = self._get_company_currency(cr, uid, voucher_id, context) + current_currency = self._get_current_currency(cr, uid, voucher_id, context) context_multi_currency = context.copy() voucher_brw = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) context_multi_currency.update({'date': voucher_brw.date}) @@ -745,6 +747,50 @@ class account_voucher(osv.osv): } return move + def _get_exchange_lines(self, cr, uid, line, move_id, amount_residual, context = None): + ''' + Generate two lines when the amount residual is due to difference on exchange. + + @param line: browse object of the voucher.line + @param move_id: Account move wher the move lines will be. + @param amount_residual: Amount to be posted. + @param context: Context wher we are working + @return: Tuple with 2 dicts account move line in pos [0] and counterpart in pos [1]. + ''' + company_currency = self._get_company_currency(cr, uid, line.voucher_id.id, context) + current_currency = self._get_current_currency(cr, uid, line.voucher_id.id, context) + if not line.voucher_id.exchange_acc_id.id: + raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) + move_line = { + 'journal_id': line.voucher_id.journal_id.id, + 'period_id': line.voucher_id.period_id.id, + 'name': _('change')+': '+(line.name or '/'), + 'account_id': line.account_id.id, + 'move_id': move_id, + 'partner_id': line.voucher_id.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'amount_currency': 0.0, + 'quantity': 1, + 'credit': amount_residual > 0 and amount_residual or 0.0, + 'debit': amount_residual < 0 and -amount_residual or 0.0, + 'date': line.voucher_id.date, + } + move_line_counterpart = { + 'journal_id': line.voucher_id.journal_id.id, + 'period_id': line.voucher_id.period_id.id, + 'name': _('change')+': '+(line.name or '/'), + 'account_id': line.voucher_id.exchange_acc_id.id, + 'move_id': move_id, + 'amount_currency': 0.0, + 'partner_id': line.voucher_id.partner_id.id, + 'currency_id': company_currency <> current_currency and current_currency or False, + 'quantity': 1, + 'debit': amount_residual > 0 and amount_residual or 0.0, + 'credit': amount_residual < 0 and -amount_residual or 0.0, + 'date': line.voucher_id.date, + } + return (move_line,move_line_counterpart) + def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, context=None): ''' Create all ther rest of account move lines on accout move object. @@ -820,38 +866,11 @@ class account_voucher(osv.osv): rec_ids = [voucher_line, line.move_line_id.id] if amount_residual: # Change difference entry - if not voucher_brw.exchange_acc_id.id: - raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) - move_line = { - 'journal_id': voucher_brw.journal_id.id, - 'period_id': voucher_brw.period_id.id, - 'name': _('change')+': '+(line.name or '/'), - 'account_id': line.account_id.id, - 'move_id': move_id, - 'partner_id': voucher_brw.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'amount_currency': 0.0, - 'quantity': 1, - 'credit': amount_residual > 0 and amount_residual or 0.0, - 'debit': amount_residual < 0 and -amount_residual or 0.0, - 'date': voucher_brw.date, - } - new_id = move_line_pool.create(cr, uid, move_line) - move_line = { - 'journal_id': voucher_brw.journal_id.id, - 'period_id': voucher_brw.period_id.id, - 'name': _('change')+': '+(line.name or '/'), - 'account_id': voucher_brw.exchange_acc_id.id, - 'move_id': move_id, - 'amount_currency': 0.0, - 'partner_id': voucher_brw.partner_id.id, - 'currency_id': company_currency <> current_currency and current_currency or False, - 'quantity': 1, - 'debit': amount_residual > 0 and amount_residual or 0.0, - 'credit': amount_residual < 0 and -amount_residual or 0.0, - 'date': voucher_brw.date, - } - move_line_pool.create(cr, uid, move_line) + print "Amount Residual %s " % str(amount_residual) + exch_lines = self._get_exchange_lines(cr, uid, line, move_id, + amount_residual ,context) + new_id = move_line_obj.create(cr, uid, exch_lines[0],context) + move_line_obj.create(cr, uid, exch_lines[1], context) rec_ids.append(new_id) if line.move_line_id.id: @@ -864,8 +883,6 @@ class account_voucher(osv.osv): ''' Set a dict to be use to create the writeoff move line. - @param cr: A database cursor - @param uid: ID of the user currently logged in @param voucher_id: Id of voucher what we are creating account_move. @param line_total: Amount total of the first account move line of the voucher. @param move_id: Id of account move where this line will be added. @@ -910,13 +927,19 @@ class account_voucher(osv.osv): def _get_company_currency(self, cr, uid, voucher_id, context=None): ''' - @voucher_id: Id of the voucher what i want to obtain company currency. + Get the courrency of the actual company. + + @param voucher_id: Id of the voucher what i want to obtain company currency. + @return id of currency ''' return self.pool.get('account.voucher').browse(cr,uid,voucher_id,context).journal_id.company_id.currency_id.id def _get_current_currency(self, cr, uid, voucher_id, context=None): ''' - @voucher_id: Id of the voucher what i want to obtain current currency. + Get currency we are working with. + + @param voucher_id: Id of the voucher what i want to obtain current currency. + @return id of currency ''' voucher = self.pool.get('account.voucher').browse(cr,uid,voucher_id,context) return voucher.currency_id.id or self._get_company_currency(cr,uid,voucher.id,context) @@ -924,6 +947,7 @@ class account_voucher(osv.osv): def action_move_line_create(self, cr, uid, ids, context=None): ''' Create account move for account voucher. + ''' if context is None: context = {} From 737fccbbc2f2928c9c4b360f1991f196430e6759 Mon Sep 17 00:00:00 2001 From: "Javier Duran javier@vauxoo.com" <> Date: Mon, 10 Oct 2011 23:56:46 -0400 Subject: [PATCH 16/31] [REF] Including decimal precision on amount_residual calculated to avoid account move lines when we have little very little rounding problems bzr revid: javier@vauxoo.com-20111011035646-7jn8z1p8dw6l3f40 --- addons/account_voucher/account_voucher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 3e782b88f26..1cd7be48bff 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -864,8 +864,8 @@ class account_voucher(osv.osv): move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0 voucher_line = move_line_obj.create(cr, uid, move_line) rec_ids = [voucher_line, line.move_line_id.id] - - if amount_residual: # Change difference entry + print "What the fuck %s"% (self.pool.get('decimal.precision').precision_get(cr,uid,'Account')) + if round(amount_residual,self.pool.get('decimal.precision').precision_get(cr,uid,'Account')): # Change difference entry print "Amount Residual %s " % str(amount_residual) exch_lines = self._get_exchange_lines(cr, uid, line, move_id, amount_residual ,context) From 410ee16b088595b7b10b43e781666c4bd6d5a0e8 Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Tue, 11 Oct 2011 00:01:40 -0400 Subject: [PATCH 17/31] [REF] Just taking off some useless strings bzr revid: javier@vauxoo.com-20111011040140-dkpt9hc76n029mwo --- addons/account_voucher/account_voucher.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 1cd7be48bff..b383cbe7f2b 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -864,9 +864,7 @@ class account_voucher(osv.osv): move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0 voucher_line = move_line_obj.create(cr, uid, move_line) rec_ids = [voucher_line, line.move_line_id.id] - print "What the fuck %s"% (self.pool.get('decimal.precision').precision_get(cr,uid,'Account')) if round(amount_residual,self.pool.get('decimal.precision').precision_get(cr,uid,'Account')): # Change difference entry - print "Amount Residual %s " % str(amount_residual) exch_lines = self._get_exchange_lines(cr, uid, line, move_id, amount_residual ,context) new_id = move_line_obj.create(cr, uid, exch_lines[0],context) @@ -947,7 +945,6 @@ class account_voucher(osv.osv): def action_move_line_create(self, cr, uid, ids, context=None): ''' Create account move for account voucher. - ''' if context is None: context = {} @@ -957,7 +954,6 @@ class account_voucher(osv.osv): tax_obj = self.pool.get('account.tax') seq_obj = self.pool.get('ir.sequence') for voucher in self.browse(cr, uid, ids, context=context): - if voucher.move_id: continue company_currency = self._get_company_currency(cr, uid, voucher.id, context) @@ -976,7 +972,6 @@ class account_voucher(osv.osv): line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) elif voucher.type == 'purchase': line_total = line_total + currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context_multi_currency) - ############################################################ #create one move line per voucher line where amount is not 0.0 line_total, rec_list_ids = self.voucher_move_line_create(cr, uid, voucher.id, line_total, move_id, context) From 98fd90fcd846627b066fd5a720f2797941869aaf Mon Sep 17 00:00:00 2001 From: Javier Duran Date: Tue, 11 Oct 2011 00:14:15 -0400 Subject: [PATCH 18/31] [REF] Correcting bad comment bzr revid: javier@vauxoo.com-20111011041415-ql0k37mouhu8a9fg --- addons/account_voucher/account_voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index b383cbe7f2b..6a113fa8e56 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -979,7 +979,7 @@ class account_voucher(osv.osv): ml_writeoff = self.writeoff_move_line_get(cr, uid, voucher.id, line_total, move_id, name, context) if ml_writeoff: ml_writeoff_id = move_line_pool.create(cr, uid, ml_writeoff, context) - #We put posted the voucher. + #We post the voucher. self.write(cr, uid, [voucher.id], { 'move_id': move_id, 'state': 'posted', From 9bfa7b11962a9b6b4102cc15c27d68cca8f0cea7 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 15:51:09 +0200 Subject: [PATCH 19/31] [IMP] accont_voucher: changed case1_usd_usd.yml in order to have it work as expected in the latest version of this module bzr revid: qdp-launchpad@openerp.com-20111013135109-ulwvoep4lq7opb13 --- addons/account_voucher/test/case1_usd_usd.yml | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index dc7654ab9c3..9c5ecece7f1 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -179,13 +179,6 @@ voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) voucher_id = self.browse(cr, uid, voucher[0]) assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.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_strauss0'))]) - 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 - @@ -207,9 +200,7 @@ - I check that my debtor account is correct - - I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 135 and 56 -- - I check that my currency rate difference is correct. 34 in credit with no amount_currency + I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 162 and 63 - I check that my write-off is correct. 9 debit and 10 amount_currency - @@ -220,22 +211,20 @@ 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." + assert move_line.credit == 162.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 rate difference." + assert move_line.credit == 63.00, "Debtor account has wrong entry." elif move_line.amount_currency == 10.00: assert move_line.debit == 9.00, "Writeoff amount is wrong." - - I check the residual amount of Invoice1, should be 20 in amount_currency and 15 in company currency + I check the residual amount of Invoice1, should be 20 in amount_currency - !python {model: account.invoice}: | invoice_id = self.browse(cr, uid, ref("account_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.0) , "Residual amount is not correct for first Invoice" + assert (move_line.amount_residual_currency == 20.0) , "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 - @@ -244,7 +233,7 @@ 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.0 and move_line.amount_residual == 24.0) , "Residual amount is not correct for first Invoice" + assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice" - I create the second voucher of payment @@ -287,13 +276,6 @@ voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) 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_strauss0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == -8.50), "Currency rate difference is not -8.50" - I confirm the voucher - @@ -315,7 +297,7 @@ - I check that my debtor account is correct - - I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 15 and 24. + I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 19 and 28.5 - I check that my currency rate difference is correct. 8.5 in credit with no amount_currency - @@ -328,13 +310,13 @@ 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 == -20.00: - assert move_line.credit == 15.00, "Debtor account has wrong entry." + assert move_line.credit == 19.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." + assert move_line.credit == 28.50, "Debtor account has wrong entry." elif move_line.amount_currency == 5.00: assert move_line.debit == 4.75, "Writeoff amount is wrong." +- + I should check that the total reconcilaition created entries as expected: TODO - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - @@ -344,7 +326,7 @@ 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 first Invoice" -- +- I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | @@ -352,4 +334,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" From 3ca449046fe519676b4c988abb88d2ac788accb1 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 16:58:04 +0200 Subject: [PATCH 20/31] [FIX] account: partial reconcile must look for amount_currency ONLY in the case there is a currency_id field set on the account reconciled bzr revid: qdp-launchpad@openerp.com-20111013145804-q7o0ye77yprriyoj --- addons/account/account.py | 6 +++++- addons/account/account_move_line.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 46e7b3457ec..c3ead387fba 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1563,11 +1563,15 @@ class account_move_reconcile(osv.osv): _defaults = { 'name': lambda self,cr,uid,ctx={}: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile') or '/', } + def reconcile_partial_check(self, cr, uid, ids, type='auto', context=None): total = 0.0 for rec in self.browse(cr, uid, ids, context=context): for line in rec.line_partial_ids: - total += (line.debit or 0.0) - (line.credit or 0.0) + if line.account_id.currency_id: + total += line.amount_currency + else: + total += (line.debit or 0.0) - (line.credit or 0.0) if not total: self.pool.get('account.move.line').write(cr, uid, map(lambda x: x.id, rec.line_partial_ids), diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 5de7fed2428..c18e6c318e0 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -749,11 +749,17 @@ class account_move_line(osv.osv): if not line2.reconcile_id: if line2.id not in merges: merges.append(line2.id) - total += (line2.debit or 0.0) - (line2.credit or 0.0) + if line2.account_id.currency_id: + total += line2.amount_currency + else: + total += (line2.debit or 0.0) - (line2.credit or 0.0) merges_rec.append(line.reconcile_partial_id.id) else: unmerge.append(line.id) - total += (line.debit or 0.0) - (line.credit or 0.0) + if line.account_id.currency_id: + total += line.amount_currency + else: + total += (line.debit or 0.0) - (line.credit or 0.0) if self.pool.get('res.currency').is_zero(cr, uid, company_currency_id, total): res = self.reconcile(cr, uid, merges+unmerge, context=context, writeoff_acc_id=writeoff_acc_id, writeoff_period_id=writeoff_period_id, writeoff_journal_id=writeoff_journal_id) return res From fca9676ac297964969119f746314c99f3e0a961a Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 17:13:42 +0200 Subject: [PATCH 21/31] [FIX] account_voucher: fixed errors in yaml test bzr revid: qdp-launchpad@openerp.com-20111013151342-l4ougzlsnhvz9sj0 --- addons/account_voucher/__openerp__.py | 7 ++++++- addons/account_voucher/test/case1_usd_usd.yml | 19 +++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/account_voucher/__openerp__.py b/addons/account_voucher/__openerp__.py index 97ac9950efb..82516a0113f 100644 --- a/addons/account_voucher/__openerp__.py +++ b/addons/account_voucher/__openerp__.py @@ -59,7 +59,12 @@ Account Voucher module includes all the basic requirements of Voucher Entries fo "test/account_voucher.yml", "test/sales_receipt.yml", "test/sales_payment.yml", - "test/account_voucher_report.yml" + "test/account_voucher_report.yml", + "test/case1_usd_usd.yml", + #"test/case2_suppl_usd_eur.yml", + #"test/case2_usd_eur.yml", + #"test/case3_eur_eur.yml", + #"test/case4_cad_chf.yml", ], 'certificate': '0037580727101', "active": False, diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index 9c5ecece7f1..be5912f0bbf 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -6,7 +6,7 @@ - !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}) @@ -49,12 +49,6 @@ 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 new partner Mark Strauss. - @@ -173,12 +167,12 @@ 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 -10.0 + I check that writeoff amount computed is 10.0 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0" + assert (voucher_id.writeoff_amount == 10.0), "Writeoff amount is not 10.0" - I confirm the voucher - @@ -246,6 +240,7 @@ vals = { 'account_id': ref('account.cash'), 'amount': 45.00, + 'exchange_acc_id': ref('account.o_expense'), 'company_id': ref('base.main_company'), 'currency_id': ref('base.USD'), 'journal_id': ref('bank_journal_USD'), @@ -270,12 +265,12 @@ 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 5.0 - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0" + assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0" - I confirm the voucher - @@ -316,7 +311,7 @@ elif move_line.amount_currency == 5.00: assert move_line.debit == 4.75, "Writeoff amount is wrong." - - I should check that the total reconcilaition created entries as expected: TODO + I check that the total reconcilaition created entries as expected: TODO - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - From 3adcfa34673f1813e285d4ac5010496c019d62af Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 18:02:11 +0200 Subject: [PATCH 22/31] [FIX] account_voucher: finalized case1_usd_usd.yml bzr revid: qdp-launchpad@openerp.com-20111013160211-6r6msluqwc8eduwo --- addons/account_voucher/test/case1_usd_usd.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index be5912f0bbf..eabcec2a08c 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -295,6 +295,8 @@ I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 19 and 28.5 - I check that my currency rate difference is correct. 8.5 in credit with no amount_currency +- + I check that the total reconcilation created entries as expected - I check that my writeoff is correct. 4.75 debit and 5 amount_currency - @@ -303,6 +305,14 @@ 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.reconcile_id.id, "The invoice of 200$ is not fully reconciled" + reconcile_b = move_line.reconcile_id.id + elif move_line.amount_currency == -30.00: + 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 == -20.00: assert move_line.credit == 19.00, "Debtor account has wrong entry." @@ -310,8 +320,10 @@ assert move_line.credit == 28.50, "Debtor account has wrong entry." elif move_line.amount_currency == 5.00: assert move_line.debit == 4.75, "Writeoff amount is wrong." -- - I check that the total reconcilaition created entries as expected: TODO + elif move_line.debit == 11.5 and move_line.account_id.reconcile: + assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong" + elif move_line.debit == 31.0 and move_line.account_id.reconcile: + assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong" - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - From 6a0d99cde92866bbf5dd8a82a9515c20eb6f1e66 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 19:00:29 +0200 Subject: [PATCH 23/31] [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" From 6fe4f45ed061beb11a9cb675da4e793bf0c7fa26 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 13 Oct 2011 19:43:30 +0200 Subject: [PATCH 24/31] [ADD] account_voucher: added case2_usd_eur_debtor_in_usd.yml bzr revid: qdp-launchpad@openerp.com-20111013174330-hf8gwa1161bflbh7 --- addons/account_voucher/__openerp__.py | 2 +- .../test/case2_usd_eur_debtor_in_usd.yml | 344 ++++++++++++++++++ 2 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml diff --git a/addons/account_voucher/__openerp__.py b/addons/account_voucher/__openerp__.py index 07f6372e8b9..031d9f158da 100644 --- a/addons/account_voucher/__openerp__.py +++ b/addons/account_voucher/__openerp__.py @@ -61,8 +61,8 @@ Account Voucher module includes all the basic requirements of Voucher Entries fo "test/sales_payment.yml", "test/account_voucher_report.yml", "test/case1_usd_usd.yml", - #"test/case2_suppl_usd_eur.yml", "test/case2_usd_eur_debtor_in_eur.yml", + "test/case2_usd_eur_debtor_in_usd.yml", #"test/case3_eur_eur.yml", #"test/case4_cad_chf.yml", ], diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml new file mode 100644 index 00000000000..03fafe8a182 --- /dev/null +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml @@ -0,0 +1,344 @@ +- + 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 set the currency_id = USD +- + !python {model: account.account}: | + from datetime import datetime + ids = self.search(cr, uid, [('name', 'ilike', 'debtor')]) + self.write(cr, uid, ids, {'currency_id': ref('base.USD')}) +- + 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')])[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}) +- + I create currency USD in OpenERP for February of 1.250000 Rate +- + !record {model: res.currency.rate, id: febr_usd}: + currency_id: base.USD + name: !eval "'%s-02-01' %(datetime.now().year)" + rate: 1.250000 +- + I create currency USD in OpenERP for March of 1.111111 Rate +- + !record {model: res.currency.rate, id: marc_usd}: + currency_id: base.USD + name: !eval "'%s-03-01' %(datetime.now().year)" + rate: 1.111111 +- + I create currency USD in OpenERP for April of 1.052632 Rate +- + !record {model: res.currency.rate, id: apri_usd}: + currency_id: base.USD + name: !eval "'%s-04-01' %(datetime.now().year)" + rate: 1.052632 +- + I create a bank journal with EUR as currency +- + !record {model: account.journal, id: bank_journal_EUR}: + name: Bank Journal(EUR) + code: BEUR + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.EUR + company_id: base.main_company + view_id: account.account_journal_bank_view +- + I create a bank journal with USD as currency +- + !record {model: account.journal, id: bank_journal_USD}: + name: Bank Journal(USD) + code: BUSD + type: bank + analytic_journal_id: account.sit + sequence_id: account.sequence_bank_journal + default_debit_account_id: account.cash + default_credit_account_id: account.cash + currency: base.USD + company_id: base.main_company + view_id: account.account_journal_bank_view +- + I create a new partner Michal Gallette +- + !record {model: res.partner, id: res_partner_michal1}: + address: + - city: paris + country_id: base.fr + name: Michal + street: 1 rue Rockfeller + type: invoice + zip: '75016' + name: Mr.Michal Gallette +- + I create the first invoice on 1st January for 200 USD +- + !record {model: account.invoice, id: account_first_invoice_jan_michal}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-01-01' %(datetime.now().year)" + period_id: account.period_1 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 200.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_michal1 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_michal} +- + I check that first invoice move is correct for debtor account(debit - credit == 150) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" +- + I create the second invoice on 1st February for 100 USD +- + !record {model: account.invoice, id: account_second_invoice_feb_michal}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.USD + date_invoice: !eval "'%s-02-01' %(datetime.now().year)" + period_id: account.period_2 + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 100.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: res_partner_michal1 + reference_type: none +- + I Validate invoice by clicking on Validate button +- + !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_michal} +- + I check that second invoice move is correct for debtor account (debit - credit == 80) +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal")) + assert invoice_id.move_id, "Move not created for open invoice" + move_line_obj = self.pool.get('account.move.line') + move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) + move_line = move_line_obj.browse(cr, uid, move_lines[0]) + 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 + vals = {} + print "<<<<<<<<<<<<<<<<<" + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michal1"), ref('bank_journal_EUR'), 200.0, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 200.0, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.EUR'), + 'journal_id': ref('bank_journal_EUR'), + 'partner_id': ref('res_partner_michal1'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + 'date': time.strftime("%Y-03-01"), + 'payment_option': 'with_writeoff', + 'writeoff_acc_id': ref('account.a_expense'), + 'comment': 'Write Off', + 'name': 'First 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'] == 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 confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michal1'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that the move of my voucher is valid +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_michal1'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + assert move_line.state == 'valid', "Voucher move is not valid" +- + I check that my debtor account is correct +- + I check that the debtor account has 2 new lines with 144.44 and 77.78 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_michal1'))]) + 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)]) + for move_line in move_line_obj.browse(cr, uid, move_lines): + if move_line.credit == 70.0: + assert move_line.amount_currency == -77.78, "Wrong debtor entry" + if move_line.credit == 130.0: + assert move_line.amount_currency == -144.44, "Wrong debtor entry" +- + 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_michal")) + 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 == 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_michal")) + 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 == 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_michal1"), ref('bank_journal_USD'), 80.0, 2, ttype='receipt', date=False) + vals = { + 'account_id': ref('account.cash'), + 'amount': 80.0, + 'company_id': ref('base.main_company'), + 'currency_id': ref('base.USD'), + 'journal_id': ref('bank_journal_USD'), + 'partner_id': ref('res_partner_michal1'), + 'period_id': ref('account.period_3'), + 'type': 'receipt', + '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'] == 55.56: + item['amount'] = 55.56 + else: + 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 2.22 +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michal1'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$" +- + I confirm the voucher +- + !python {model: account.voucher}: | + import netsvc + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michal1'))]) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr) +- + I check that my voucher state is posted +- + !python {model: account.voucher}: | + voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_michal1'))]) + voucher_id = self.browse(cr, uid, voucher[0]) + assert voucher_id.state == 'posted', "Voucher state is not posted" +- + I check that my debtor account is correct +- + 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. +- + 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_michal1'))]) + 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 == -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 +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal")) + 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 first Invoice" +- + I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid +- + !python {model: account.invoice}: | + invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal")) + 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" From 0c0881e17fbe1449d379d9f4cc85aab001666d8f Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 14 Oct 2011 00:39:58 +0200 Subject: [PATCH 25/31] [FIX] use correct currency_id for is_zero bzr revid: al@openerp.com-20111013223958-p24b36eno5ljfey1 --- addons/account/account_move_line.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index c18e6c318e0..2af05c3c82e 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -741,7 +741,10 @@ class account_move_line(osv.osv): company_list.append(line.company_id.id) for line in self.browse(cr, uid, ids, context=context): - company_currency_id = line.company_id.currency_id + if line.account_id.currency_id: + currency_id = line.account_id.currency_id + else: + currency_id = line.company_id.currency_id if line.reconcile_id: raise osv.except_osv(_('Warning'), _('Already Reconciled!')) if line.reconcile_partial_id: @@ -760,7 +763,7 @@ class account_move_line(osv.osv): total += line.amount_currency else: total += (line.debit or 0.0) - (line.credit or 0.0) - if self.pool.get('res.currency').is_zero(cr, uid, company_currency_id, total): + if self.pool.get('res.currency').is_zero(cr, uid, currency_id, total): res = self.reconcile(cr, uid, merges+unmerge, context=context, writeoff_acc_id=writeoff_acc_id, writeoff_period_id=writeoff_period_id, writeoff_journal_id=writeoff_journal_id) return res r_id = move_rec_obj.create(cr, uid, { From 1abc42257d64ea2f6196fbebec142933ac9bf841 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 17 Oct 2011 09:43:16 +0200 Subject: [PATCH 26/31] [ADD] account_voucher: added case3_eur_eur.yml bzr revid: qdp-launchpad@openerp.com-20111017074316-mh11ronz30vxsuz4 --- addons/account_voucher/__openerp__.py | 2 +- addons/account_voucher/test/case3_eur_eur.yml | 46 +++---------------- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/addons/account_voucher/__openerp__.py b/addons/account_voucher/__openerp__.py index 031d9f158da..fe74691e700 100644 --- a/addons/account_voucher/__openerp__.py +++ b/addons/account_voucher/__openerp__.py @@ -63,7 +63,7 @@ Account Voucher module includes all the basic requirements of Voucher Entries fo "test/case1_usd_usd.yml", "test/case2_usd_eur_debtor_in_eur.yml", "test/case2_usd_eur_debtor_in_usd.yml", - #"test/case3_eur_eur.yml", + "test/case3_eur_eur.yml", #"test/case4_cad_chf.yml", ], 'certificate': '0037580727101', diff --git a/addons/account_voucher/test/case3_eur_eur.yml b/addons/account_voucher/test/case3_eur_eur.yml index b35daf49402..374f40607bd 100644 --- a/addons/account_voucher/test/case3_eur_eur.yml +++ b/addons/account_voucher/test/case3_eur_eur.yml @@ -9,26 +9,12 @@ name: !eval "'%s-01-01' %(datetime.now().year)" rate: 1.000000 - - I create currency EUR in OpenERP for February of 1.000000 Rate + I modify the debtor account in order to make sure there is no currency_id linked - - !record {model: res.currency.rate, id: feb_eur}: - currency_id: base.EUR - name: !eval "'%s-02-01' %(datetime.now().year)" - rate: 1.000000 -- - I create currency EUR in OpenERP for March of 1.000000 Rate -- - !record {model: res.currency.rate, id: mar_eur}: - currency_id: base.EUR - name: !eval "'%s-03-01' %(datetime.now().year)" - rate: 1.000000 -- - I create currency EUR in OpenERP for April of 1.000000 Rate -- - !record {model: res.currency.rate, id: apr_eur}: - currency_id: base.EUR - name: !eval "'%s-04-01' %(datetime.now().year)" - rate: 1.000000 + !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 a bank journal with EUR as currency - @@ -43,12 +29,6 @@ currency: base.EUR 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 Peter Lawson. - @@ -172,13 +152,6 @@ voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) voucher_id = self.browse(cr, uid, voucher[0]) assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0.00" -- - I check that currency rate difference is 0.00 -- - !python {model: account.voucher}: | - voucher = self.search(cr, uid, [('name', '=', 'First payment'),('partner_id', '=', ref('res_partner_peter0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == 0.00), "Currency rate difference is not 0.00" - I confirm the voucher - @@ -271,13 +244,6 @@ voucher = self.search(cr, uid, [('name', '=', 'Second payment'),('partner_id', '=', ref('res_partner_peter0'))]) voucher_id = self.browse(cr, uid, voucher[0]) assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0" -- - I check that currency rate difference is 0.00 -- - !python {model: account.voucher}: | - voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_peter0'))]) - voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == 0.00), "Currency rate difference is not 0" - I confirm the voucher - @@ -328,4 +294,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 == -10.0 and move_line.amount_residual == -10.0) , "Residual amount is not correct for second Invoice" \ No newline at end of file + assert (move_line.amount_residual_currency == -10.0 and move_line.amount_residual == -10.0) , "Residual amount is not correct for second Invoice" From 7bef183b51118032ede6e90fcfb2663e4b6a4e28 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 17 Oct 2011 09:58:51 +0200 Subject: [PATCH 27/31] [IMP] account, invoice form view: show the reopen button anytime as soon as the conditions are met + added an help tooltip on it bzr revid: qdp-launchpad@openerp.com-20111017075851-vn9zevb2dyd4i96t --- addons/account/account_invoice_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 11ec7d8360a..a84eb5f5a32 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -305,8 +305,8 @@