[FIX] mrp: potential traceback

- Create a MO for 500 Units
- Produce 500 Units
- In the "Finished Products" tab, change the produced quantity to 450

At that point, the button "Mark As Done" doesn't appear anymore.
Therefore, we need to change the "Quantity To Produce" to 450 => This
causes a traceback because of a division by zero.

Fixes #14499
opw-695269
This commit is contained in:
Nicolas Martinelli
2016-12-05 16:50:37 +01:00
parent d6b26f1d62
commit 3ea207b5c3
+4 -2
View File
@@ -43,7 +43,9 @@ class ChangeProductionQty(models.TransientModel):
if wizard.product_qty < produced:
raise UserError(_("You have already processed %d. Please input a quantity higher than %d ")%(produced, produced))
production.write({'product_qty': wizard.product_qty})
factor = production.product_uom_id._compute_quantity(production.product_qty - production.qty_produced, production.bom_id.product_uom_id) / production.bom_id.product_qty
done_moves = production.move_finished_ids.filtered(lambda x: x.state == 'done' and x.product_id == production.product_id)
qty_produced = production.product_id.uom_id._compute_quantity(sum(done_moves.mapped('product_qty')), production.product_uom_id)
factor = production.product_uom_id._compute_quantity(production.product_qty - qty_produced, production.bom_id.product_uom_id) / production.bom_id.product_qty
boms, lines = production.bom_id.explode(production.product_id, factor, picking_type=production.bom_id.picking_type_id)
for line, line_data in lines:
production._update_raw_move(line, line_data)
@@ -51,7 +53,7 @@ class ChangeProductionQty(models.TransientModel):
for bom, bom_data in boms:
for operation in bom.routing_id.operation_ids:
operation_bom_qty[operation.id] = bom_data['qty']
self._update_product_to_produce(production, production.product_qty - production.qty_produced)
self._update_product_to_produce(production, production.product_qty - qty_produced)
moves = production.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
moves.do_unreserve()
moves.action_assign()