[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
This commit is contained in:
Quentin (OpenERP) 2011-11-24 16:42:16 +01:00
parent 07d143d74d
commit 62398c5cba
8 changed files with 92 additions and 17 deletions

View File

@ -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:

View File

@ -259,5 +259,19 @@
</field>
</record>
<!-- res.company form view -->
<record model="ir.ui.view" id="view_company_inherit_currency_xchange_form">
<field name="name">res.company.form.inherit</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="model">res.company</field>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="income_currency_exchange_account_id" colspan="2"/>
<field name="expense_currency_exchange_account_id" colspan="2"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@ -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$

View File

@ -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
-

View File

@ -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'

View File

@ -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'

View File

@ -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'
-

View File

@ -171,7 +171,7 @@
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
required="1" readonly="1"
required="1"
/>
<field name="account_id" groups="base.group_no_one" domain="[('type','=','payable')]"/>
<field name="date_original" readonly="1"/>
@ -187,7 +187,7 @@
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
required="1" readonly="1"
required="1"
/>
<field name="account_id" groups="base.group_no_one" domain="[('type','=','payable')]"/>
<field name="date_original" readonly="1"/>
@ -205,8 +205,6 @@
<group col="2" colspan="1">
<group col="4" colspan="1" attrs="{'invisible':[('currency_id','=',False)]}">
<separator string="Currency Options" colspan="4"/>
<field name="exchange_acc_id"
domain="[('type','=','other')]" colspan="4"/>
<field name="payment_rate" required="1" on_change="onchange_rate(payment_rate, amount, currency_id, payment_rate_currency_id, company_id, context)" groups='base.group_extended' colspan="3"/>
<field name="payment_rate_currency_id" groups='base.group_extended' colspan="1" nolabel="1" on_change="onchange_payment_rate_currency(currency_id, payment_rate, payment_rate_currency_id, date, amount, company_id, context)"/>
<field name="paid_amount_in_company_currency" groups='base.group_extended' colspan="4"/>
@ -325,7 +323,7 @@
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
required="1" readonly="1"
required="1"
/>
<field name="account_id" groups="base.group_no_one" domain="[('type','=','receivable')]"/>
<field name="date_original" readonly="1"/>
@ -341,7 +339,7 @@
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
required="1" readonly="1"
required="1"
/>
<field name="account_id" groups="base.group_no_one" domain="[('type','=','receivable')]"/>
<field name="date_original" readonly="1"/>
@ -359,8 +357,6 @@
<group col="2" colspan="1">
<group col="4" colspan="1" attrs="{'invisible':[('currency_id','=',False)]}">
<separator string="Currency Options" colspan="4"/>
<field name="exchange_acc_id"
domain="[('type','=','other')]" colspan="4"/>
<field name="payment_rate" required="1" on_change="onchange_rate(payment_rate, amount, currency_id, payment_rate_currency_id, company_id, context)" groups='base.group_extended' colspan="3"/>
<field name="payment_rate_currency_id" groups='base.group_extended' colspan="1" nolabel="1" on_change="onchange_payment_rate_currency(currency_id, payment_rate, payment_rate_currency_id, date, amount, company_id, context)"/>
<field name="paid_amount_in_company_currency" groups='base.group_extended' colspan="4"/>