From 643c91aba6077748a37a480d2efc8ef7a93664f8 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Wed, 6 Nov 2019 10:09:13 +0000 Subject: [PATCH] [FIX] mrp: fix workcenter capacity Planning the workorders depends on the quantity to produce of those workorder This will create as much as production batch needed regarding the workcenter capacity. This method is good except in case of product tracked by serial number. In that case the quantity to produce on the workorders is force to 1 regardless of the quantity to produce on the production closes odoo/odoo#40226 X-original-commit: 3c4133ddac256c63802a99461db49cc9bd9fa1d6 Signed-off-by: William Henrotin --- addons/mrp/models/mrp_production.py | 6 ++++-- addons/mrp/tests/test_workorder_operation.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 98e2755e0e3..868c917f2ec 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -703,6 +703,8 @@ class MrpProduction(models.Model): self.ensure_one() # Schedule all work orders (new ones and those already created) + qty_to_produce = max(self.product_qty - self.qty_produced, 0) + qty_to_produce = self.product_uom_id._compute_quantity(qty_to_produce, self.product_id.uom_id) start_date = self._get_start_date() for workorder in self.workorder_ids: workcenters = workorder.workcenter_id | workorder.workcenter_id.alternative_workcenter_ids @@ -712,7 +714,7 @@ class MrpProduction(models.Model): for workcenter in workcenters: # compute theoretical duration time_cycle = workorder.operation_id.time_cycle - cycle_number = float_round(workorder.qty_producing / workcenter.capacity, precision_digits=0, rounding_method='UP') + cycle_number = float_round(qty_to_produce / workcenter.capacity, precision_digits=0, rounding_method='UP') duration_expected = workcenter.time_start + workcenter.time_stop + cycle_number * time_cycle * 100.0 / workcenter.time_efficiency # get first free slot @@ -740,7 +742,7 @@ class MrpProduction(models.Model): # Instantiate start_date for the next workorder planning if workorder.next_work_order_id: - if workorder.operation_id.batch == 'no' or workorder.operation_id.batch_size >= workorder.qty_producing: + if workorder.operation_id.batch == 'no' or workorder.operation_id.batch_size >= qty_to_produce: start_date = best_finished_date else: cycle_number = float_round(workorder.operation_id.batch_size / best_workcenter.capacity, precision_digits=0, rounding_method='UP') diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py index 3cccd8d167a..52b44901933 100644 --- a/addons/mrp/tests/test_workorder_operation.py +++ b/addons/mrp/tests/test_workorder_operation.py @@ -1263,6 +1263,26 @@ class TestWorkOrderProcess(TestWorkOrderProcessCommon): self.assertAlmostEqual(wo.date_planned_start, datetime.now(), delta=timedelta(seconds=10)) self.assertAlmostEqual(wo.date_planned_finished, datetime.now(), delta=timedelta(seconds=10)) + def test_planning_7(self): + """ set the workcenter capacity to 10. Produce a dozen of product tracked by + SN. The production should be done in two batches""" + self.workcenter_1.capacity = 10 + self.workcenter_1.time_efficiency = 100 + self.workcenter_1.time_start = 0 + self.workcenter_1.time_stop = 0 + self.routing_1.operation_ids.time_cycle = 60 + self.product_4.tracking = 'serial' + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = self.product_4 + mo_form.bom_id = self.planning_bom + mo_form.product_uom_id = self.uom_dozen + mo_form.product_qty = 1 + mo = mo_form.save() + mo.action_confirm() + mo.button_plan() + wo = mo.workorder_ids + self.assertEqual(wo.duration_expected, 120) + def test_plan_unplan_date(self): """ Testing planning a workorder then cancel it and then plan it again. The planned date must be the same the first time and the second time the