Skip to content

Commit

Permalink
[FIX] resource_booking: Add extra consistency check to _availability_…
Browse files Browse the repository at this point in the history
…is_fitting

Signed-off-by: Carmen Bianca BAKKER <carmen@coopiteasy.be>
  • Loading branch information
carmenbianca committed Feb 9, 2023
1 parent c2c063c commit da716b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion resource_booking/models/resource_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ def _availability_is_fitting(available_intervals, start_dt, end_dt):
and start_date != end_date
and (end_date - start_date).days == (len(available_intervals) - 1)
):
return True
for item in available_intervals:
# Intervals that aren't on the end date should end at 23:59.
if item[1].date() != end_date and (
item[1].hour != 23 or item[1].minute != 59
):
break
# Intervals that aren't on the start date should start at 00:00.
if item[0].date() != start_date and (
item[0].hour != 0 or item[0].minute != 0
):
break
else:
return True
return False


Expand Down
12 changes: 12 additions & 0 deletions resource_booking/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ def test_scheduling_constraints_span_days(self):
"combination_auto_assign": False,
}
)
# Booking cannot overlap.
with self.assertRaises(ValidationError), self.env.cr.savepoint():
self.env["resource.booking"].create(
{
"partner_id": self.partner.id,
"start": "2021-03-06 22:00:00",
"duration": 4,
"type_id": self.rbt.id,
"combination_id": rbc_satsun.id,
"combination_auto_assign": False,
}
)
# If there are too many minutes between the end and start of the two
# dates, the booking cannot be contiguous.
cal_satsun.attendance_ids[0].hour_to = 23.96 # 23:58
Expand Down

0 comments on commit da716b0

Please sign in to comment.