From 463e31f4d3b4df9c1a44985589e6ea16fb76691a Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 12 Sep 2015 20:18:51 +0200 Subject: [PATCH] [FIX] Average price is based on product, not template --- addons/stock_account/stock_account.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index 1ec8f27c2de..3b61bcadd12 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -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)