Mayur Maheshwari(OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-hr_expense-multi_currency_issue-mma
into lp:~openerp-dev/openobject-addons/trunk-hr_expense.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-hr_expense-multi_currency_issue-mma/+merge/119477
Hello,
hr_expense: I Have improved expense line with multi currency when voucher
journal have secondary currency convert the expense to that currency and put an
on-change in the currency field that fill the force journal field with a
purchase journal that has the same currency
Thanks,
Mayur
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-hr_expense-multi_currency_issue-mma/+merge/119477
Your team OpenERP R&D Team is requested to review the proposed merge of
lp:~openerp-dev/openobject-addons/trunk-hr_expense-multi_currency_issue-mma
into lp:~openerp-dev/openobject-addons/trunk-hr_expense.
=== modified file 'hr_expense/hr_expense.py'
--- hr_expense/hr_expense.py 2012-08-09 13:15:16 +0000
+++ hr_expense/hr_expense.py 2012-08-14 07:00:32 +0000
@@ -100,6 +100,14 @@
'currency_id': _get_currency,
}
+ def onchange_currency_id(self, cr, uid, ids, currency_id, context=None):
+ res = {'value': {'journal_id': False}}
+ company_id = self.browse(cr, uid, ids[0], context=context).company_id.id
+ journal_id = self.pool.get('account.journal').search(cr, uid, [('type','=','purchase'), ('currency','=',currency_id), ('company_id', '=', company_id)])
+ if journal_id:
+ res['value']['journal_id'] = journal_id
+ return res
+
def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
emp_obj = self.pool.get('hr.employee')
department_id = False
@@ -145,6 +153,7 @@
total = 0.0
ctx = context.copy()
ctx.update({'date': exp.date})
+ journal = False
for line in exp.line_ids:
if line.product_id:
acc = line.product_id.product_tmpl_id.property_account_expense
@@ -159,6 +168,23 @@
total_amount = currency_obj.compute(cr, uid, exp.currency_id.id, exp.company_id.currency_id.id, line.total_amount, context=ctx)
else:
total_amount = line.total_amount
+ if exp.journal_id:
+ journal = exp.journal_id
+ if journal.currency:
+ if exp.currency_id != journal.currency:
+ total_amount = currency_obj.compute(cr, uid, exp.currency_id.id, journal.currency.id, line.total_amount, context=ctx)
+ else:
+ total_amount = line.total_amount
+ else:
+ journal_id = voucher_obj._get_journal(cr, uid, context={'type': 'purchase', 'company_id': company_id})
+ if journal_id:
+ journal = account_journal.browse(cr, uid, journal_id, context=context)
+ if journal.currency:
+ if exp.currency_id != journal.currency:
+ total_amount = currency_obj.compute(cr, uid, exp.currency_id.id, journal.currency.id, line.total_amount, context=ctx)
+ else:
+ total_amount = line.total_amount
+
lines.append((0, False, {
'name': line.name,
'account_id': acc.id,
@@ -178,18 +204,10 @@
'partner_id': exp.employee_id.address_home_id.id,
'company_id': company_id,
'currency_id': exp.currency_id.id,
+ 'journal_id': journal.id,
'line_ids': lines,
'amount': total
}
- journal = False
- if exp.journal_id:
- voucher['journal_id'] = exp.journal_id.id
- journal = exp.journal_id
- else:
- journal_id = voucher_obj._get_journal(cr, uid, context={'type': 'purchase', 'company_id': company_id})
- if journal_id:
- voucher['journal_id'] = journal_id
- journal = account_journal.browse(cr, uid, journal_id, context=context)
if journal and not journal.analytic_journal_id:
analytic_journal_ids = analytic_journal_obj.search(cr, uid, [('type','=','purchase')], context=context)
if analytic_journal_ids:
=== modified file 'hr_expense/hr_expense_view.xml'
--- hr_expense/hr_expense_view.xml 2012-08-10 15:11:08 +0000
+++ hr_expense/hr_expense_view.xml 2012-08-14 07:00:32 +0000
@@ -84,7 +84,7 @@
<group>
<field name="name"/>
<field name="user_valid"/>
- <field name="currency_id" groups="base.group_multi_currency"/>
+ <field name="currency_id" groups="base.group_multi_currency" on_change="onchange_currency_id(currency_id)"/>
</group>
</group>
<notebook>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp