Skip to content

Commit

Permalink
[FIX] Modify how employee attedance is computed
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiJoQuim committed Oct 21, 2024
1 parent a5080b7 commit dddb149
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions project_forecast_line/models/forecast_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _prepare_forecast_lines(
resource = self.env["resource.resource"]
calendar = self.env.company.resource_calendar_id
for updates in self._split_per_period(
date_from, date_to, forecast_hours, unit_cost, resource, calendar
date_from, date_to, forecast_hours, unit_cost, resource, calendar, force_granularity= (res_model=='hr.employee')
):
values = common_value_dict.copy()
values.update(updates)
Expand All @@ -332,7 +332,7 @@ def _compute_horizon(self, date_from, date_to):
return horiz_date_from, horiz_date_to, date_to

def _split_per_period(
self, date_from, date_to, forecast_hours, unit_cost, resource, calendar
self, date_from, date_to, forecast_hours, unit_cost, resource, calendar, force_granularity=False
):
company = self.env.company
granularity = company.forecast_line_granularity
Expand All @@ -344,7 +344,7 @@ def _split_per_period(
if horiz_date_to <= horiz_date_from:
return
whole_period_forecast = self._number_of_hours(
horiz_date_from, horiz_date_to, resource, calendar
horiz_date_from, horiz_date_to, resource, calendar, force_granularity=force_granularity
)
if whole_period_forecast == 0:
# the resource if completely off during the period -> we cannot
Expand Down
8 changes: 3 additions & 5 deletions project_forecast_line/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ def _update_forecast_lines(self):
[
("res_id", "in", self.ids),
("res_model", "=", self._name),
("date_from", "<", today),
]
).unlink()
horizon_end = ForecastLine._company_horizon_end()
horiz_date_from, horiz_date_to, date_to = (ForecastLine._compute_horizon(today,ForecastLine._company_horizon_end()))
for rec in self:
ForecastLine = ForecastLine.with_company(rec.company_id)
if rec.date_end:
Expand All @@ -126,11 +125,10 @@ def _update_forecast_lines(self):
[
("res_id", "=", rec.id),
("res_model", "=", self._name),
("date_to", ">=", date_end),
]
).unlink()
else:
date_end = horizon_end - relativedelta(days=1)
date_end = date_to
if leave_date_to is not None:
date_end = min(leave_date_to, date_end)
date_start = max(rec.date_start, today)
Expand All @@ -140,7 +138,7 @@ def _update_forecast_lines(self):
calendar = resource.calendar_id

forecast = ForecastLine._number_of_hours(
date_start, date_end, resource, calendar, force_granularity=True
date_start, date_end - relativedelta(days=1), resource, calendar, force_granularity=False
)
forecast_lines = ForecastLine.search(
[
Expand Down

0 comments on commit dddb149

Please sign in to comment.