From 31f50efe0a10cb5aff27e38255eee967bdf0b829 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Wed, 25 May 2016 15:46:23 +1000 Subject: [PATCH] [FIX] stock_account: average cost with foreign currency Quants are created, and stock moves are updated, with the purchase value converted at current rates. However, the product average was calculated before that value was retrieved. This ensures the correct value is retrieved for the average cost calculation and will match the actual quants. Fixes #12163 Closes #12164 opw-678511 --- addons/stock_account/stock_account.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index 203d896aee9..aae0f832db8 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -420,12 +420,14 @@ class stock_move(osv.osv): else: tmpl_dict[product_id] = 0 product_avail = qty_available + # if the incoming move is for a purchase order with foreign currency, need to call this to get the same value that the quant will use. + price_unit = self.pool.get('stock.move').get_price_unit(cr, uid, move, context=context) if product_avail <= 0: - new_std_price = move.price_unit + new_std_price = price_unit else: # 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) + new_std_price = ((amount_unit * product_avail) + (price_unit * move.product_qty)) / (product_avail + 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)