From a63f866e6a0b9af78751c56d7bdde8cd8ea22f2e Mon Sep 17 00:00:00 2001 From: braisab Date: Fri, 29 Apr 2022 17:36:21 +0200 Subject: [PATCH] [IMP]pms: added overbooking field and compute in reservation line --- pms/models/pms_reservation_line.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index febbc741a..ba348384d 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -113,6 +113,13 @@ class PmsReservationLine(models.Model): related="reservation_id.overnight_room", store=True, ) + overbooking = fields.Boolean( + string="Overbooking", + help="Indicate if exists overbooking in the reservation line", + store=True, + readonly=False, + compute="_compute_overbooking", + ) _sql_constraints = [ ( "rule_availability", @@ -469,6 +476,28 @@ class PmsReservationLine(models.Model): else: record.avail_id = False + @api.depends("reservation_id.overbooking") + def _compute_overbooking(self): + for record in self: + if record.reservation_id.overbooking: + real_avail = ( + self.env["pms.availability"] + .search( + [ + ("room_type_id", "=", record.room_id.room_type_id.id), + ("date", "=", record.date), + ("pms_property_id", "=", record.pms_property_id.id), + ] + ) + .real_avail + ) + if real_avail == 0: + record.overbooking = True + else: + record.overbooking = False + else: + record.overbooking = False + # Constraints and onchanges @api.constrains("date") def constrains_duplicated_date(self):