[FIX]16.0-fix-french-holidays:fix the resource calendar linked to the leave
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "France - Time Off",
|
"name": "France - Time Off",
|
||||||
"version": "16.0.1.0.0",
|
"version": "16.0.1.0.1",
|
||||||
"category": "Human Resources/Time Off",
|
"category": "Human Resources/Time Off",
|
||||||
"countries": ["fr"],
|
"countries": ["fr"],
|
||||||
"summary": "Management of leaves for part-time workers in France",
|
"summary": "Management of leaves for part-time workers in France",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from odoo import fields, models, _
|
from odoo import fields, models, _, api
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
class HrLeave(models.Model):
|
class HrLeave(models.Model):
|
||||||
@@ -11,6 +11,13 @@ class HrLeave(models.Model):
|
|||||||
resource_calendar_id = fields.Many2one('resource.calendar', compute='_compute_resource_calendar_id', store=True, readonly=False, copy=False)
|
resource_calendar_id = fields.Many2one('resource.calendar', compute='_compute_resource_calendar_id', store=True, readonly=False, copy=False)
|
||||||
l10n_fr_date_to_changed = fields.Boolean()
|
l10n_fr_date_to_changed = fields.Boolean()
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
'holiday_type',
|
||||||
|
'employee_id',
|
||||||
|
'employee_id.resource_calendar_id',
|
||||||
|
'request_date_from',
|
||||||
|
'request_date_to',
|
||||||
|
)
|
||||||
def _compute_resource_calendar_id(self):
|
def _compute_resource_calendar_id(self):
|
||||||
for leave in self:
|
for leave in self:
|
||||||
calendar = False
|
calendar = False
|
||||||
@@ -36,6 +43,20 @@ class HrLeave(models.Model):
|
|||||||
# If there are more than one contract they should all have the
|
# If there are more than one contract they should all have the
|
||||||
# same calendar, otherwise a constraint is violated.
|
# same calendar, otherwise a constraint is violated.
|
||||||
calendar = contracts[:1].resource_calendar_id
|
calendar = contracts[:1].resource_calendar_id
|
||||||
|
# Crappy hack again : if hr_employee_calendar_planning is installed
|
||||||
|
# use planning calendar instead of contract calendar
|
||||||
|
if 'hr.employee.calendar' in self.env:
|
||||||
|
calendar_planning = self.env["hr.employee.calendar"].search(
|
||||||
|
[
|
||||||
|
("employee_id", "=", leave.employee_id.id),
|
||||||
|
("date_start", "<=", leave.request_date_to),
|
||||||
|
"|", ("date_end", "=", False), # pas de date de fin OU
|
||||||
|
("date_end", ">=", leave.request_date_from), # date de fin après le début
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
if calendar_planning:
|
||||||
|
calendar = calendar_planning.calendar_id
|
||||||
elif leave.holiday_type == 'department':
|
elif leave.holiday_type == 'department':
|
||||||
calendar = leave.department_id.company_id.resource_calendar_id
|
calendar = leave.department_id.company_id.resource_calendar_id
|
||||||
elif leave.holiday_type == 'company':
|
elif leave.holiday_type == 'company':
|
||||||
|
|||||||
Reference in New Issue
Block a user