From 4ec6069accb862beead8377247a9ca6b128d37ed Mon Sep 17 00:00:00 2001 From: amoyaux Date: Tue, 29 Aug 2017 10:19:08 +0200 Subject: [PATCH] [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. --- addons/mrp/wizard/change_production_qty.py | 1 - addons/mrp/wizard/mrp_product_produce.py | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/addons/mrp/wizard/change_production_qty.py b/addons/mrp/wizard/change_production_qty.py index b408bef5f8b..cd3cf5a5864 100644 --- a/addons/mrp/wizard/change_production_qty.py +++ b/addons/mrp/wizard/change_production_qty.py @@ -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 diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index b887ac2a62d..8b08771e6e6 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -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({