diff --git a/mrp_production_date_planned_finished/models/mrp_production.py b/mrp_production_date_planned_finished/models/mrp_production.py index 81e50b3097..d99e04c88c 100644 --- a/mrp_production_date_planned_finished/models/mrp_production.py +++ b/mrp_production_date_planned_finished/models/mrp_production.py @@ -10,12 +10,24 @@ class MrpProduction(models.Model): _inherit = "mrp.production" + def _get_date_planned_start_using_delays(self): + warehouse = self.picking_type_id.warehouse_id + date_planned_start = self.date_planned_finished + if hasattr(warehouse, "calendar_id") and warehouse.calendar_id: + # See `mrp_warehouse_calendar` module. + delay = self.product_id.produce_delay + self.company_id.manufacturing_lead + date_planned_start = warehouse.calendar_id.plan_days( + -1 * (delay + 1), date_planned_start + ) + else: + date_planned_start -= relativedelta(days=self.product_id.produce_delay) + date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead) + return date_planned_start + @api.onchange("date_planned_finished") def _onchange_date_planned_finished_set_date_planned_start(self): if self.date_planned_finished and not self.is_planned: - date_planned_start = self.date_planned_finished - date_planned_start -= relativedelta(days=self.product_id.produce_delay) - date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead) + date_planned_start = self._get_date_planned_start_using_delays() if date_planned_start == self.date_planned_finished: date_planned_start -= relativedelta(hours=1) if self.date_planned_start != date_planned_start: