23
23
from appointment .utils .db_helpers import (
24
24
Appointment , AppointmentRequest , EmailVerificationCode , Service , StaffMember , WorkingHours , calculate_slots ,
25
25
calculate_staff_slots , check_day_off_for_staff , create_and_save_appointment , create_new_user ,
26
- day_off_exists_for_date_range , exclude_booked_slots , get_all_appointments , get_all_staff_members ,
26
+ day_off_exists_for_date_range , exclude_booked_slots , exclude_pending_reschedules , get_all_appointments ,
27
+ get_all_staff_members ,
27
28
get_appointment_by_id , get_appointments_for_date_and_time , get_staff_member_appointment_list ,
28
29
get_staff_member_from_user_id_or_logged_in , get_times_from_config , get_user_by_email ,
29
30
get_working_hours_for_staff_and_day , parse_name , update_appointment_reminder , working_hours_exist )
@@ -304,7 +305,7 @@ def get_working_hours_and_days_off_context(request, btn_txt, form_name, form, us
304
305
return context
305
306
306
307
307
- def save_appointment (appt , client_name , client_email , start_time , phone_number , client_address , service_id ,
308
+ def save_appointment (appt , client_name , client_email , start_time , phone_number , client_address , service_id , request ,
308
309
want_reminder = False , additional_info = None ):
309
310
"""Save an appointment's details.
310
311
:return: The modified appointment.
@@ -329,7 +330,7 @@ def save_appointment(appt, client_name, client_email, start_time, phone_number,
329
330
330
331
# Update reminder here
331
332
update_appointment_reminder (appointment = appt , new_date = appt_request .date , new_start_time = start_time ,
332
- want_reminder = want_reminder )
333
+ want_reminder = want_reminder , request = request )
333
334
334
335
appt_request .service = service
335
336
appt_request .start_time = start_time
@@ -345,12 +346,13 @@ def save_appointment(appt, client_name, client_email, start_time, phone_number,
345
346
return appt
346
347
347
348
348
- def save_appt_date_time (appt_start_time , appt_date , appt_id ):
349
+ def save_appt_date_time (appt_start_time , appt_date , appt_id , request ):
349
350
"""Save the date and time of an appointment request.
350
351
351
352
:param appt_start_time: The start time of the appointment request.
352
353
:param appt_date: The date of the appointment request.
353
354
:param appt_id: The ID of the appointment to modify.
355
+ :param request: The request object.
354
356
:return: The modified appointment.
355
357
"""
356
358
appt = Appointment .objects .get (id = appt_id )
@@ -373,7 +375,8 @@ def save_appt_date_time(appt_start_time, appt_date, appt_id):
373
375
appt_date_obj = appt_date
374
376
375
377
# Update reminder here
376
- update_appointment_reminder (appointment = appt , new_date = appt_date_obj , new_start_time = appt_start_time_obj )
378
+ update_appointment_reminder (appointment = appt , new_date = appt_date_obj , new_start_time = appt_start_time_obj ,
379
+ request = request )
377
380
378
381
# Modify and save appointment request details
379
382
appt_request = appt .appointment_request
@@ -422,6 +425,7 @@ def get_available_slots_for_staff(date, staff_member):
422
425
423
426
slot_duration = datetime .timedelta (minutes = staff_member .get_slot_duration ())
424
427
slots = calculate_staff_slots (date , staff_member )
428
+ slots = exclude_pending_reschedules (slots , staff_member , date )
425
429
appointments = get_appointments_for_date_and_time (date , working_hours_dict ['start_time' ],
426
430
working_hours_dict ['end_time' ], staff_member )
427
431
slots = exclude_booked_slots (appointments , slots , slot_duration )
@@ -594,7 +598,7 @@ def create_new_appointment(data, request):
594
598
'additional_info' : data .get ("additional_info" , "" ),
595
599
'paid' : False
596
600
}
597
- appointment = create_and_save_appointment (appointment_request , client_data , appointment_data )
601
+ appointment = create_and_save_appointment (appointment_request , client_data , appointment_data , request )
598
602
appointment_list = convert_appointment_to_json (request , [appointment ])
599
603
600
604
return json_response ("Appointment created successfully." , custom_data = {'appt' : appointment_list })
@@ -613,7 +617,8 @@ def update_existing_appointment(data, request):
613
617
client_address = data .get ("client_address" ),
614
618
service_id = data .get ("service_id" ),
615
619
want_reminder = want_reminder ,
616
- additional_info = data .get ("additional_info" )
620
+ additional_info = data .get ("additional_info" ),
621
+ request = request ,
617
622
)
618
623
appointments_json = convert_appointment_to_json (request , [appt ])[0 ]
619
624
return json_response (appt_updated_successfully , custom_data = {'appt' : appointments_json })
0 commit comments