[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 <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2019-11-13 17:45:51 +00:00
committed by fw-bot
parent eea62c09c9
commit 643c91aba6
2 changed files with 24 additions and 2 deletions
+4 -2
View File
@@ -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')
@@ -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