[FIX] Average price is based on product, not template
This commit is contained in:
@@ -388,12 +388,12 @@ class stock_move(osv.osv):
|
||||
#adapt standard price on incomming moves if the product cost_method is 'average'
|
||||
if (move.location_id.usage == 'supplier') and (move.product_id.cost_method == 'average'):
|
||||
product = move.product_id
|
||||
prod_tmpl_id = move.product_id.product_tmpl_id.id
|
||||
qty_available = move.product_id.product_tmpl_id.qty_available
|
||||
if tmpl_dict.get(prod_tmpl_id):
|
||||
product_avail = qty_available + tmpl_dict[prod_tmpl_id]
|
||||
product_id = move.product_id.id
|
||||
qty_available = move.product_id.qty_available
|
||||
if tmpl_dict.get(product_id):
|
||||
product_avail = qty_available + tmpl_dict[product_id]
|
||||
else:
|
||||
tmpl_dict[prod_tmpl_id] = 0
|
||||
tmpl_dict[product_id] = 0
|
||||
product_avail = qty_available
|
||||
if product_avail <= 0:
|
||||
new_std_price = move.price_unit
|
||||
@@ -401,7 +401,7 @@ class stock_move(osv.osv):
|
||||
# Get the standard price
|
||||
amount_unit = product.standard_price
|
||||
new_std_price = ((amount_unit * product_avail) + (move.price_unit * move.product_qty)) / (product_avail + move.product_qty)
|
||||
tmpl_dict[prod_tmpl_id] += move.product_qty
|
||||
tmpl_dict[product_id] += move.product_qty
|
||||
# Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products
|
||||
ctx = dict(context or {}, force_company=move.company_id.id)
|
||||
product_obj.write(cr, SUPERUSER_ID, [product.id], {'standard_price': new_std_price}, context=ctx)
|
||||
|
||||
Reference in New Issue
Block a user