diff --git a/pos_restaurant_table_booking/models/res_config_settings.py b/pos_restaurant_table_booking/models/res_config_settings.py index 9d5f886..c587c3a 100644 --- a/pos_restaurant_table_booking/models/res_config_settings.py +++ b/pos_restaurant_table_booking/models/res_config_settings.py @@ -6,6 +6,7 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' default_duration = fields.Float(string="Default duration", default_model='restaurant.booking') + default_can_overlap = fields.Boolean(string="Table bookings can overlap", default_model='restaurant.booking', default=False) _sql_constraints = [ ('duration_positive', 'CHECK(default_duration >= 0)', "The default booking duration must be positive or null.") diff --git a/pos_restaurant_table_booking/models/restaurant_booking.py b/pos_restaurant_table_booking/models/restaurant_booking.py index 04ef2eb..00e2150 100644 --- a/pos_restaurant_table_booking/models/restaurant_booking.py +++ b/pos_restaurant_table_booking/models/restaurant_booking.py @@ -43,6 +43,7 @@ class RestaurantBooking(models.Model): datetime_start = fields.Datetime(string="Date start", compute="_get_datetimes", store=True) datetime_stop = fields.Datetime(string="Date stop", compute="_get_datetimes", store=True) count = fields.Integer(string="People count", required=True) + can_overlap = fields.Boolean(string="Table bookings can overlap") available_table_ids = fields.Many2many(comodel_name='restaurant.table', string="Available tables", column1="booking_id", column2="table_id", relation="booking_available_table_rel", compute="_get_available_tables") @@ -101,22 +102,22 @@ class RestaurantBooking(models.Model): for booking in self: booking.table_capacity_ok = bool(booking.table_capacity >= booking.count) - @api.depends('datetime_start', 'datetime_stop', 'table_ids') + @api.depends('datetime_start', 'datetime_stop', 'can_overlap') def _get_available_tables(self): Table = self.env['restaurant.table'] TableBooking = self.env['restaurant.table_booking'] for booking in self: if booking.datetime_start and booking.datetime_stop: - tbookings = TableBooking.search([ - '|', '&', ('datetime_start', '<', booking.datetime_stop), - ('datetime_start', '>=', booking.datetime_start), - '&', ('datetime_stop', '>', booking.datetime_start), - ('datetime_stop', '<=', booking.datetime_stop) - ]) - booking.available_table_ids = Table.search([ - ('bookable', '=', True), - ('id', 'not in', tbookings.mapped('table_id').ids), - ]) - booking.table_ids + domain = [('bookable', '=', True)] + if not self.can_overlap: + tbookings = TableBooking.search([ + '|', '&', ('datetime_start', '<', booking.datetime_stop), + ('datetime_start', '>=', booking.datetime_start), + '&', ('datetime_stop', '>', booking.datetime_start), + ('datetime_stop', '<=', booking.datetime_stop) + ]) + domain.append(('id', 'not in', tbookings.mapped('table_id').ids)) + booking.available_table_ids = Table.search(domain) else: booking.available_table_ids = [(5, 0, 0)] diff --git a/pos_restaurant_table_booking/views/res_config_settings.xml b/pos_restaurant_table_booking/views/res_config_settings.xml index c72138d..1c3c9f2 100644 --- a/pos_restaurant_table_booking/views/res_config_settings.xml +++ b/pos_restaurant_table_booking/views/res_config_settings.xml @@ -19,6 +19,16 @@ +
+
+
+
+
+