Skip to content

Commit

Permalink
Merge pull request #2 from coopiteasy/9.0-provelo-fix-get-contract-ho…
Browse files Browse the repository at this point in the history
…urs-per-day

[FIX] hr_timesheet_holiday: filters contract records
  • Loading branch information
vvrossem authored Apr 28, 2020
2 parents 29cc1df + 0f80048 commit 53a9469
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion hr_timesheet_holiday/models/hr_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,31 @@ def _get_contract_hours_per_day(self, employee, date):
elif date.date() == to_dt.date():
start_dt = date.replace(hour=0, minute=0, second=0, microsecond=0)
end_dt = to_dt
else:
start_dt = date.replace(hour=0, minute=0, second=0, microsecond=0)
end_dt = date.replace(
hour=23, minute=59, second=59, microsecond=999999
)
hours_per_day = 0.0
contracts = (
self.env["hr.contract"]
.sudo()
.search([("employee_id.id", "=", employee.id)])
.filtered(
lambda r: (
fields.Date.from_string(r.date_start)
<= fields.Date.from_string(self.date_from)
)
and (
not r.date_end
or fields.Date.from_string(self.date_to)
<= fields.Date.from_string(r.date_end)
)
)
)
for contract in contracts:
for calendar in contract.working_hours:
working_hours = calendar.get_working_hours_of_date(
working_hours = calendar.get_working_hours(
start_dt=start_dt, end_dt=end_dt
)
hours_per_day += sum(wh for wh in working_hours)
Expand Down

0 comments on commit 53a9469

Please sign in to comment.