Update account_analytic_default.py
Fix issue #270 : account_analytic_default doesn't work with company_id condition
This commit is contained in:
parent
ccdae747a0
commit
37bff3b62c
|
@ -39,7 +39,7 @@ class account_analytic_default(osv.osv):
|
|||
'date_stop': fields.date('End Date', help="Default end date for this Analytic Account."),
|
||||
}
|
||||
|
||||
def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context=None):
|
||||
def account_get(self, cr, uid, product_id=None, partner_id=None, company_id=None, user_id=None, date=None, context=None):
|
||||
domain = []
|
||||
if product_id:
|
||||
domain += ['|', ('product_id', '=', product_id)]
|
||||
|
@ -47,6 +47,9 @@ class account_analytic_default(osv.osv):
|
|||
if partner_id:
|
||||
domain += ['|', ('partner_id', '=', partner_id)]
|
||||
domain += [('partner_id', '=', False)]
|
||||
if company_id:
|
||||
domain += ['|', ('company_id', '=', company_id)]
|
||||
domain += [('company_id', '=', False)]
|
||||
if user_id:
|
||||
domain += ['|',('user_id', '=', user_id)]
|
||||
domain += [('user_id','=', False)]
|
||||
|
@ -59,6 +62,7 @@ class account_analytic_default(osv.osv):
|
|||
index = 0
|
||||
if rec.product_id: index += 1
|
||||
if rec.partner_id: index += 1
|
||||
if rec.company_id: index += 1
|
||||
if rec.user_id: index += 1
|
||||
if rec.date_start: index += 1
|
||||
if rec.date_stop: index += 1
|
||||
|
@ -74,7 +78,10 @@ class account_invoice_line(osv.osv):
|
|||
|
||||
def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, context=None, company_id=None):
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id=currency_id, context=context, company_id=company_id)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context=context)
|
||||
if context is None:
|
||||
context = {}
|
||||
company_id = company_id if company_id != None else context.get('company_id',False)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, company_id, uid, time.strftime('%Y-%m-%d'), context=context)
|
||||
if rec:
|
||||
res_prod['value'].update({'account_analytic_id': rec.analytic_id.id})
|
||||
else:
|
||||
|
@ -88,7 +95,7 @@ class stock_picking(osv.osv):
|
|||
|
||||
def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
|
||||
partner_id = picking.partner_id and picking.partner_id.id or False
|
||||
rec = self.pool.get('account.analytic.default').account_get(cursor, user, move_line.product_id.id, partner_id , user, time.strftime('%Y-%m-%d'), context={})
|
||||
rec = self.pool.get('account.analytic.default').account_get(cursor, user, move_line.product_id.id, partner_id, company_id, user, time.strftime('%Y-%m-%d'), context={})
|
||||
|
||||
if rec:
|
||||
return rec.analytic_id.id
|
||||
|
@ -109,7 +116,7 @@ class sale_order_line(osv.osv):
|
|||
anal_def_obj = self.pool.get('account.analytic.default')
|
||||
|
||||
for line in inv_line_obj.browse(cr, uid, create_ids, context=context):
|
||||
rec = anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, sale_line.order_id.user_id.id, time.strftime('%Y-%m-%d'), context=context)
|
||||
rec = anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, sale_line.order_id.user_id.id, False, time.strftime('%Y-%m-%d'), context=context)
|
||||
|
||||
if rec:
|
||||
inv_line_obj.write(cr, uid, [line.id], {'account_analytic_id': rec.analytic_id.id}, context=context)
|
||||
|
|
Loading…
Reference in New Issue