From 82f5f363fe43f83c82a4a374314bf489fe12bb99 Mon Sep 17 00:00:00 2001 From: Maksym Yankin Date: Mon, 5 Sep 2022 11:03:52 +0300 Subject: [PATCH] [15.0][IMP] project_forecast_line: setting to control consumption states --- project_forecast_line/models/forecast_line.py | 10 +++++++++- project_forecast_line/models/res_company.py | 16 ++++++++++++++++ .../models/res_config_settings.py | 4 +++- .../views/res_config_settings_views.xml | 11 +++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/project_forecast_line/models/forecast_line.py b/project_forecast_line/models/forecast_line.py index 72026960f6e3..11cfc325a3a7 100644 --- a/project_forecast_line/models/forecast_line.py +++ b/project_forecast_line/models/forecast_line.py @@ -85,8 +85,13 @@ class ForecastLine(models.Model): "forecast.line", "employee_resource_forecast_line_id" ) + def _get_consumption_states(self): + consumption_states = self.env.company.forecast_consumption_states + return tuple(consumption_states.split("_")) + @api.depends("employee_id", "date_from", "type", "res_model") def _compute_employee_forecast_line_id(self): + consumption_states = self._get_consumption_states() employees = self.mapped("employee_id") main_roles = employees.mapped("main_role_id") date_froms = self.mapped("date_from") @@ -111,7 +116,10 @@ def _compute_employee_forecast_line_id(self): (line.employee_id.id, line.date_from, line.forecast_role_id.id) ] = line.id for rec in self: - if rec.type == "confirmed" and rec.res_model != "hr.employee.forecast.role": + if ( + rec.type in consumption_states + and rec.res_model != "hr.employee.forecast.role" + ): resource_forecast_line = capacities.get( (rec.employee_id.id, rec.date_from, rec.forecast_role_id.id), False ) diff --git a/project_forecast_line/models/res_company.py b/project_forecast_line/models/res_company.py index 4d88fee87d3a..c3a41c066129 100644 --- a/project_forecast_line/models/res_company.py +++ b/project_forecast_line/models/res_company.py @@ -14,6 +14,22 @@ class ResCompany(models.Model): forecast_line_horizon = fields.Integer( help="Number of month for the forecast planning", default=12 ) + forecast_consumption_states = fields.Selection( + selection=[ + ("confirmed", "Compute consolidated forecast for lines of type confirmed"), + ( + "forecast_confirmed", + "Include lines of type forecast in consolidated forecast computation", + ), + ], + string="Consumption state rules", + help="For instance, holidays requests and sales quotation lines" + "create lines of type forecast and won't be taken into account" + "during consolidated forecast computation, whereas tasks for project" + "which are in a running state create lines with type confirmed" + "and will be used to compute consolidated forecast.", + default="confirmed", + ) def write(self, values): res = super().write(values) diff --git a/project_forecast_line/models/res_config_settings.py b/project_forecast_line/models/res_config_settings.py index 4ac43649ec64..4c7cc90534fe 100644 --- a/project_forecast_line/models/res_config_settings.py +++ b/project_forecast_line/models/res_config_settings.py @@ -12,7 +12,9 @@ class ResConfigSettings(models.TransientModel): forecast_line_horizon = fields.Integer( related="company_id.forecast_line_horizon", readonly=False ) - + forecast_consumption_states = fields.Selection( + related="company_id.forecast_consumption_states", readonly=False + ) group_forecast_line_on_quotation = fields.Boolean( "Forecast Line on Quotations", implied_group="project_forecast_line.group_forecast_line_on_quotation", diff --git a/project_forecast_line/views/res_config_settings_views.xml b/project_forecast_line/views/res_config_settings_views.xml index e273587afbd1..61b15942a2c3 100644 --- a/project_forecast_line/views/res_config_settings_views.xml +++ b/project_forecast_line/views/res_config_settings_views.xml @@ -50,6 +50,17 @@ class="o_field_integer o_field_number o_field_widget o_input oe_inline col-lg-2" /> +
+