[FIX] resource : fix traceback in _get_attendance_intervals_days_data with adjacent attendances
----------------------Issue-------------------------- When calling get_work_duration_data on a calendar that contains adjacent calendar attendances, we get a traceback in the method _get_attendance_intervals_days_data. This is due to the fact that adjacent attendances (like 09:00 -> 13:00, 13:00 -> 17:00) will get merged into one single interval. Which will generate an attendance interval with multiple resource.calendar.attendance records associated with it. ----------------Steps to reproduce------------------- 1) Create a Calendar 2) Create for a same day 2 attendances going from 09:00 to 13:00 and another going from 13:00 to 17:00 3) Try creating a time-off for that day 3) Associate that calendar with an employee 4) Try creating a time off on the day where we have adjacent attendances ---------------------Fix----------------------------- Adapt _get_attendance_intervals_days_data to handle attendance intervals associated with multiple resource.calendar.attendance task-3615723 closes odoo/odoo#144036 Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
This commit is contained in:
@@ -488,7 +488,7 @@ class ResourceCalendar(models.Model):
|
||||
# take durations in days proportionally to what is left of the interval.
|
||||
interval_hours = (stop - start).total_seconds() / 3600
|
||||
day_hours[start.date()] += interval_hours
|
||||
day_days[start.date()] += meta.duration_days * interval_hours / meta.duration_hours
|
||||
day_days[start.date()] += sum(meta.mapped('duration_days')) * interval_hours / sum(meta.mapped('duration_hours'))
|
||||
|
||||
return {
|
||||
# Round the number of days to the closest 16th of a day.
|
||||
|
||||
@@ -61,6 +61,8 @@ class TestResourceCommon(TransactionCase):
|
||||
|
||||
cls.calendar_paul = cls._define_calendar('Morning and evening shifts', sum([((2, 7, i, 0.5), (10, 16, i, 0.5)) for i in range(5)], ()), 'Brazil/DeNoronha')
|
||||
|
||||
cls.calendar_bob = cls._define_calendar('Calendar with adjacent attendances', sum([((8, 12, i, 0.5), (12, 16, i, 0.5)) for i in range(5)], ()), 'Europe/Brussels')
|
||||
|
||||
# Employee is linked to a resource.resource via resource.mixin
|
||||
cls.jean = cls.env['resource.test'].create({
|
||||
'name': 'Jean',
|
||||
@@ -84,6 +86,12 @@ class TestResourceCommon(TransactionCase):
|
||||
'resource_calendar_id': cls.calendar_paul.id,
|
||||
})
|
||||
|
||||
cls.bob = cls.env['resource.test'].create({
|
||||
'name': 'Bob',
|
||||
'resource_calendar_id': cls.calendar_bob.id,
|
||||
})
|
||||
|
||||
|
||||
cls.two_weeks_resource = cls._define_calendar_2_weeks(
|
||||
'Two weeks resource',
|
||||
[
|
||||
|
||||
@@ -668,6 +668,14 @@ class TestResMixin(TestResourceCommon):
|
||||
)[self.jean.id]
|
||||
self.assertEqual(data, {'days': 5, 'hours': 40})
|
||||
|
||||
# Viewing it as Bob
|
||||
data = self.bob._get_work_days_data_batch(
|
||||
datetime_tz(2018, 4, 2, 0, 0, 0, tzinfo=self.bob.tz),
|
||||
datetime_tz(2018, 4, 6, 16, 0, 0, tzinfo=self.bob.tz),
|
||||
)[self.bob.id]
|
||||
self.assertEqual(data, {'days': 5, 'hours': 40})
|
||||
|
||||
|
||||
# Viewing it as Patel
|
||||
# Views from 2018/04/01 20:00:00 to 2018/04/06 12:00:00
|
||||
data = self.jean._get_work_days_data_batch(
|
||||
|
||||
Reference in New Issue
Block a user