From 62398c5cba3a821b24cf7cd30875c9fd286fb7e6 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 24 Nov 2011 16:42:16 +0100 Subject: [PATCH] [IMP + FIX] account_voucher: fixed few remaining bugs and improved the code in order to remove the field ecxhange_acc_id from the voucher. We now will use fields on the company bzr revid: qdp-launchpad@openerp.com-20111124154216-ivne5w0q9cwhn12r --- addons/account_voucher/account_voucher.py | 34 +++++++++++++++++--- addons/account_voucher/account_voucher_view.xml | 14 ++++++++ addons/account_voucher/test/case1_usd_usd.yml | 10 +++++- .../account_voucher/test/case2_suppl_usd_eur.yml | 9 ++++++ .../test/case2_usd_eur_debtor_in_eur.yml | 10 +++++- .../test/case2_usd_eur_debtor_in_usd.yml | 10 +++++- addons/account_voucher/test/case4_cad_chf.yml | 10 +++++- .../voucher_payment_receipt_view.xml | 12 +++---- 8 files changed, 92 insertions(+), 17 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index e03f453..6860665 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -91,6 +91,10 @@ class account_voucher(osv.osv): return False def _get_payment_rate_currency(self, cr, uid, context=None): + ''' + Return the default value for field payment_rate_currency_id: the currency of the journal + if there is one, otherwise the currency of the user's company + ''' if context is None: context = {} journal_pool = self.pool.get('account.journal') journal_id = context.get('journal_id', False) @@ -266,7 +270,6 @@ class account_voucher(osv.osv): ('without_writeoff', 'Keep Open'), ('with_writeoff', 'Reconcile Payment Balance'), ], 'Payment Difference', required=True, readonly=True, states={'draft': [('readonly', False)]}), - 'exchange_acc_id': fields.many2one('account.account', 'Exchange Diff. Account', readonly=True, states={'draft': [('readonly', False)]}), 'writeoff_acc_id': fields.many2one('account.account', 'Counterpart Account', readonly=True, states={'draft': [('readonly', False)]}), 'comment': fields.char('Counterpart Comment', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), 'analytic_id': fields.many2one('account.analytic.account','Write-Off Analytic Account', readonly=True, states={'draft': [('readonly', False)]}), @@ -851,8 +854,14 @@ class account_voucher(osv.osv): :return: the account move line and its counterpart to create, depicted as mapping between fieldname and value :rtype: tuple of dict ''' - if not line.voucher_id.exchange_acc_id.id: - raise osv.except_osv(_('Error!'), _('You must provide an account for the exchange difference.')) + if amount_residual > 0: + account_id = line.voucher_id.company_id.expense_currency_exchange_account_id + if not account_id: + raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Income Currency Rate' on the company! ")) + else: + account_id = line.voucher_id.company_id.income_currency_exchange_account_id + if not account_id: + raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Expense Currency Rate' on the company! ")) move_line = { 'journal_id': line.voucher_id.journal_id.id, @@ -872,7 +881,7 @@ class account_voucher(osv.osv): '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, + 'account_id': account_id.id, 'move_id': move_id, 'amount_currency': 0.0, 'partner_id': line.voucher_id.partner_id.id, @@ -1139,7 +1148,7 @@ class account_voucher(osv.osv): # 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) + move_line_pool.reconcile_partial(cr, uid, rec_ids, writeoff_acc_id=voucher.writeoff_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): @@ -1390,4 +1399,19 @@ def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): results.append(result) return results +class res_company(osv.osv): + _inherit = "res.company" + _columns = { + 'income_currency_exchange_account_id': fields.many2one( + 'account.account', + string="Income Currency Rate", + domain="[('type', '=', 'other')]",), + 'expense_currency_exchange_account_id': fields.many2one( + 'account.account', + string="Expense Currency Rate", + domain="[('type', '=', 'other')]",), + } + +res_company() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_voucher/account_voucher_view.xml b/addons/account_voucher/account_voucher_view.xml index 4e218e0..cbe35b5 100644 --- a/addons/account_voucher/account_voucher_view.xml +++ b/addons/account_voucher/account_voucher_view.xml @@ -259,5 +259,19 @@ + + + res.company.form.inherit + + res.company + form + + + + + + + + diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index 96a0e07..3432d3c 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -2,6 +2,15 @@ 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 set the income and expense currency accounts on the main company +- + !python {model: res.company}: | + from datetime import datetime + vals = { + 'income_currency_exchange_account_id': ref('account.o_expense'), + 'expense_currency_exchange_account_id': ref('account.o_expense')} + self.write(cr, uid, ref('base.main_company'), vals) +- I create currency USD in OpenERP for January of 1.333333 Rate - !python {model: res.currency.rate}: | @@ -243,7 +252,6 @@ date: !eval time.strftime("%Y-04-01") payment_option: 'with_writeoff' writeoff_acc_id: account.a_expense - exchange_acc_id: account.o_expense comment: 'Write Off' - I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$ diff --git a/addons/account_voucher/test/case2_suppl_usd_eur.yml b/addons/account_voucher/test/case2_suppl_usd_eur.yml index 6d6f71b..0ad523b 100644 --- a/addons/account_voucher/test/case2_suppl_usd_eur.yml +++ b/addons/account_voucher/test/case2_suppl_usd_eur.yml @@ -2,6 +2,15 @@ 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 set the income and expense currency accounts on the main company +- + !python {model: res.company}: | + from datetime import datetime + vals = { + 'income_currency_exchange_account_id': ref('account.o_expense'), + 'expense_currency_exchange_account_id': ref('account.o_expense')} + self.write(cr, uid, ref('base.main_company'), vals) +- I create a bank journal with EUR as currency - !record {model: account.journal, id: bank_journal_EUR}: diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml index 5aadc93..ac77aef 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml @@ -2,6 +2,15 @@ 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 set the income and expense currency accounts on the main company +- + !python {model: res.company}: | + from datetime import datetime + vals = { + 'income_currency_exchange_account_id': ref('account.o_expense'), + 'expense_currency_exchange_account_id': ref('account.o_expense')} + self.write(cr, uid, ref('base.main_company'), vals) +- I modify the debtor account in order to make sure there is no currency_id linked - !python {model: account.account}: | @@ -221,7 +230,6 @@ date: !eval time.strftime("%Y-04-01") payment_option: 'with_writeoff' writeoff_acc_id: account.a_expense - exchange_acc_id: account.o_expense comment: 'Write Off' name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR' 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 index 43c00a9..326ba69 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml @@ -2,6 +2,15 @@ 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 set the income and expense currency accounts on the main company +- + !python {model: res.company}: | + from datetime import datetime + vals = { + 'income_currency_exchange_account_id': ref('account.o_expense'), + 'expense_currency_exchange_account_id': ref('account.o_expense')} + self.write(cr, uid, ref('base.main_company'), vals) +- I modify the debtor account in order to set the currency_id = USD - !python {model: account.account}: | @@ -236,7 +245,6 @@ date: !eval time.strftime("%Y-04-01") payment_option: 'with_writeoff' writeoff_acc_id: account.a_expense - exchange_acc_id: account.o_expense comment: 'Write Off' name: 'Second payment: Case 2 SUPPL USD/EUR DR USD' diff --git a/addons/account_voucher/test/case4_cad_chf.yml b/addons/account_voucher/test/case4_cad_chf.yml index bb9bda9..7c0f927 100644 --- a/addons/account_voucher/test/case4_cad_chf.yml +++ b/addons/account_voucher/test/case4_cad_chf.yml @@ -2,6 +2,15 @@ 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 set the income and expense currency accounts on the main company +- + !python {model: res.company}: | + from datetime import datetime + vals = { + 'income_currency_exchange_account_id': ref('account.o_expense'), + 'expense_currency_exchange_account_id': ref('account.o_expense')} + self.write(cr, uid, ref('base.main_company'), vals) +- I create currency CAD in OpenERP for January of 1.338800 Rate - !record {model: res.currency.rate, id: jan_cad}: @@ -106,7 +115,6 @@ date: !eval time.strftime("%Y-03-01") payment_option: 'with_writeoff' writeoff_acc_id: account.a_expense - exchange_acc_id: account.o_expense comment: 'Write Off' name: 'First payment: Case 4' - diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 4b6817d..db7c9d9 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -171,7 +171,7 @@ @@ -187,7 +187,7 @@ @@ -205,8 +205,6 @@ - @@ -325,7 +323,7 @@ @@ -341,7 +339,7 @@ @@ -359,8 +357,6 @@ - -- 1.7.10.4