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),
|
("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(
|
count_rooms_not_avail = len(
|
||||||
record.get_rooms_not_avail(
|
record.get_rooms_not_avail(
|
||||||
checkin=record.date,
|
checkin=record.date,
|
||||||
|
|||||||
@@ -136,15 +136,6 @@ class PmsReservationLine(models.Model):
|
|||||||
ondelete="restrict",
|
ondelete="restrict",
|
||||||
)
|
)
|
||||||
|
|
||||||
_sql_constraints = [
|
|
||||||
(
|
|
||||||
"rule_availability",
|
|
||||||
"EXCLUDE (room_id WITH =, date WITH =) \
|
|
||||||
WHERE (occupies_availability = True)",
|
|
||||||
"Room Occupied",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
result = []
|
result = []
|
||||||
for res in self:
|
for res in self:
|
||||||
@@ -242,7 +233,7 @@ class PmsReservationLine(models.Model):
|
|||||||
# if the preferred room is NOT available
|
# if the preferred room is NOT available
|
||||||
else:
|
else:
|
||||||
if self.env.context.get("force_overbooking"):
|
if self.env.context.get("force_overbooking"):
|
||||||
reservation.overbooking = True
|
line.overbooking = True
|
||||||
line.room_id = reservation.preferred_room_id
|
line.room_id = reservation.preferred_room_id
|
||||||
else:
|
else:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
@@ -426,6 +417,11 @@ class PmsReservationLine(models.Model):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
if avail:
|
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
|
record.avail_id = avail.id
|
||||||
else:
|
else:
|
||||||
record.avail_id = self.env["pms.availability"].create(
|
record.avail_id = self.env["pms.availability"].create(
|
||||||
|
|||||||
Reference in New Issue
Block a user