From 52eb6fd1dd2f7c6b3a5b87387fb708ab38ba3f43 Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Mon, 13 Aug 2012 18:53:47 +0530 Subject: [PATCH 1/4] [FIX]hr_expense :improve voucher if voucher journal have currency convert the expense to that currency bzr revid: mma@tinyerp.com-20120813132347-j6f6uy991wbrogfi --- addons/hr_expense/hr_expense.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 01a054c4c90..72b30cb2b46 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -145,6 +145,7 @@ class hr_expense_expense(osv.osv): 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 +160,18 @@ class hr_expense_expense(osv.osv): 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 + 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 +191,10 @@ class hr_expense_expense(osv.osv): '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: From 25367f13bb39090c6c72522274c30d37ac5cd12b Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Tue, 14 Aug 2012 11:13:48 +0530 Subject: [PATCH 2/4] [FIX]hr_expense :improve fource journal if fource journal have currency convert the expense to that currency bzr revid: mma@tinyerp.com-20120814054348-6ofe8r0fcksbhp85 --- addons/hr_expense/hr_expense.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 72b30cb2b46..d860b21c125 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -162,6 +162,11 @@ class hr_expense_expense(osv.osv): 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: From 48f2640283326026a9df21e297f7ca351d2eadfd Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Tue, 14 Aug 2012 12:22:01 +0530 Subject: [PATCH 3/4] [FIX]hr_expense :put an onchange in the currency field that fill the force journal field with a purhcase journal that has the same currency bzr revid: mma@tinyerp.com-20120814065201-57472t4o0wma1232 --- addons/hr_expense/hr_expense.py | 8 ++++++++ addons/hr_expense/hr_expense_view.xml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index d860b21c125..ecd0c97f7e9 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -100,6 +100,14 @@ class hr_expense_expense(osv.osv): '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 diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index 1f9d49ee7c1..980b6e993c8 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -84,7 +84,7 @@ - + From 26d020fe4ca5a1ab4332146eb1d5ca4c60fd248c Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Thu, 16 Aug 2012 12:16:37 +0530 Subject: [PATCH 4/4] [FIX]hr_expense :improve multi currency code for expense line with multiple cases bzr revid: mma@tinyerp.com-20120816064637-4c5oo6jbprqcocdx --- addons/hr_expense/hr_expense.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 9154502003e..483813e3103 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -169,28 +169,12 @@ class hr_expense_expense(osv.osv): acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category', context={'force_company': company_id}) if not acc: raise osv.except_osv(_('Error!'), _('Please configure Default Expense account for Product purchase: `property_account_expense_categ`.')) - total_amount = 0.0 - if journal.currency and exp.currency_id.id != journal.currency.id: - 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 - 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 - + total_amount = line.total_amount + if journal.currency: + if exp.currency_id != journal.currency: + total_amount = currency_obj.compute(cr, uid, exp.currency_id.id, journal.currency.id, total_amount, context=ctx) + elif exp.company_id.currency_id != exp.currency_id: + total_amount = currency_obj.compute(cr, uid, exp.currency_id.id, exp.company_id.currency_id.id, total_amount, context=ctx) lines.append((0, False, { 'name': line.name, 'account_id': acc.id, @@ -210,7 +194,6 @@ class hr_expense_expense(osv.osv): '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_id': journal.id,