Skip to content

Commit

Permalink
[IMP] hr_contract_employee_calendar_planning: test post_init_hook by …
Browse files Browse the repository at this point in the history
…creating contracts with different work hours
  • Loading branch information
jonasbuchholz committed Dec 14, 2023
1 parent e5567d4 commit 22726c8
Showing 1 changed file with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,58 @@


class TestHrContractEmployeeCalendarPlanning(TestContractCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
def test_calendar_migration_from_contracts(self):
self.env = self.env(
context=dict(
cls.env.context,
self.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
calendar_ids = [
(
0,
0,
{
"date_start": False,
"date_end": datetime.strptime("2020-11-30", "%Y-%m-%d").date(),
"calendar_id": cls.env["resource.calendar"].browse([2]).id,
},
),
(
0,
0,
{
"date_start": datetime.strptime("2020-12-01", "%Y-%m-%d").date(),
"date_end": False,
"calendar_id": cls.env["resource.calendar"].browse([1]).id,
},
),
]
cls.employee.calendar_ids = calendar_ids

def test_calendar_migration_from_contracts(self):
self.contract1 = self.env["hr.contract"].create(
# newly created contracts get the same calendar as the employee
self.employee.resource_calendar_id = self.env["resource.calendar"].browse([1])
self.env["hr.contract"].create(
{
"name": "contract1",
"employee_id": self.employee.id,
"wage": 1,
"state": "close",
"kanban_state": "normal",
"resource_calendar_id": self.env["resource.calendar"].browse([1]).id,
"employee_id": self.employee.id,
"date_start": datetime.strptime("2018-11-30", "%Y-%m-%d").date(),
"date_end": datetime.strptime("2019-11-30", "%Y-%m-%d").date(),
}
)
self.contract2 = self.env["hr.contract"].create(
self.employee.resource_calendar_id = self.env["resource.calendar"].browse([2])
self.env["hr.contract"].create(
{
"name": "contract2",
"employee_id": self.employee.id,
"wage": 1,
"state": "open",
"kanban_state": "normal",
"resource_calendar_id": self.env["resource.calendar"].browse([2]).id,
"employee_id": self.employee.id,
"date_start": datetime.strptime("2019-12-01", "%Y-%m-%d").date(),
"date_end": datetime.strptime("2020-11-30", "%Y-%m-%d").date(),
}
)
original_cal_ids = self.employee.calendar_ids.ids
calendar_ids = self.env["hr.employee.calendar"].create(
[
{
"date_start": False,
"date_end": datetime.strptime("2020-11-30", "%Y-%m-%d").date(),
"calendar_id": 2,
"employee_id": self.employee.id,
},
{
"date_start": datetime.strptime("2020-12-01", "%Y-%m-%d").date(),
"date_end": False,
"calendar_id": 1,
"employee_id": self.employee.id,
},
]
)
self.employee.calendar_ids = [(6, 0, calendar_ids.ids)]
start_dt = datetime(2019, 1, 1, 0, 0, 0)
end_dt = datetime(2019, 1, 2, 0, 0, 0)
self.assertEqual(
Expand All @@ -85,6 +76,4 @@ def test_calendar_migration_from_contracts(self):
end_dt=end_dt,
),
)
self.assertTrue(
all(ids in self.employee.calendar_ids.ids for ids in original_cal_ids)
)
self.assertTrue(calendar_ids.ids < self.employee.calendar_ids.ids)

0 comments on commit 22726c8

Please sign in to comment.