mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] hr_payroll_overtime: implement date or day of week overrides to overtime rules
This commit is contained in:
@@ -78,13 +78,24 @@ class HRPayslip(models.Model):
|
||||
day_hours[iso_date] += regular_hours
|
||||
week_hours[week] += regular_hours
|
||||
if ot_hours:
|
||||
overtime_work_type = work_type.overtime_work_type_id
|
||||
multiplier = work_type.overtime_type_id.multiplier
|
||||
override = work_type.overtime_type_id.override_for_iso_date(iso_date)
|
||||
if work_type == overtime_work_type:
|
||||
# trivial infinite recursion
|
||||
raise UserError('Work type "%s" (id %s) must not have itself as its next overtime type.' % (work_type.name, work_type.id))
|
||||
if override:
|
||||
overtime_work_type = override.work_type_id
|
||||
multiplier = override.multiplier
|
||||
if work_type == overtime_work_type:
|
||||
# trivial infinite recursion from override
|
||||
raise UserError('Work type "%s" (id %s) must not have itself as its next overtime type. '
|
||||
'This occurred due to an override "%s" from overtime rules "%s".' % (
|
||||
work_type.name, work_type.id, override.name, work_type.overtime_type_id.name))
|
||||
# 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
|
||||
if work_type == work_type.overtime_work_type_id:
|
||||
# trivial infinite recursion
|
||||
raise UserError('Work type %s (id %s) must not have itself as its next overtime type.' % (work_type.name, work_type.id))
|
||||
self._aggregate_overtime_add_work_type_hours(work_type.overtime_work_type_id, ot_hours, iso_date,
|
||||
working_aggregation[overtime_work_type][2] = multiplier
|
||||
self._aggregate_overtime_add_work_type_hours(overtime_work_type, ot_hours, iso_date,
|
||||
working_aggregation, iso_days, day_hours, week_hours)
|
||||
else:
|
||||
# No overtime, just needs added to set
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .resource_calendar import WEEKDAY_SELECTION
|
||||
|
||||
|
||||
class HRWorkEntryType(models.Model):
|
||||
@@ -19,3 +22,40 @@ class HRWorkEntryOvertime(models.Model):
|
||||
help='Number of hours worked in a week to trigger overtime.')
|
||||
multiplier = fields.Float(string='Multiplier',
|
||||
help='Rate for when overtime is reached.')
|
||||
override_ids = fields.One2many('hr.work.entry.overtime.type.override', 'overtime_type_id',
|
||||
string='Overrides',
|
||||
help='Override lines with a Date will be considered before Day of Week.')
|
||||
|
||||
def override_for_iso_date(self, iso_date):
|
||||
return self.override_ids.iso_date_applies(iso_date)
|
||||
|
||||
|
||||
class HRWorkEntryOvertimeOverride(models.Model):
|
||||
_name = 'hr.work.entry.overtime.type.override'
|
||||
_description = 'Overtime Rule Override'
|
||||
_order = 'date desc, day_of_week'
|
||||
|
||||
name = fields.Char(string='Description')
|
||||
overtime_type_id = fields.Many2one('hr.work.entry.overtime.type',
|
||||
string='Overtime Rules')
|
||||
work_type_id = fields.Many2one('hr.work.entry.type', string='Overtime Work Type', required=True,
|
||||
help='Distinct Work Type for this. Given the different rate, it should '
|
||||
' be different from other Overtime Work Types (because payslips '
|
||||
'should only have one line/rate per work type).')
|
||||
multiplier = fields.Float(string='Multiplier',
|
||||
help='Rate for when overtime is reached.')
|
||||
day_of_week = fields.Selection(WEEKDAY_SELECTION, string='Day of Week')
|
||||
date = fields.Date(string='Date')
|
||||
|
||||
@api.constrains('day_of_week', 'date')
|
||||
def _constrain_days(self):
|
||||
for override in self:
|
||||
if override.day_of_week and override.date:
|
||||
raise ValidationError('An override should only have a Date OR Day of Week.')
|
||||
|
||||
def iso_date_applies(self, iso_date):
|
||||
for override in self:
|
||||
if override.date and override.date.isocalendar() == iso_date:
|
||||
return override
|
||||
if int(override.day_of_week) == iso_date[2]:
|
||||
return override
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
WEEKDAY_SELECTION = [
|
||||
('1', 'Monday'),
|
||||
('2', 'Tuesday'),
|
||||
('3', 'Wednesday'),
|
||||
('4', 'Thursday'),
|
||||
('5', 'Friday'),
|
||||
('6', 'Saturday'),
|
||||
('7', 'Sunday'),
|
||||
]
|
||||
|
||||
|
||||
class ResourceCalendar(models.Model):
|
||||
_inherit = 'resource.calendar'
|
||||
|
||||
day_week_start = fields.Selection([
|
||||
('1', 'Monday'),
|
||||
('2', 'Tuesday'),
|
||||
('3', 'Wednesday'),
|
||||
('4', 'Thursday'),
|
||||
('5', 'Friday'),
|
||||
('6', 'Saturday'),
|
||||
('7', 'Sunday'),
|
||||
], string='Day Week Starts', required=True, default='1')
|
||||
day_week_start = fields.Selection(WEEKDAY_SELECTION, string='Day Week Starts', required=True, default='1')
|
||||
|
||||
Reference in New Issue
Block a user