From abe429ca57c900c4afc7f18d2f9bb679a12784af Mon Sep 17 00:00:00 2001 From: snd Date: Thu, 10 Aug 2023 13:33:26 +0200 Subject: [PATCH] [IMP] mrp: planning with components availability added a contextual action to call action_plan_with_components_availability() if each component line of a production order has a forecast_expected_date, the date_start of the production order will be the latest forecasted date task 3395161 Part-of: odoo/odoo#129933 --- addons/mrp/models/mrp_production.py | 10 ++++++++++ addons/mrp/views/mrp_production_views.xml | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 4ca19d3b9d3..d1b8abe06d9 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -2199,6 +2199,16 @@ class MrpProduction(models.Model): 'res_id': production.id, } + def action_plan_with_components_availability(self): + for production in self.filtered(lambda p: p.state in ('draft', 'confirmed')): + if production.state == 'draft': + production.action_confirm() + expected_date = max(production.move_raw_ids.filtered('forecast_expected_date').mapped('forecast_expected_date'), default=False) + if expected_date: + production.date_start = expected_date + self.button_plan() + + def _has_workorders(self): return self.workorder_ids diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 07742956a15..0786d6b588a 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -79,6 +79,16 @@ action = records.action_split() + + Plan based on Components Availability + + + + list,form + code + action = records.action_plan_with_components_availability() + + Merge