From 137fda461e981cedee2d87dd3f0363ec311d364e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 21 Mar 2023 16:54:02 +0100 Subject: [PATCH] [IMP]pms: avoid contrains availability_id, by validation error in compute --- pms/models/pms_availability.py | 4 +++- pms/models/pms_reservation_line.py | 16 ++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pms/models/pms_availability.py b/pms/models/pms_availability.py index 7bce58b8d..3ed1d6cf9 100644 --- a/pms/models/pms_availability.py +++ b/pms/models/pms_availability.py @@ -105,7 +105,9 @@ class PmsAvailability(models.Model): ("pms_property_id", "=", record.pms_property_id.id), ] ) - room_ids = record.room_type_id.mapped("room_ids.id") + room_ids = record.room_type_id.room_ids.filtered( + lambda r: r.pms_property_id == record.pms_property_id + ).ids count_rooms_not_avail = len( record.get_rooms_not_avail( checkin=record.date, diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index a2bef0ef4..01a216cd7 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -136,15 +136,6 @@ class PmsReservationLine(models.Model): ondelete="restrict", ) - _sql_constraints = [ - ( - "rule_availability", - "EXCLUDE (room_id WITH =, date WITH =) \ - WHERE (occupies_availability = True)", - "Room Occupied", - ), - ] - def name_get(self): result = [] for res in self: @@ -242,7 +233,7 @@ class PmsReservationLine(models.Model): # if the preferred room is NOT available else: if self.env.context.get("force_overbooking"): - reservation.overbooking = True + line.overbooking = True line.room_id = reservation.preferred_room_id else: raise ValidationError( @@ -426,6 +417,11 @@ class PmsReservationLine(models.Model): ] ) if avail: + if not avail.real_avail and record.occupies_availability: + raise ValidationError( + _("There is no availability for the room type %s on %s") + % (record.room_id.room_type_id.name, record.date) + ) record.avail_id = avail.id else: record.avail_id = self.env["pms.availability"].create(