Permalink
Browse files

[FIX] mrp: do not lose done quantities when updating the quantity to …

…do of a MO

Suppose you have a workorder to create n units of product P,
using raw material R (suppose we use one for one, the following can be extended
to any number of raw materials and factors in a straightforward manner).

Produce j < n units of P. Next, update the quantity to produce to j < k < n.
Since any number m of units between j and n may already have been reserved,
in particular values such that m > k, the move will unreserve the material R.
However, while doing so it will unlink the move_lines, and lose the
quantity_done (j).
The newly created move lines have a quantity_done of zero by default.

Therefore, we store in a dictionary the quantities done for each move line,
and reset these values once the unreservation/reservation of k units is done.

opw 1911969

closes #28990
  • Loading branch information...
len-odoo committed Nov 23, 2018
1 parent 09f24de commit 8db7d70776a276d153d62708c9b703b0b756dae6
Showing with 4 additions and 0 deletions.
  1. +4 −0 addons/mrp/wizard/change_production_qty.py
@@ -50,6 +50,7 @@ def change_prod_qty(self):
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)
done_quantities = {move: move.quantity_done for move in production.move_raw_ids}
for line, line_data in lines:
production._update_raw_move(line, line_data)
operation_bom_qty = {}
@@ -59,6 +60,9 @@ def change_prod_qty(self):
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._action_assign()
for move in production.move_raw_ids:
if move.quantity_done != done_quantities[move]:
move._set_quantity_done(done_quantities[move])
for wo in production.workorder_ids:
operation = wo.operation_id
if operation_bom_qty.get(operation.id):

0 comments on commit 8db7d70

Please sign in to comment.