From 95038f0bf3d71ce8ec7eb5a08a49988cf008229c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 23 Feb 2017 16:16:33 +0100 Subject: [PATCH] [FIX] stock_account: product_price_update_before_done When updating several moves for the same product, each time a write was done, the move.product_id.standard_price was not updated due to "with_context(force_company=move.company_id.id)" before write. Making a with_context before write changes the environment of the write, this why the cache was not updated. opw:709329 --- addons/stock_account/models/stock.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 4c33b0df245..fe89547e200 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -184,6 +184,7 @@ class StockMove(models.Model): def product_price_update_before_done(self): tmpl_dict = defaultdict(lambda: 0.0) # adapt standard price on incomming moves if the product cost_method is 'average' + std_price_update = {} for move in self.filtered(lambda move: move.location_id.usage == 'supplier' and move.product_id.cost_method == 'average'): product_tot_qty_available = move.product_id.qty_available + tmpl_dict[move.product_id.id] @@ -192,12 +193,13 @@ class StockMove(models.Model): new_std_price = move.get_price_unit() else: # Get the standard price - amount_unit = move.product_id.standard_price + amount_unit = std_price_update.get(move.product_id.id) or move.product_id.standard_price new_std_price = ((amount_unit * product_tot_qty_available) + (move.get_price_unit() * move.product_qty)) / (product_tot_qty_available + move.product_qty) tmpl_dict[move.product_id.id] += move.product_qty # Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products move.product_id.with_context(force_company=move.company_id.id).write({'standard_price': new_std_price}) + std_price_update[move.product_id.id] = new_std_price @api.multi def product_price_update_after_done(self):