Skip to content

Commit

Permalink
[FIX] hr_payroll, resource: no attendances
Browse files Browse the repository at this point in the history
Method `get_day_work_hours_count` can return 0 if no attendance is found
in the calendar. Therefore, we must make sure to not divide by zero,
otherwise, boom boom.

Closes odoo#22900
opw-1815095
  • Loading branch information
nim-odoo committed Feb 22, 2018
1 parent 58eea6b commit 5ce76a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion addons/hr_payroll/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def get_worked_day_lines(self, contracts, date_from, date_to):
leave_time = (interval[1] - interval[0]).seconds / 3600
current_leave_struct['number_of_hours'] += leave_time
work_hours = contract.employee_id.get_day_work_hours_count(interval[0].date(), calendar=contract.resource_calendar_id)
current_leave_struct['number_of_days'] += leave_time / work_hours
if work_hours:
current_leave_struct['number_of_days'] += leave_time / work_hours

# compute worked days
work_data = contract.employee_id.get_work_days_data(day_from, day_to, calendar=contract.resource_calendar_id)
Expand Down
6 changes: 4 additions & 2 deletions addons/resource/models/resource_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def get_work_days_data(self, from_datetime, to_datetime, calendar=None):
theoric_hours = self.get_day_work_hours_count(day_intervals[0][0].date(), calendar=calendar)
work_time = sum((interval[1] - interval[0] for interval in day_intervals), timedelta())
total_work_time += work_time
days_count += float_utils.round((work_time.total_seconds() / 3600 / theoric_hours) * 4) / 4
if theoric_hours:
days_count += float_utils.round((work_time.total_seconds() / 3600 / theoric_hours) * 4) / 4
return {
'days': days_count,
'hours': total_work_time.total_seconds() / 3600,
Expand All @@ -80,7 +81,8 @@ def get_leaves_day_count(self, from_datetime, to_datetime, calendar=None):
for day_intervals in calendar._iter_leave_intervals(from_datetime, to_datetime, self.resource_id.id):
theoric_hours = self.get_day_work_hours_count(day_intervals[0][0].date(), calendar=calendar)
leave_time = sum((interval[1] - interval[0] for interval in day_intervals), timedelta())
days_count += float_utils.round((leave_time.total_seconds() / 3600 / theoric_hours) * 4) / 4
if theoric_hours:
days_count += float_utils.round((leave_time.total_seconds() / 3600 / theoric_hours) * 4) / 4
return days_count

def iter_leaves(self, from_datetime, to_datetime, calendar=None):
Expand Down

0 comments on commit 5ce76a0

Please sign in to comment.