[IMP]pms: avoid contrains availability_id, by validation error in compute

This commit is contained in:
Darío Lodeiros
2023-03-21 16:54:02 +01:00
parent ef7c48a4f6
commit 137fda461e
2 changed files with 9 additions and 11 deletions

View File

@@ -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,

View File

@@ -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(