diff --git a/addons/dine360_reservation/controllers/__pycache__/main.cpython-310.pyc b/addons/dine360_reservation/controllers/__pycache__/main.cpython-310.pyc index 1cfab85..6522f02 100644 Binary files a/addons/dine360_reservation/controllers/__pycache__/main.cpython-310.pyc and b/addons/dine360_reservation/controllers/__pycache__/main.cpython-310.pyc differ diff --git a/addons/dine360_reservation/controllers/main.py b/addons/dine360_reservation/controllers/main.py index b6b1ee0..8d5888d 100644 --- a/addons/dine360_reservation/controllers/main.py +++ b/addons/dine360_reservation/controllers/main.py @@ -1,6 +1,7 @@ from odoo import http, _ from odoo.http import request import datetime +import pytz class TableReservationController(http.Controller): @@ -24,8 +25,14 @@ class TableReservationController(http.Controller): start_time_str = post.get('start_time') # Format: 2024-05-20T18:00 num_people = int(post.get('num_people', 1)) - # Convert start_time to datetime object - start_time = datetime.datetime.strptime(start_time_str, '%Y-%m-%dT%H:%M') + # Convert start_time to datetime object and localize to restaurant timezone (Brampton) + restaurant_tz = pytz.timezone('America/Toronto') + local_start = datetime.datetime.strptime(start_time_str, '%Y-%m-%dT%H:%M') + local_start = restaurant_tz.localize(local_start) + + # Convert to UTC for Odoo + start_time = local_start.astimezone(pytz.utc).replace(tzinfo=None) + # Standard duration of 1 hour for now end_time = start_time + datetime.timedelta(hours=1) diff --git a/addons/dine360_reservation/models/__pycache__/restaurant_reservation.cpython-310.pyc b/addons/dine360_reservation/models/__pycache__/restaurant_reservation.cpython-310.pyc index 13e366a..63babc5 100644 Binary files a/addons/dine360_reservation/models/__pycache__/restaurant_reservation.cpython-310.pyc and b/addons/dine360_reservation/models/__pycache__/restaurant_reservation.cpython-310.pyc differ diff --git a/addons/dine360_reservation/models/restaurant_reservation.py b/addons/dine360_reservation/models/restaurant_reservation.py index 75049aa..a760419 100644 --- a/addons/dine360_reservation/models/restaurant_reservation.py +++ b/addons/dine360_reservation/models/restaurant_reservation.py @@ -1,6 +1,7 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError from datetime import timedelta +import pytz class RestaurantReservation(models.Model): _name = 'restaurant.reservation' @@ -23,8 +24,8 @@ class RestaurantReservation(models.Model): def _compute_whatsapp_url(self): for rec in self: - if rec.phone: - msg = f"Hello {rec.customer_name}, your reservation {rec.name} for {rec.start_time.strftime('%I:%M %p')} is confirmed!" + if rec.phone and rec.customer_name and rec.start_time: + msg = f"Hello {rec.customer_name}, your reservation {rec.name or ''} for {rec.start_time.strftime('%I:%M %p')} is confirmed!" rec.whatsapp_url = f"https://wa.me/{rec.phone}?text={msg.replace(' ', '%20')}" else: rec.whatsapp_url = False @@ -56,6 +57,24 @@ class RestaurantReservation(models.Model): if overlap: raise ValidationError(_('This table is already reserved for the selected time slot.')) + @api.constrains('start_time', 'end_time') + def _check_opening_hours(self): + restaurant_tz = pytz.timezone('America/Toronto') + for rec in self: + local_start = pytz.utc.localize(rec.start_time).astimezone(restaurant_tz) + local_end = pytz.utc.localize(rec.end_time).astimezone(restaurant_tz) + + day = local_start.weekday() # 0=Mon, 6=Sun + time_start = local_start.hour + local_start.minute / 60.0 + time_end = local_end.hour + local_end.minute / 60.0 + + if day in [6, 0, 1, 2, 3]: # Sun-Thu + if time_start < 12.0 or time_end > 21.0: + raise ValidationError(_('Reservations for Sunday - Thursday must be between 12:00 PM and 9:00 PM (Local Time).')) + else: # Fri-Sat + if time_start < 12.0 or time_end > 23.0: + raise ValidationError(_('Reservations for Friday & Saturday must be between 12:00 PM and 11:00 PM (Local Time).')) + @api.onchange('start_time') def _onchange_start_time(self): if self.start_time: diff --git a/addons/dine360_reservation/views/reservation_templates.xml b/addons/dine360_reservation/views/reservation_templates.xml index 7c96086..8d3c4f4 100644 --- a/addons/dine360_reservation/views/reservation_templates.xml +++ b/addons/dine360_reservation/views/reservation_templates.xml @@ -11,7 +11,10 @@

Table Reservation

-

Book your spot for an authentic South Indian dining experience.

+

Book your spot for an authentic South Indian dining experience.

+
+ Sun - Thu: 12pm - 9pm | Fri & Sat: 12pm - 11pm +
@@ -20,7 +23,7 @@
-
+