Skip to content

Commit 1ffd16a

Browse files
committed
Merge PR OCA#1193 into 14.0
Signed-off-by pedrobaeza
2 parents 389408b + cf0fbaa commit 1ffd16a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

hr_employee_calendar_planning/models/hr_employee.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2019 Tecnativa - Pedro M. Baeza
2-
# Copyright 2022 Tecnativa - Víctor Martínez
2+
# Copyright 2022-2023 Tecnativa - Víctor Martínez
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

55
from odoo import _, api, fields, models
@@ -45,6 +45,7 @@ class HrEmployee(models.Model):
4545
comodel_name="hr.employee.calendar",
4646
inverse_name="employee_id",
4747
string="Calendar planning",
48+
copy=True,
4849
)
4950

5051
def _regenerate_calendar(self):
@@ -142,6 +143,14 @@ def regenerate_calendar(self):
142143
for item in self:
143144
item._regenerate_calendar()
144145

146+
def copy(self, default=None):
147+
self.ensure_one()
148+
new = super().copy(default)
149+
# Define a good main calendar for being able to regenerate it later
150+
new.resource_id.calendar_id = fields.first(new.calendar_ids).calendar_id
151+
new.filtered("calendar_ids").regenerate_calendar()
152+
return new
153+
145154
@api.model_create_multi
146155
def create(self, vals_list):
147156
res = super().create(vals_list)

hr_employee_calendar_planning/tests/test_hr_employee_calendar_planning.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2019 Tecnativa - Pedro M. Baeza
2-
# Copyright 2021 Tecnativa - Víctor Martínez
2+
# Copyright 2021-2023 Tecnativa - Víctor Martínez
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

55
from odoo import exceptions, fields
@@ -415,3 +415,19 @@ def test_copy_global_leaves(self):
415415
)
416416
# test that global leaves on original calendar are not changed
417417
self.assertEqual(global_leave_ids_cal1, self.calendar1.global_leave_ids.ids)
418+
419+
def test_employee_copy(self):
420+
self.employee.calendar_ids = [
421+
(0, 0, {"date_end": "2019-12-31", "calendar_id": self.calendar1.id}),
422+
(0, 0, {"date_start": "2020-01-01", "calendar_id": self.calendar2.id}),
423+
]
424+
self.assertTrue(self.employee.resource_calendar_id)
425+
self.assertTrue(self.employee.resource_calendar_id.auto_generate)
426+
employee2 = self.employee.copy()
427+
self.assertIn(self.calendar1, employee2.mapped("calendar_ids.calendar_id"))
428+
self.assertIn(self.calendar2, employee2.mapped("calendar_ids.calendar_id"))
429+
self.assertTrue(employee2.resource_calendar_id)
430+
self.assertTrue(employee2.resource_calendar_id.auto_generate)
431+
self.assertNotEqual(
432+
self.employee.resource_calendar_id, employee2.resource_calendar_id
433+
)

0 commit comments

Comments
 (0)