[FIX] hr_work_entry_contract: Fix work entries generation

Coming from https://github.com/odoo/odoo/commit/0bac1d33a25e37ebece69de030b9fd72caa43a02

closes odoo/odoo#90670

X-original-commit: f2eb4f0fb4294b4548312a909a841744ee4a9734
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Yannick Tivisse
2022-05-06 13:30:15 +02:00
parent e5d33096fc
commit e5e1f09ae7
2 changed files with 16 additions and 1 deletions
@@ -105,7 +105,7 @@ class HrContract(models.Model):
for leave in itertools.chain(leaves_by_resource[False], leaves_by_resource[resource.id]):
for resource in resources_list:
# Global time off is not for this calendar, can happen with multiple calendars in self
if resource and leave.calendar_id != calendar and not leave.resource_id:
if resource and leave.calendar_id and leave.calendar_id != calendar and not leave.resource_id:
continue
tz = tz if tz else pytz.timezone((resource or contract).tz)
if (tz, start_dt) in tz_dates:
@@ -36,3 +36,18 @@ class TestGlobalTimeOff(TestWorkEntryBase):
leave.calendar_id = contract.resource_calendar_id
work_entries = contract._generate_work_entries(start, end)
self.assertEqual(work_entries.work_entry_type_id, leave.work_entry_type_id)
def test_gto_no_calendar(self):
start = datetime(2018, 1, 1, 0, 0, 0)
end = datetime(2018, 1, 1, 23, 59, 59)
leave = self.env['resource.calendar.leaves'].create({
'date_from': start,
'date_to': end,
'work_entry_type_id': self.work_entry_type_leave.id,
})
contract = self.richard_emp.contract_ids
contract.state = 'open'
contract.date_generated_from = start
contract.date_generated_to = start
work_entries = contract._generate_work_entries(start, end)
self.assertEqual(work_entries.work_entry_type_id, leave.work_entry_type_id)