-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathhr_version.py
More file actions
40 lines (36 loc) · 1.73 KB
/
Copy pathhr_version.py
File metadata and controls
40 lines (36 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from odoo import api, models
class HrVersion(models.Model):
_inherit = "hr.version"
def write(self, vals):
if vals.get("resource_calendar_id") and self.filtered(
lambda version: version.employee_id
and vals.get("resource_calendar_id")
!= version.employee_id.resource_calendar_id.id
):
# in the write method of versions, when writing the resource_calendar_id
# the employee resource_calendar_id is set to the same id
# this interferes with the logic of hr_employee_calendar_planning,
# which assumes that calendar times are managed by
# resource.calendar.attendances in auto-generated calendars
# based on the employee's calendar_ids.
# since the default calendar for new versions is the employee calendar,
# and we set the correct calendar for the existing version
# in the post_init_hook, we resolve this conflict by not allowing
# calendar changes in versions.
vals.pop("resource_calendar_id")
return super().write(vals)
@api.model_create_multi
def create(self, vals_list):
# the create method of versions syncs version
# calendars with employee calendars
# in order to not overwrite the employee calendar
# we set the version calendar to match the employee calendar
for vals in vals_list:
employee_calendar = (
self.env["hr.employee"]
.browse([vals.get("employee_id")])
.resource_calendar_id
)
if employee_calendar:
vals.update({"resource_calendar_id": employee_calendar.id})
return super().create(vals_list)