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 to abstract override class and use on Work Types themselves
E.g. It is now possible to support "Sunday Pay" where before it was only possible to give "Sunday Overtime Pay" as an override to overtime itself.
This commit is contained in:
@@ -4,11 +4,51 @@ from odoo.exceptions import ValidationError
|
||||
from .resource_calendar import WEEKDAY_SELECTION
|
||||
|
||||
|
||||
class WorkEntryOverride(models.AbstractModel):
|
||||
_name = 'hr.work.entry.type.override.abstract'
|
||||
_order = 'date desc, day_of_week'
|
||||
|
||||
name = fields.Char(string='Description')
|
||||
work_type_id = fields.Many2one('hr.work.entry.type', string='Override Work Type', required=True,
|
||||
help='Distinct Work Type for when this applies.')
|
||||
multiplier = fields.Float(string='Multiplier',
|
||||
help='Rate for override. E.g. maybe you have "Sunday Pay" at 2.0x')
|
||||
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
|
||||
|
||||
|
||||
class HRWorkEntryType(models.Model):
|
||||
_inherit = 'hr.work.entry.type'
|
||||
|
||||
overtime_work_type_id = fields.Many2one('hr.work.entry.type', string='Overtime Work Type')
|
||||
overtime_type_id = fields.Many2one('hr.work.entry.overtime.type', string='Overtime Rules')
|
||||
override_ids = fields.One2many('hr.work.entry.type.override', 'original_type_id', string='Overrides',
|
||||
help='Override work entry type on payslip.')
|
||||
|
||||
def override_for_iso_date(self, iso_date):
|
||||
return self.override_ids.iso_date_applies(iso_date)
|
||||
|
||||
|
||||
class HRWorkEntryTypeOverride(models.Model):
|
||||
_name = 'hr.work.entry.type.override'
|
||||
_inherit = 'hr.work.entry.type.override.abstract'
|
||||
_description = 'Work Type Override'
|
||||
|
||||
original_type_id = fields.Many2one('hr.work.entry.type',
|
||||
string='Work Entry Type')
|
||||
|
||||
|
||||
class HRWorkEntryOvertime(models.Model):
|
||||
@@ -32,30 +72,8 @@ class HRWorkEntryOvertime(models.Model):
|
||||
|
||||
class HRWorkEntryOvertimeOverride(models.Model):
|
||||
_name = 'hr.work.entry.overtime.type.override'
|
||||
_inherit = 'hr.work.entry.type.override.abstract'
|
||||
_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
|
||||
|
||||
Reference in New Issue
Block a user