[FIX] stock_landed_costs : Fixed the cost price of related quant.

bzr revid: mdi@tinyerp.com-20140424102431-llaqwn80mfp1j3h6
This commit is contained in:
DJ Patel 2014-04-24 15:54:31 +05:30
parent d626d770bf
commit 7e700e4554
1 changed files with 8 additions and 4 deletions

View File

@ -153,16 +153,20 @@ class stock_landed_cost(osv.osv):
def button_validate(self, cr ,uid, ids, context=None):
quant_obj = self.pool.get('stock.quant')
for cost in self.browse(cr, uid, ids, context=context):
quant_dict = {}
for line in cost.valuation_adjustment_lines:
per_unit = line.final_cost / line.quantity
diff = per_unit - line.former_cost_per_unit
quants = [quant for quant in line.move_id.quant_ids if line.move_id]
for quant in quants:
if quant.cost < 0:
new_cost = quant.cost - diff
if quant.id not in quant_dict:
quant_dict[quant.id] = quant.cost + diff
else:
new_cost = quant.cost + diff
quant_obj.write(cr, uid, quant.id, {'cost': new_cost}, context=context)
quant_dict[quant.id] += diff
for key, value in quant_dict.items():
quant_obj.write(cr, uid, quant.id, {'cost': value}, context=context)
self._create_accounting_entries(cr, uid, cost, cost.valuation_adjustment_lines, context=context)
self.write(cr, uid, cost.id, {'state': 'open'}, context=context)
return True