From c9d3653f486f6c22b47c91f9dc7583219fffc47b Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 11 Apr 2019 12:54:25 +0000 Subject: [PATCH] [FIX] mrp: state on workorder with 0 batch size Usecase: - Go on a BoM with a routing. Go on the first operation and set the next operation(batch field) as 'Once a minimum number of products is processed'. - Set the batch size (minimum operation) to 0. - Create a MO and plan it. - The second work order has state 'pending' instead of 'ready' It happens because the system automatically set the first wo as 'ready' and the following as 'pending' and don't check the batch and batch_size. closes odoo/odoo#32628 Signed-off-by: Simon Lejeune (sle) --- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/mrp_workorder.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) 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):