Skip to content

Commit

Permalink
[FIX] mrp: do not lose done quantities when updating the quantity to …
Browse files Browse the repository at this point in the history
…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 26, 2018
1 parent 09f24de commit 8db7d70
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/mrp/wizard/change_production_qty.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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) 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 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) 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: for line, line_data in lines:
production._update_raw_move(line, line_data) production._update_raw_move(line, line_data)
operation_bom_qty = {} operation_bom_qty = {}
Expand All @@ -59,6 +60,9 @@ def change_prod_qty(self):
self._update_product_to_produce(production, production.product_qty - 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 = production.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
moves._action_assign() 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: for wo in production.workorder_ids:
operation = wo.operation_id operation = wo.operation_id
if operation_bom_qty.get(operation.id): if operation_bom_qty.get(operation.id):
Expand Down

0 comments on commit 8db7d70

Please sign in to comment.