From d494f5988a89ddeff9431523948fa942d52cea54 Mon Sep 17 00:00:00 2001 From: Triet Ngo Date: Thu, 28 Jul 2022 13:40:32 +0000 Subject: [PATCH] [IMP] mrp: Add setup/cleanup time to Workcenter Specific Capacities - Add columns setup/cleanup time to Specific Capatities of Workcenter - Take into account these 2 fields when compute expected duration in WO task-2925474 Part-of: odoo/odoo#97588 --- addons/mrp/models/mrp_workcenter.py | 11 +++++++++++ addons/mrp/models/mrp_workorder.py | 6 +++--- addons/mrp/views/mrp_workcenter_views.xml | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_workcenter.py b/addons/mrp/models/mrp_workcenter.py index 0961e8f9e71..0c2f41a5535 100644 --- a/addons/mrp/models/mrp_workcenter.py +++ b/addons/mrp/models/mrp_workcenter.py @@ -292,6 +292,15 @@ class MrpWorkcenter(models.Model): product_capacity = self.capacity_ids.filtered(lambda capacity: capacity.product_id == product) return product_capacity.capacity if product_capacity else self.default_capacity + def _get_expected_duration(self, product_id): + """Compute the expected duration when using this work-center + Always include workcenter startup time and clean-up time. + In case there are specific capacities defined in the workcenter + that matches the product we are producing. Add the extra-time. + """ + capacity = self.capacity_ids.filtered(lambda p: p.product_id == product_id) + return self.time_start + self.time_stop + (capacity.time_start + capacity.time_stop if capacity else 0.0) + class WorkcenterTag(models.Model): _name = 'mrp.workcenter.tag' @@ -421,6 +430,8 @@ class MrpWorkCenterCapacity(models.Model): product_id = fields.Many2one('product.product', string='Product', required=True) product_uom_id = fields.Many2one('uom.uom', string='Product UoM', related='product_id.uom_id') capacity = fields.Float('Capacity', default=1.0, help="Number of pieces that can be produced in parallel for this product.") + time_start = fields.Float('Setup Time (minutes)', help="Time in minutes for the setup.") + time_stop = fields.Float('Cleanup Time (minutes)', help="Time in minutes for the cleaning.") _sql_constraints = [ ('positive_capacity', 'CHECK(capacity > 0)', 'Capacity should be a positive number.'), diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index d2746d76814..c6c036b7d53 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -745,7 +745,7 @@ class MrpWorkorder(models.Model): duration_expected_working = (self.duration_expected - self.workcenter_id.time_start - self.workcenter_id.time_stop) * self.workcenter_id.time_efficiency / 100.0 if duration_expected_working < 0: duration_expected_working = 0 - return self.workcenter_id.time_start + self.workcenter_id.time_stop + duration_expected_working * ratio * 100.0 / self.workcenter_id.time_efficiency + return self.workcenter_id._get_expected_duration(self.product_id) + duration_expected_working * ratio * 100.0 / self.workcenter_id.time_efficiency qty_production = self.production_id.product_uom_id._compute_quantity(self.qty_production, self.production_id.product_id.uom_id) capacity = self.workcenter_id._get_capacity(self.product_id) cycle_number = float_round(qty_production / capacity, precision_digits=0, rounding_method='UP') @@ -756,9 +756,9 @@ class MrpWorkorder(models.Model): duration_expected_working = 0 capacity = alternative_workcenter._get_capacity(self.product_id) alternative_wc_cycle_nb = float_round(qty_production / capacity, precision_digits=0, rounding_method='UP') - return alternative_workcenter.time_start + alternative_workcenter.time_stop + alternative_wc_cycle_nb * duration_expected_working * 100.0 / alternative_workcenter.time_efficiency + return alternative_workcenter._get_expected_duration(self.product_id) + alternative_wc_cycle_nb * duration_expected_working * 100.0 / alternative_workcenter.time_efficiency time_cycle = self.operation_id.time_cycle - return self.workcenter_id.time_start + self.workcenter_id.time_stop + cycle_number * time_cycle * 100.0 / self.workcenter_id.time_efficiency + return self.workcenter_id._get_expected_duration(self.product_id) + cycle_number * time_cycle * 100.0 / self.workcenter_id.time_efficiency def _get_conflicted_workorder_ids(self): """Get conlicted workorder(s) with self. diff --git a/addons/mrp/views/mrp_workcenter_views.xml b/addons/mrp/views/mrp_workcenter_views.xml index 29f9ccb3c04..234c2dd1048 100644 --- a/addons/mrp/views/mrp_workcenter_views.xml +++ b/addons/mrp/views/mrp_workcenter_views.xml @@ -393,6 +393,8 @@ + +