[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
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user