Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions project_forecast_line/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def create(self, vals_list):
if vals.get("planned_date_end"):
vals["forecast_date_planned_end"] = vals["planned_date_end"]
tasks = super().create(vals_list)
# tasks._update_forecast_lines()
for i,task in enumerate(tasks):
if set(vals_list[i]) & set(self._update_forecast_lines_trigger_fields()):
task._update_forecast_lines()
return tasks

def _update_forecast_lines_trigger_fields(self):
Expand Down Expand Up @@ -59,15 +61,32 @@ def write(self, values):
values["forecast_date_planned_start"] = values["planned_date_begin"]
if "planned_date_end" in values:
values["forecast_date_planned_end"] = values["planned_date_end"]
return super().write(values)

def _write(self, values):
res = super()._write(values)
if "forecast_recomputation_trigger" in values:
res = super().write(values)
if set(values.keys()) & {
# "sale_order_line_id",
"forecast_role_id",
"forecast_date_planned_start",
"forecast_date_planned_end",
# "remaining_hours",
"name",
# "planned_time",
"user_ids",
"project_id.stage_id",
"project_id.stage_id.forecast_line_type",
"planned_hours"
}:
self._update_forecast_lines()
elif "remaining_hours" in values:
self._quick_update_forecast_lines()
return res
def _write(self, values):
res = super()._write(values)
"""if "forecast_recomputation_trigger" in values:
self._update_forecast_lines()"""
if "remaining_hours" in values:
self._quick_update_forecast_lines()
return res

@api.onchange("user_ids")
def onchange_user_ids(self):
Expand Down
16 changes: 16 additions & 0 deletions project_forecast_line/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ def write(self, values):
self.env["forecast.line"].sudo().search(
[("sale_id", "in", self.ids)]
).write({"project_id": values["project_id"]})
if self and "default_forecast_date_start" in values or "default_forecast_date_end" in values:
for sol in self.mapped("order_line"):
update_forecast = False
if not sol.forecast_date_start:
sol.write({
"forecast_date_start": values.get(
"default_forecast_date_start"
)})
update_forecast = True
if not sol.forecast_date_end:
sol.write({
"forecast_date_end": values.get("default_forecast_date_end"),
})
update_forecast = True
if update_forecast:
sol._update_forecast_lines()
return res
16 changes: 8 additions & 8 deletions project_forecast_line/tests/test_forecast_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,14 @@ def test_task_forecast_lines_consolidated_forecast(self):
@freeze_time("2022-01-01 12:00:00")
def test_forecast_with_holidays(self):
self.test_task_forecast_lines_consolidated_forecast()
with Form(self.env["hr.leave"]) as form:
form.employee_id = self.employee_consultant
form.holiday_status_id = self.env.ref("hr_holidays.holiday_status_unpaid")
form.request_date_from = "2022-02-14"
form.request_date_to = "2022-02-15"
form.request_hour_from = "8"
form.request_hour_to = "18"
leave_request = form.save()
leave_request = self.env["hr.leave"].create(
{
"employee_id": self.employee_consultant.id,
"holiday_status_id": self.env.ref("hr_holidays.holiday_status_unpaid").id,
"date_from": "2022-02-14 07:00:00",
"date_to": "2022-02-15 17:00:00",
}
)
# validating the leave request will recompute the forecast lines for
# the employee capactities (actually delete the existing ones and
# create new ones -> we check that the project task lines are
Expand Down