@@ -18,22 +18,20 @@ class AppointmentType(models.Model):
18
18
19
19
capacity_type = fields .Selection (
20
20
[
21
- ("single_booking " , "Single Booking" ),
21
+ ("one_booking " , "One Booking" ),
22
22
("multiple_bookings" , "Multiple Bookings" ),
23
23
("multiple_seats" , "Multiple Seats" ),
24
24
],
25
25
string = "Capacity Type" ,
26
26
required = True ,
27
- default = "single_booking " ,
27
+ default = "one_booking " ,
28
28
)
29
-
30
29
user_capacity_count = fields .Integer (
31
30
"User cpacity count" ,
32
31
default = 1 ,
33
32
help = "Maximum number of users bookings per slot (for multiple bookings or multiple seats)." ,
34
33
)
35
34
36
-
37
35
@api .constrains ("user_capacity_count" )
38
36
def _check_user_capacity_count (self ):
39
37
for record in self :
@@ -91,7 +89,7 @@ def _slot_availability_is_resource_available(self, slot, resource, availability_
91
89
slot_start_dt_utc , slot_end_dt_utc = slot ['UTC' ][0 ], slot ['UTC' ][1 ]
92
90
resource_to_bookings = availability_values .get ('resource_to_bookings' )
93
91
# Check if there is already a booking line for the time slot and make it available
94
- # only if the resource is shareable and the capacity_type is not single_booking .
92
+ # only if the resource is shareable and the capacity_type is not one_booking .
95
93
# This avoid to mark the resource as "available" and compute unnecessary remaining capacity computation
96
94
# because of potential linked resources.
97
95
if resource_to_bookings .get (resource ):
@@ -108,7 +106,6 @@ def _slot_availability_is_resource_available(self, slot, resource, availability_
108
106
109
107
return True
110
108
111
-
112
109
def _slot_availability_select_best_resources (self , capacity_info , asked_capacity ):
113
110
""" Check and select the best resources for the capacity needed
114
111
:params main_resources_remaining_capacity <dict>: dict containing remaining capacities of resources available
@@ -120,7 +117,7 @@ def _slot_availability_select_best_resources(self, capacity_info, asked_capacity
120
117
available_resources = self .env ['appointment.resource' ].concat (* capacity_info .keys ()).sorted ('sequence' )
121
118
if not available_resources :
122
119
return self .env ['appointment.resource' ]
123
- if self .capacity_type == 'single_booking ' :
120
+ if self .capacity_type == 'one_booking ' :
124
121
return available_resources [0 ] if self .assign_method != 'time_resource' else available_resources
125
122
126
123
perfect_matches = available_resources .filtered (
@@ -209,10 +206,9 @@ def _slots_fill_users_availability(self, slots, start_dt, end_dt, filter_users=N
209
206
else :
210
207
slot ['staff_user_id' ] = available_staff_users
211
208
212
-
213
-
214
209
def _slot_availability_is_user_available (self , slot , staff_user , availability_values , asked_capacity = 1 ):
215
- """ This method verifies if the user is available on the given slot.
210
+ """
211
+ This method verifies if the user is available on the given slot.
216
212
It checks whether the user has calendar events clashing and if he
217
213
is included in slot's restricted users.
218
214
@@ -247,7 +243,7 @@ def _slot_availability_is_user_available(self, slot, staff_user, availability_va
247
243
# return False
248
244
for event in day_events :
249
245
if not event .allday and (event .start < slot_end_dt_utc and event .stop > slot_start_dt_utc ):
250
- if self .capacity_type != "single_booking " and self == event .appointment_type_id :
246
+ if self .capacity_type != "one_booking " and self == event .appointment_type_id :
251
247
if users_remaining_capacity ['total_remaining_capacity' ] >= asked_capacity :
252
248
continue
253
249
return False
@@ -261,7 +257,7 @@ def _slot_availability_is_user_available(self, slot, staff_user, availability_va
261
257
return True
262
258
263
259
def _get_users_remaining_capacity (self , users , slot_start_utc , slot_stop_utc , availability_values = None ):
264
- """
260
+ """
265
261
Compute the remaining capacity for users in a specific time slot.
266
262
:param <res.users> users : record containing one or a multiple of user
267
263
:param datetime slot_start_utc: start of slot (in naive UTC)
@@ -297,7 +293,7 @@ def _get_users_remaining_capacity(self, users, slot_start_utc, slot_stop_utc, av
297
293
return users_remaining_capacity
298
294
299
295
def _slot_availability_prepare_users_values (self , staff_users , start_dt , end_dt ):
300
- """
296
+ """
301
297
Override to add booking values.
302
298
303
299
:return: update ``super()`` values with users booking vaues, formatted like
@@ -312,11 +308,11 @@ def _slot_availability_prepare_users_values(self, staff_users, start_dt, end_dt)
312
308
313
309
def _slot_availability_prepare_users_bookings_values (self , users , start_dt_utc , end_dt_utc ):
314
310
"""
315
- This method retrieves and organizes bookings for the given users within the specified time range.
316
- Users may handle multiple appointment types, so all overlapping bookings must be considered
311
+ This method retrieves and organizes bookings for the given users within the specified time range.
312
+ Users may handle multiple appointment types, so all overlapping bookings must be considered
317
313
to prevent double booking.
318
314
319
- :param <res.users> users: A recordset of staff users for whom availability is being checked.
315
+ :param <res.users> users: A recordset of staff users for whom availability is being checked.
320
316
:param datetime start_dt_utc: The start of the appointment check boundary in UTC.
321
317
:param datetime end_dt_utc: The end of the appointment check boundary in UTC.
322
318
@@ -339,7 +335,8 @@ def _slot_availability_prepare_users_bookings_values(self, users, start_dt_utc,
339
335
}
340
336
341
337
def _get_appointment_slots (self , timezone , filter_users = None , filter_resources = None , asked_capacity = 1 , reference_date = None ):
342
- """ Fetch available slots to book an appointment.
338
+ """
339
+ Fetch available slots to book an appointment.
343
340
344
341
:param str timezone: timezone string e.g.: 'Europe/Brussels' or 'Etc/GMT+1'
345
342
:param <res.users> filter_users: filter available slots for those users (can be a singleton
@@ -390,13 +387,13 @@ def _get_appointment_slots(self, timezone, filter_users=None, filter_resources=N
390
387
if self .category == 'custom' and unique_slots :
391
388
# Custom appointment type, the first day should depend on the first slot datetime
392
389
start_first_slot = unique_slots [0 ].start_datetime
393
- first_day_utc = start_first_slot if reference_date > start_first_slot else reference_date
390
+ first_day_utc = min ( reference_date , start_first_slot )
394
391
first_day = requested_tz .fromutc (first_day_utc + relativedelta (hours = self .min_schedule_hours ))
395
392
appointment_duration_days = (unique_slots [- 1 ].end_datetime .date () - reference_date .date ()).days
396
393
last_day = requested_tz .fromutc (reference_date + relativedelta (days = appointment_duration_days ))
397
394
elif self .category == 'punctual' :
398
395
# Punctual appointment type, the first day is the start_datetime if it is in the future, else the first day is now
399
- first_day = requested_tz .fromutc (self . start_datetime if self .start_datetime > now else now )
396
+ first_day = requested_tz .fromutc (max ( now , self .start_datetime ) )
400
397
last_day = requested_tz .fromutc (self .end_datetime )
401
398
else :
402
399
# Recurring appointment type
0 commit comments