Browse Source

[ADD] booking overlap setting

14.0
Rémi FRANÇOIS 4 years ago
parent
commit
ef11973162
  1. 1
      pos_restaurant_table_booking/models/res_config_settings.py
  2. 11
      pos_restaurant_table_booking/models/restaurant_booking.py
  3. 10
      pos_restaurant_table_booking/views/res_config_settings.xml

1
pos_restaurant_table_booking/models/res_config_settings.py

@ -6,6 +6,7 @@ class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings' _inherit = 'res.config.settings'
default_duration = fields.Float(string="Default duration", default_model='restaurant.booking') 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 = [ _sql_constraints = [
('duration_positive', 'CHECK(default_duration >= 0)', "The default booking duration must be positive or null.") ('duration_positive', 'CHECK(default_duration >= 0)', "The default booking duration must be positive or null.")

11
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_start = fields.Datetime(string="Date start", compute="_get_datetimes", store=True)
datetime_stop = fields.Datetime(string="Date stop", 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) 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", available_table_ids = fields.Many2many(comodel_name='restaurant.table', string="Available tables",
column1="booking_id", column2="table_id", relation="booking_available_table_rel", column1="booking_id", column2="table_id", relation="booking_available_table_rel",
compute="_get_available_tables") compute="_get_available_tables")
@ -101,22 +102,22 @@ class RestaurantBooking(models.Model):
for booking in self: for booking in self:
booking.table_capacity_ok = bool(booking.table_capacity >= booking.count) 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): def _get_available_tables(self):
Table = self.env['restaurant.table'] Table = self.env['restaurant.table']
TableBooking = self.env['restaurant.table_booking'] TableBooking = self.env['restaurant.table_booking']
for booking in self: for booking in self:
if booking.datetime_start and booking.datetime_stop: if booking.datetime_start and booking.datetime_stop:
domain = [('bookable', '=', True)]
if not self.can_overlap:
tbookings = TableBooking.search([ tbookings = TableBooking.search([
'|', '&', ('datetime_start', '<', booking.datetime_stop), '|', '&', ('datetime_start', '<', booking.datetime_stop),
('datetime_start', '>=', booking.datetime_start), ('datetime_start', '>=', booking.datetime_start),
'&', ('datetime_stop', '>', booking.datetime_start), '&', ('datetime_stop', '>', booking.datetime_start),
('datetime_stop', '<=', booking.datetime_stop) ('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.append(('id', 'not in', tbookings.mapped('table_id').ids))
booking.available_table_ids = Table.search(domain)
else: else:
booking.available_table_ids = [(5, 0, 0)] booking.available_table_ids = [(5, 0, 0)]

10
pos_restaurant_table_booking/views/res_config_settings.xml

@ -19,6 +19,16 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-12 col-lg-6 o_setting_box" id="default_duration_setting" title="This duration is applied to any new booking created in the point of sale.">
<div class="o_setting_right_pane">
<div>
<label for="default_can_overlap"/>
<div class="content-group mt16">
<field name="default_can_overlap" colspan="4" nolabel="1"/>
</div>
</div>
</div>
</div>
</div> </div>
</xpath> </xpath>
</field> </field>

Loading…
Cancel
Save