mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: avoid contrains availability_id, by validation error in compute
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user