[ADD]allow_negative_leave_and_allocation

This commit is contained in:
2025-04-16 15:05:12 +02:00
parent beb64d034d
commit 4a00e642e0
14 changed files with 980 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import hr_leave_type, hr_leave, hr_leave_allocation

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Copyright (c) 2005-2006 Axelor SARL. (http://www.axelor.com)
from odoo import api, models
class HrLeave(models.Model):
_inherit = "hr.leave"
@api.constrains('state', 'number_of_days', 'holiday_status_id')
def _check_holidays(self):
for holiday in self:
if holiday.holiday_status_id.allows_negative:
continue
super()._check_holidays()

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Copyright (c) 2005-2006 Axelor SARL. (http://www.axelor.com)
from odoo import models
class HrLeaveAllocation(models.Model):
_inherit = "hr.leave.allocation"
_sql_constraints = [
('type_value',
"CHECK( (holiday_type='employee' AND (employee_id IS NOT NULL OR multi_employee IS TRUE)) or "
"(holiday_type='category' AND category_id IS NOT NULL) or "
"(holiday_type='department' AND department_id IS NOT NULL) or "
"(holiday_type='company' AND mode_company_id IS NOT NULL))",
"The employee, department, company or employee category of this request is missing. Please make sure that your user login is linked to an employee."),
('duration_check', "CHECK((allocation_type != 'regular'))", "The duration must be greater than 0."),
]

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class HolidaysType(models.Model):
_inherit = "hr.leave.type"
# negative time off
allows_negative = fields.Boolean(string='Allow Negative Leaves',
help="If checked, users request can exceed the allocated days and balance can go in negative.")
@api.depends('requires_allocation')
def _compute_valid(self):
res = super()._compute_valid()
for holiday_type in res:
if not holiday_type.has_valid_allocation:
holiday_type.has_valid_allocation = holiday_type.allows_negative
def _get_days_request(self):
res = super()._get_days_request()
res[1]['allows_negative'] = self.allows_negative
return res