[FIX] mrp: update qty to produce does not remove the qty produced

When updating the quantity to produce on a MO, the quantity done
on finished/consumed moves that were not done was erased.

It happens due to write on stock move that always wanted to
unreserve the move and thus drop the move lines with qty_done.
This issue has been resolve in previous commit

This commit correct some mistakes in wizard methods in order
to correctly update open moves.
This commit is contained in:
amoyaux
2017-08-30 11:34:20 +02:00
committed by Pierre Masereel
parent de6a50e984
commit 4ec6069acc
2 changed files with 11 additions and 12 deletions
@@ -55,7 +55,6 @@ class ChangeProductionQty(models.TransientModel):
operation_bom_qty[operation.id] = bom_data['qty']
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()
for wo in production.workorder_ids:
operation = wo.operation_id
+11 -11
View File
@@ -78,22 +78,22 @@ class MrpProductProduce(models.TransientModel):
@api.multi
def do_produce(self):
# Nothing to do for lots since values are created using default data (stock.move.lots)
moves = self.production_id.move_raw_ids
quantity = self.product_qty
if float_compare(quantity, 0, precision_rounding=self.product_uom_id.rounding) <= 0:
raise UserError(_('You should at least produce some quantity'))
for move in moves.filtered(lambda x: x.product_id.tracking == 'none' and x.quantity_done == 0 and x.state not in ('done', 'cancel')):
if move.unit_factor:
for move in self.production_id.move_raw_ids:
# TODO currently not possible to guess if the user updated quantity by hand or automatically by the produce wizard.
if move.product_id.tracking == 'none' and move.quantity_done < move.product_uom_qty and move.state not in ('done', 'cancel') and move.unit_factor:
rounding = move.product_uom.rounding
move.quantity_done += float_round(quantity * move.unit_factor, precision_rounding=rounding)
moves = self.production_id.move_finished_ids.filtered(lambda x: x.product_id.tracking == 'none' and x.state not in ('done', 'cancel'))
for move in moves:
rounding = move.product_uom.rounding
if move.product_id.id == self.production_id.product_id.id:
move.quantity_done += float_round(quantity, precision_rounding=rounding)
elif move.unit_factor:
# byproducts handling
move.quantity_done += float_round(quantity * move.unit_factor, precision_rounding=rounding)
for move in self.production_id.move_finished_ids:
if move.product_id.tracking == 'none' and move.state not in ('done', 'cancel'):
rounding = move.product_uom.rounding
if move.product_id.id == self.production_id.product_id.id:
move.quantity_done += float_round(quantity, precision_rounding=rounding)
elif move.unit_factor:
# byproducts handling
move.quantity_done += float_round(quantity * move.unit_factor, precision_rounding=rounding)
self.check_finished_move_lots()
if self.production_id.state == 'confirmed':
self.production_id.write({