[IMP] sale: add comment on onchange_fiscal_position and update taxes of order lines only if a product is defined
bzr revid: chm@openerp.com-20140506080525-4scwvtk7os8b63d0
This commit is contained in:
parent
74a6bde093
commit
8065294976
|
@ -627,6 +627,12 @@ class sale_order(osv.osv):
|
|||
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
|
||||
|
||||
def onchange_fiscal_position(self, cr, uid, ids, fiscal_position, order_lines, context=None):
|
||||
'''Update taxes of order lines for each line where a product is defined
|
||||
|
||||
:param list ids: not used
|
||||
:param int fiscal_position: sale order fiscal position
|
||||
:param list order_lines: command list for one2many write method
|
||||
'''
|
||||
order_line = []
|
||||
fiscal_obj = self.pool.get('account.fiscal.position')
|
||||
product_obj = self.pool.get('product.product')
|
||||
|
@ -640,14 +646,13 @@ class sale_order(osv.osv):
|
|||
# create (0, 0, { fields })
|
||||
# update (1, ID, { fields })
|
||||
if line[0] in [0, 1]:
|
||||
taxes_id = None
|
||||
prod = None
|
||||
if line[2].get('product_id'):
|
||||
taxes_id = product_obj.browse(cr, uid, line[2]['product_id'], context=context).taxes_id
|
||||
prod = product_obj.browse(cr, uid, line[2]['product_id'], context=context)
|
||||
elif line[1]:
|
||||
# don't change taxes if they are no product defined
|
||||
taxes_id = line_obj.browse(cr, uid, line[1], context=context).product_id.taxes_id
|
||||
if taxes_id:
|
||||
line[2]['tax_id'] = [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, taxes_id)]]
|
||||
prod = line_obj.browse(cr, uid, line[1], context=context).product_id
|
||||
if prod and prod.taxes_id:
|
||||
line[2]['tax_id'] = [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, prod.taxes_id)]]
|
||||
order_line.append(line)
|
||||
|
||||
# link (4, ID)
|
||||
|
@ -655,9 +660,11 @@ class sale_order(osv.osv):
|
|||
elif line[0] in [4, 6]:
|
||||
line_ids = line[0] == 4 and [line[1]] or line[2]
|
||||
for line_id in line_ids:
|
||||
taxes_id = line_obj.browse(cr, uid, line_id, context=context).product_id.taxes_id
|
||||
order_line.append([1, line_id, {'tax_id': [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, taxes_id)]]}])
|
||||
|
||||
prod = line_obj.browse(cr, uid, line_id, context=context).product_id
|
||||
if prod and prod.taxes_id:
|
||||
order_line.append([1, line_id, {'tax_id': [[6, 0, fiscal_obj.map_tax(cr, uid, fpos, prod.taxes_id)]]}])
|
||||
else:
|
||||
order_line.append([4, line_id])
|
||||
else:
|
||||
order_line.append(line)
|
||||
return {'value': {'order_line': order_line}}
|
||||
|
|
Loading…
Reference in New Issue