mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] hr_payroll_overtime: refactor calculation to allow 'recursion' or overtime on overtime
Example. Lets say you have 8hr/day overtime at 1.5x, and 12hr/day overtime at 2x. Now you can create a 2x overtime rules for 12 hours/day, and use it as the overtime rules for the original overtime worktype.
This commit is contained in:
@@ -32,75 +32,56 @@ class HRPayslip(models.Model):
|
||||
iso_days = set()
|
||||
for iso_date, entries in work_data:
|
||||
iso_date = _adjust_week(iso_date)
|
||||
week = iso_date[1]
|
||||
for work_type, hours, _ in entries:
|
||||
if work_type.overtime_work_type_id and work_type.overtime_type_id:
|
||||
ot_h_w = work_type.overtime_type_id.hours_per_week
|
||||
ot_h_d = work_type.overtime_type_id.hours_per_day
|
||||
if ot_h_d and (day_hours[iso_date] + hours) > ot_h_d:
|
||||
if day_hours[iso_date] >= ot_h_d:
|
||||
# no time is regular time
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type.overtime_work_type_id][0] += 1.0
|
||||
result[work_type.overtime_work_type_id][1] += hours
|
||||
result[work_type.overtime_work_type_id][2] = work_type.overtime_type_id.multiplier
|
||||
else:
|
||||
remaining_regular_hours = ot_h_d - day_hours[iso_date]
|
||||
if remaining_regular_hours - hours < 0.0:
|
||||
# some time is regular time
|
||||
regular_hours = remaining_regular_hours
|
||||
overtime_hours = hours - remaining_regular_hours
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += regular_hours
|
||||
result[work_type.overtime_work_type_id][1] += overtime_hours
|
||||
result[work_type.overtime_work_type_id][2] = work_type.overtime_type_id.multiplier
|
||||
else:
|
||||
# all time is regular time
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += hours
|
||||
elif ot_h_w:
|
||||
if week_hours[week] > ot_h_w:
|
||||
# no time is regular time
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type.overtime_work_type_id][0] += 1.0
|
||||
result[work_type.overtime_work_type_id][1] += hours
|
||||
result[work_type.overtime_work_type_id][2] = work_type.overtime_type_id.multiplier
|
||||
else:
|
||||
remaining_regular_hours = ot_h_w - week_hours[week]
|
||||
if remaining_regular_hours - hours < 0.0:
|
||||
# some time is regular time
|
||||
regular_hours = remaining_regular_hours
|
||||
overtime_hours = hours - remaining_regular_hours
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += regular_hours
|
||||
result[work_type.overtime_work_type_id][1] += overtime_hours
|
||||
result[work_type.overtime_work_type_id][2] = work_type.overtime_type_id.multiplier
|
||||
else:
|
||||
# all time is regular time
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += hours
|
||||
else:
|
||||
# all time is regular time
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += hours
|
||||
else:
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
result[work_type][0] += 1.0
|
||||
result[work_type][1] += hours
|
||||
# Always
|
||||
day_hours[iso_date] += hours
|
||||
week_hours[week] += hours
|
||||
self._aggregate_overtime_add_work_type_hours(work_type, hours, iso_date, result, iso_days, day_hours, week_hours)
|
||||
|
||||
return result
|
||||
|
||||
def _aggregate_overtime_add_work_type_hours(self, work_type, hours, iso_date, working_aggregation, iso_days, day_hours, week_hours):
|
||||
"""
|
||||
:param work_type: work type of hours being added
|
||||
:param hours: hours being added
|
||||
:param iso_date: date hours were worked
|
||||
:param working_aggregation: dict of work type hours as they are processed
|
||||
:param iso_days: set of iso days already seen
|
||||
:param day_hours: hours worked on iso dates already processed
|
||||
:param week_hours: hours worked on iso week already processed
|
||||
:return:
|
||||
"""
|
||||
week = iso_date[1]
|
||||
if work_type.overtime_work_type_id and work_type.overtime_type_id:
|
||||
ot_h_w = work_type.overtime_type_id.hours_per_week
|
||||
ot_h_d = work_type.overtime_type_id.hours_per_day
|
||||
|
||||
regular_hours = hours
|
||||
# adjust the hours based on overtime conditions
|
||||
if ot_h_d and (day_hours[iso_date] + hours) > ot_h_d:
|
||||
# daily overtime in effect
|
||||
remaining_hours = max(ot_h_d - day_hours[iso_date], 0.0)
|
||||
regular_hours = min(remaining_hours, hours)
|
||||
elif ot_h_w:
|
||||
# not daily, but weekly limits....
|
||||
remaining_hours = max(ot_h_w - week_hours[week], 0.0)
|
||||
regular_hours = min(remaining_hours, hours)
|
||||
ot_hours = hours - regular_hours
|
||||
if regular_hours:
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
working_aggregation[work_type][0] += 1.0
|
||||
working_aggregation[work_type][1] += regular_hours
|
||||
day_hours[iso_date] += regular_hours
|
||||
week_hours[week] += regular_hours
|
||||
if ot_hours:
|
||||
# we need to save this because it won't be set once it reenter, we won't know what the original
|
||||
# overtime multiplier was
|
||||
working_aggregation[work_type.overtime_work_type_id][2] = work_type.overtime_type_id.multiplier
|
||||
self._aggregate_overtime_add_work_type_hours(work_type.overtime_work_type_id, ot_hours, iso_date,
|
||||
working_aggregation, iso_days, day_hours, week_hours)
|
||||
else:
|
||||
# No overtime, just needs added to set
|
||||
if iso_date not in iso_days:
|
||||
iso_days.add(iso_date)
|
||||
working_aggregation[work_type][0] += 1.0
|
||||
working_aggregation[work_type][1] += hours
|
||||
day_hours[iso_date] += hours
|
||||
week_hours[week] += hours
|
||||
|
||||
Reference in New Issue
Block a user