Debian Codegraph @

addons/hr_holidays_attendance/models/hr_leave_accrual_plan_level.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2 from odoo import api, fields, models
3 from odoo.exceptions import ValidationError
4
5
6 class HrLeaveAccrualLevel(models.Model):
7 _inherit = "hr.leave.accrual.level"
8
9 frequency = fields.Selection(
10 selection_add=[('worked_hours', 'Per Hour Worked')],
11 ondelete={'worked_hours': 'cascade'},
12 compute='_compute_frequency',
13 store=True,
14 readonly=False,
15 )
16
17 @api.constrains('frequency')
18 def _check_worked_hours(self):
19 for level in self:
20 if level.frequency == 'worked_hours' and level.accrued_gain_time == 'start':
21 raise ValidationError(self.env._("You can't base accrued time on hours worked, because time is accrued at the start of the period."))
22
23 @api.depends('accrued_gain_time')
24 def _compute_frequency(self):
25 for level in self:
26 if level.accrued_gain_time == 'start' and level.frequency == 'worked_hours':
27 level.frequency = 'hourly'
28
29 def _get_hourly_frequencies(self):
30 return super()._get_hourly_frequencies() + ["worked_hours"]