[FIX] hr_expense: Fixed problem of company id when creating invoice from expenses.

lp bug: https://launchpad.net/bugs/796363 fixed

bzr revid: uco@tinyerp.com-20110615131326-64npowgjwy4jk4xy
This commit is contained in:
Stéphane Bidoul 2011-06-15 18:43:26 +05:30 committed by Ujjvala Collins (OpenERP)
parent d9527bc6e4
commit 3cc05ec6f9
1 changed files with 19 additions and 7 deletions

View File

@ -24,6 +24,7 @@ import time
from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
import netsvc
def _employee_get(obj, cr, uid, context=None):
if context is None:
@ -54,6 +55,12 @@ class hr_expense_expense(osv.osv):
else:
return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)], context=context)[0]
def _company_get(obj, cr, uid, context=None):
employee_id = _employee_get(obj, cr, uid, context)
if employee_id:
return obj.pool.get('hr.employee').read(cr, uid, [employee_id], ['company_id'], context)[0]['company_id']
return False
_name = "hr.expense.expense"
_description = "Expense"
_columns = {
@ -91,14 +98,18 @@ class hr_expense_expense(osv.osv):
'employee_id': _employee_get,
'user_id': lambda cr, uid, id, c={}: id,
'currency_id': _get_currency,
'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
'company_id': _company_get,
}
def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
emp_obj = self.pool.get('hr.employee')
department_id = False
company_id = False
if employee_id:
department_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).department_id.id or False
return {'value':{'department_id':department_id}}
employee = emp_obj.browse(cr, uid, employee_id, context=context)
department_id = employee.department_id.id or False
company_id = employee.company_id.id or False
return {'value':{'department_id':department_id, 'company_id':company_id}}
def expense_confirm(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {
@ -153,6 +164,7 @@ class hr_expense_expense(osv.osv):
analytic_journal_obj = self.pool.get('account.analytic.journal')
account_journal = self.pool.get('account.journal')
for exp in self.browse(cr, uid, ids):
company_id = exp.company_id.id
lines = []
for l in exp.line_ids:
tax_id = []
@ -162,10 +174,9 @@ class hr_expense_expense(osv.osv):
acc = l.product_id.categ_id.property_account_expense_categ
tax_id = [x.id for x in l.product_id.supplier_taxes_id]
else:
acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category')
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`'))
lines.append((0, False, {
'name': l.name,
'account_id': acc.id,
@ -190,6 +201,7 @@ class hr_expense_expense(osv.osv):
'partner_id': exp.employee_id.address_home_id.partner_id.id,
'address_invoice_id': exp.employee_id.address_home_id.id,
'address_contact_id': exp.employee_id.address_home_id.id,
'company_id': company_id,
'origin': exp.name,
'invoice_line': lines,
'currency_id': exp.currency_id.id,
@ -205,7 +217,7 @@ class hr_expense_expense(osv.osv):
inv['journal_id']=exp.journal_id.id
journal = exp.journal_id
else:
journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice'})
journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice', 'company_id': company_id})
if journal_id:
inv['journal_id'] = journal_id
journal = account_journal.browse(cr, uid, journal_id)
@ -248,7 +260,7 @@ class hr_expense_line(osv.osv):
'unit_amount': fields.float('Unit Price', digits_compute=dp.get_precision('Account')),
'unit_quantity': fields.float('Quantities' ),
'product_id': fields.many2one('product.product', 'Product', domain=[('hr_expense_ok','=',True)]),
'uom_id': fields.many2one('product.uom', 'UoM' ),
'uom_id': fields.many2one('product.uom', 'UoM'),
'description': fields.text('Description'),
'analytic_account': fields.many2one('account.analytic.account','Analytic account'),
'ref': fields.char('Reference', size=32),