[FIX] mrp: wrong manual consumption value in onchange
When `manual_consumption` field on sm is used in any onchange function, the value will always be computed for the `new_id` record instead of using the original value stored in database. This results in a different value in some cases. In this commit, we chech if the compute function is called from an onchange funtion or not, if so, we use the original value instead of recomputation. closes odoo/odoo#140753 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -1200,12 +1200,13 @@ class MrpProduction(models.Model):
|
||||
if move.manual_consumption and move.picked:
|
||||
continue
|
||||
|
||||
if move._should_bypass_set_qty_producing():
|
||||
# sudo needed for portal users
|
||||
if move.sudo()._should_bypass_set_qty_producing():
|
||||
continue
|
||||
|
||||
new_qty = float_round((self.qty_producing - self.qty_produced) * move.unit_factor, precision_rounding=move.product_uom.rounding)
|
||||
move._set_quantity_done(new_qty)
|
||||
if (not move.manual_consumption and not move._origin.manual_consumption):
|
||||
if not move.manual_consumption:
|
||||
move.picked = True
|
||||
|
||||
def _update_raw_moves(self, factor):
|
||||
|
||||
@@ -138,9 +138,11 @@ class StockMove(models.Model):
|
||||
@api.depends('state', 'product_id', 'operation_id')
|
||||
def _compute_manual_consumption(self):
|
||||
for move in self:
|
||||
if move.state != 'draft':
|
||||
continue
|
||||
move.manual_consumption = move._is_manual_consumption()
|
||||
# when computed for new_id in onchange, use value from _origin
|
||||
if move != move._origin:
|
||||
move.manual_consumption = move._origin.manual_consumption
|
||||
elif move.state == 'draft':
|
||||
move.manual_consumption = move._is_manual_consumption()
|
||||
|
||||
@api.depends('bom_line_id')
|
||||
def _compute_description_bom_line(self):
|
||||
|
||||
Reference in New Issue
Block a user