diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py
index e03f45396a5..6860665f71d 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 4e218e04714..cbe35b5fc5f 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 96a0e07f70d..3432d3cf27b 100644
--- a/addons/account_voucher/test/case1_usd_usd.yml
+++ b/addons/account_voucher/test/case1_usd_usd.yml
@@ -1,6 +1,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
-
@@ -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 6d6f71b943e..0ad523b8004 100644
--- a/addons/account_voucher/test/case2_suppl_usd_eur.yml
+++ b/addons/account_voucher/test/case2_suppl_usd_eur.yml
@@ -1,6 +1,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
-
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 5aadc93be13..ac77aef622d 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
@@ -1,6 +1,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
-
@@ -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 43c00a9f798..326ba6989d7 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
@@ -1,6 +1,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
-
@@ -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 bb9bda9126c..7c0f9274ff8 100644
--- a/addons/account_voucher/test/case4_cad_chf.yml
+++ b/addons/account_voucher/test/case4_cad_chf.yml
@@ -1,6 +1,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
-
@@ -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 4b6817d77ef..db7c9d9ec54 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 @@
-