Skip to content

Commit

Permalink
[IMP] resource_booking: Write tests for day-spanning booking
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <carmen@coopiteasy.be>
  • Loading branch information
carmenbianca committed Jan 31, 2023
1 parent b762f92 commit ce78001
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
36 changes: 30 additions & 6 deletions resource_booking/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def create_test_data(obj):
)
)
# Create one resource.calendar available on Mondays, another one on
# Tuesdays, and another one on Mondays and Tuesdays; in that order
# Tuesdays, and another one on Mondays and Tuesdays; in that order.
# Also create an all-day calendar for Saturday and Sunday.
attendances = [
(
0,
Expand All @@ -34,12 +35,35 @@ def create_test_data(obj):
"day_period": "morning",
},
),
(
0,
0,
{
"name": "Saturdays",
"dayofweek": "5",
"hour_from": 0,
"hour_to": 23.99,
"day_period": "morning",
},
),
(
0,
0,
{
"name": "Sunday",
"dayofweek": "6",
"hour_from": 0,
"hour_to": 23.99,
"day_period": "morning",
},
),
]
obj.r_calendars = obj.env["resource.calendar"].create(
[
{"name": "Mon", "attendance_ids": attendances[:1], "tz": "UTC"},
{"name": "Tue", "attendance_ids": attendances[1:], "tz": "UTC"},
{"name": "MonTue", "attendance_ids": attendances, "tz": "UTC"},
{"name": "Mon", "attendance_ids": [attendances[0]], "tz": "UTC"},
{"name": "Tue", "attendance_ids": [attendances[1]], "tz": "UTC"},
{"name": "MonTue", "attendance_ids": attendances[0:2], "tz": "UTC"},
{"name": "SatSun", "attendance_ids": attendances[2:4], "tz": "UTC"},
]
)
# Create one material resource for each of those calendars; same order
Expand All @@ -62,7 +86,7 @@ def create_test_data(obj):
"login": "user_%d" % num,
"name": "User %d" % num,
}
for num in range(3)
for num, _ in enumerate(obj.r_calendars)
]
)
obj.r_users = obj.env["resource.resource"].create(
Expand All @@ -85,7 +109,7 @@ def create_test_data(obj):
for (user, material) in zip(obj.r_users, obj.r_materials)
]
)
# Create one RBT that includes all 3 RBCs as available combinations
# Create one RBT that includes all RBCs as available combinations
obj.rbt = obj.env["resource.booking.type"].create(
{
"name": "Test resource booking type",
Expand Down
32 changes: 31 additions & 1 deletion resource_booking/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ def test_scheduling_conflict_constraints(self):
}
)

def test_scheduling_constraints_span_days(self):
# Booking can span across two calendar days.
cal_satsun = self.r_calendars[3]
rbc_satsun = self.rbcs[3]
self.rbt.resource_calendar_id = cal_satsun
self.env["resource.booking"].create(
{
"partner_id": self.partner.id,
"start": "2021-03-06 23:00:00",
"duration": 2,
"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
with self.assertRaises(ValidationError), self.env.cr.savepoint():
self.env["resource.booking"].create(
{
"partner_id": self.partner.id,
"start": "2021-03-06 23:00:00",
"duration": 2,
"type_id": self.rbt.id,
"combination_id": rbc_satsun.id,
"combination_auto_assign": False,
}
)

def test_rbc_forced_calendar(self):
# Type is available on Mondays
cal_mon = self.r_calendars[0]
Expand Down Expand Up @@ -245,7 +275,7 @@ def test_state(self):

def test_sorted_assignment(self):
"""Set sorted assignment on RBT and test it works correctly."""
rbc_mon, rbc_tue, rbc_montue = self.rbcs
rbc_mon, rbc_tue, rbc_montue, rbc_satsun = self.rbcs
with Form(self.rbt) as rbt_form:
rbt_form.combination_assignment = "sorted"
# Book next monday at 10:00
Expand Down

0 comments on commit ce78001

Please sign in to comment.