Skip to content

Commit

Permalink
[15.0][IMP] project_forecast_line: setting to control consumption states
Browse files Browse the repository at this point in the history
  • Loading branch information
yankinmax committed Sep 5, 2022
1 parent 4ee1a26 commit 82f5f36
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion project_forecast_line/models/forecast_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
)
Expand Down
16 changes: 16 additions & 0 deletions project_forecast_line/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion project_forecast_line/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions project_forecast_line/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@
class="o_field_integer o_field_number o_field_widget o_input oe_inline col-lg-2"
/>
</div>
<div class="mt8">
<label for="forecast_consumption_states" />
<div class="text-muted">
Select the states for which the consumption is confirmed or not
</div>
<field
name="forecast_consumption_states"
required="1"
class="o_light_label"
/>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 82f5f36

Please sign in to comment.