diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 94c4577b87b..5710d9b572f 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -583,7 +583,7 @@ class MrpProduction(models.Model): }) if workorders: workorders[-1].next_work_order_id = workorder.id - workorders[-1]._init_nextworkorder_states() + workorders[-1]._start_nextworkorder() workorders += workorder # assign moves; last operation receive all unassigned moves (which case ?) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index e0b993c2215..f1544ab0e44 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -337,9 +337,6 @@ class MrpWorkorder(models.Model): move_line.lot_produced_id = self.final_lot_id.id move_line.done_wo = True - # One a piece is produced, you can launch the next work order - self._start_nextworkorder() - self.move_line_ids.filtered( lambda move_line: not move_line.done_move and not move_line.lot_produced_id and move_line.qty_done > 0 ).write({ @@ -390,6 +387,9 @@ class MrpWorkorder(models.Model): self.final_lot_id.use_next_on_work_order_id = self.next_work_order_id self.final_lot_id = False + # One a piece is produced, you can launch the next work order + self._start_nextworkorder() + # Set a qty producing rounding = self.production_id.product_uom_id.rounding if float_compare(self.qty_produced, self.production_id.product_qty, precision_rounding=rounding) >= 0: @@ -411,12 +411,13 @@ class MrpWorkorder(models.Model): @api.multi def _start_nextworkorder(self): - for record in self: - if record.next_work_order_id.state == 'pending': - record.next_work_order_id.state = 'ready' - - def _init_nextworkorder_states(self): - return 'pending' + rounding = self.product_id.uom_id.rounding + if self.next_work_order_id.state == 'pending' and ( + (self.operation_id.batch == 'no' and + float_compare(self.qty_production, self.qty_produced, precision_rounding=rounding) <= 0) or + (self.operation_id.batch == 'yes' and + float_compare(self.operation_id.batch_size, self.qty_produced, precision_rounding=rounding) <= 0)): + self.next_work_order_id.state = 'ready' @api.multi def button_start(self):