Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix booking (with close_dinner after 00) #158

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 52 additions & 20 deletions monolith/services/booking_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class BookingServices:
def book(restaurant_id, current_user, py_datetime, people_number, raw_friends):

# split friends mail and check if the number is correct
splitted_friends = raw_friends.split(";")
if len(splitted_friends) != (people_number - 1):
return (None, "You need to specify ONE mail for each person")
if people_number > 1:
splitted_friends = raw_friends.split(";")
if len(splitted_friends) != (people_number - 1):
return (None, "You need to specify ONE mail for each person")

restaurant_id = int(restaurant_id)
#
Expand Down Expand Up @@ -59,11 +60,27 @@ def book(restaurant_id, current_user, py_datetime, people_number, raw_friends):
return (None, "The restaurant is closed")

# if the resturant is open only at lunch or at dinner do some checks..
if (opening_hour.open_lunch is None or opening_hour.close_lunch is None) and (
only_time < opening_hour.open_dinner
or only_time > opening_hour.close_dinner
):
return (None, "The restaurant is closed")
if opening_hour.open_lunch is None or opening_hour.close_lunch is None:
# calc the projection (py_datetime.date combined with opening hour)

open_dinner_projection = datetime.datetime.combine(
py_datetime.date(), opening_hour.open_dinner
)
if opening_hour.close_dinner < opening_hour.open_dinner:
close_dinner_projection = datetime.datetime.combine(
py_datetime.date() + datetime.timedelta(days=1),
opening_hour.close_dinner,
)
else:
close_dinner_projection = datetime.datetime.combine(
py_datetime.date(), opening_hour.close_dinner
)

if (
py_datetime > close_dinner_projection
or py_datetime < open_dinner_projection
):
return (None, "The restaurant is closed")

if (opening_hour.open_dinner is None or opening_hour.close_dinner is None) and (
only_time < opening_hour.open_lunch or only_time > opening_hour.close_lunch
Expand All @@ -74,16 +91,30 @@ def book(restaurant_id, current_user, py_datetime, people_number, raw_friends):
# if the resturant is opened both at dinner and lunch
if opening_hour.open_lunch is not None and opening_hour.open_dinner is not None:
# asked for some hours outside the opening hours
if opening_hour.open_lunch > only_time:
return (None, "The restaurant is closed")
if only_time < opening_hour.open_lunch:
if opening_hour.close_dinner < opening_hour.open_dinner:
if only_time > opening_hour.close_dinner:
return (None, "The restaurant is closed")
else:
return (None, "The restaurant is closed")

if (
opening_hour.open_dinner > only_time
and opening_hour.close_lunch < only_time
only_time < opening_hour.open_dinner
and only_time > opening_hour.close_lunch
):
return (None, "The restaurant is closed")

if opening_hour.close_dinner < only_time:
if opening_hour.close_dinner < opening_hour.open_dinner:
close_dinner_projection = datetime.datetime.combine(
py_datetime.date() + datetime.timedelta(days=1),
opening_hour.close_dinner,
)
else:
close_dinner_projection = datetime.datetime.combine(
py_datetime.date(), opening_hour.close_dinner
)

if py_datetime > close_dinner_projection:
return (None, "The restaurant is closed")
#

Expand Down Expand Up @@ -167,14 +198,15 @@ def book(restaurant_id, current_user, py_datetime, people_number, raw_friends):
db.session.add(new_reservation)
db.session.flush()

# register friends
for friend_mail in splitted_friends:
new_friend = Friend()
new_friend.reservation_id = new_reservation.id
new_friend.email = friend_mail.strip()
db.session.add(new_friend)
if people_number > 1:
# register friends
for friend_mail in splitted_friends:
new_friend = Friend()
new_friend.reservation_id = new_reservation.id
new_friend.email = friend_mail.strip()
db.session.add(new_friend)

db.session.commit()
db.session.commit()
return (new_reservation, restaurant_name, table_name)
else:
return (None, "no tables available")
Expand Down
8 changes: 0 additions & 8 deletions monolith/views/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ def index():
)
people_number = int(request.form.get("people_number"))

# check on friends mail
if request.form.get("friends") is None or request.form.get("friends") == "":
return render_template(
"booking.html",
success=False,
error="You have to specify your friends emails",
)

# check on restaurant_id (hidden field)
if (
request.form.get("restaurant_id") is None
Expand Down