[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
This commit is contained in:
Richard deMeester
2016-05-25 10:54:09 +02:00
committed by Nicolas Martinelli
parent 5b299a2094
commit 31f50efe0a
+4 -2
View File
@@ -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)