Skip to content

Commit

Permalink
[IMP] pms: add capacity in compute_availability on pms_property and n…
Browse files Browse the repository at this point in the history
…ew field count_alternative_free_rooms in pms_reservation
  • Loading branch information
saralb9 authored and DarioLodeiros committed Feb 7, 2024
1 parent b11d2a8 commit 66a764c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pms/models/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def _compute_free_room_ids(self):
class_id = self._context.get("class_id", False)
real_avail = self._context.get("real_avail", False)
overnight_rooms = self._context.get("overnight_rooms", False)
capacity = self._context.get("capacity", False)
for pms_property in self:
free_rooms = pms_property.get_real_free_rooms(
checkin, checkout, current_lines
Expand Down Expand Up @@ -313,6 +314,10 @@ def _compute_free_room_ids(self):
free_rooms = free_rooms.filtered(
lambda x: x.room_type_id.overnight_room
)
if capacity:
free_rooms = free_rooms.filtered(
lambda x: x.capacity >= capacity
)
if len(free_rooms) > 0:
pms_property.free_room_ids = free_rooms.ids
else:
Expand Down Expand Up @@ -398,6 +403,7 @@ def _compute_availability(self):
class_id = self._context.get("class_id", False)
real_avail = self._context.get("real_avail", False)
overnight_rooms = self._context.get("overnight_rooms", False)
capacity = self._context.get("capacity", False)
pms_property = record.with_context(
checkin=checkin,
checkout=checkout,
Expand All @@ -407,6 +413,7 @@ def _compute_availability(self):
class_id=class_id,
real_avail=real_avail,
overnight_rooms=overnight_rooms,
capacity=capacity,
)
count_free_rooms = len(pms_property.free_room_ids)
if current_lines and not isinstance(current_lines, list):
Expand Down
18 changes: 17 additions & 1 deletion pms/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,10 @@ class PmsReservation(models.Model):
store=True,
readonly=False,
)

count_alternative_free_rooms = fields.Integer(
string="Count alternative free rooms",
compute="_compute_count_alternative_free_rooms",
)
@api.depends("folio_id", "folio_id.external_reference")
def _compute_external_reference(self):
for reservation in self:
Expand Down Expand Up @@ -1698,6 +1701,19 @@ def _compute_is_reselling(self):
else:
record.is_reselling = False

@api.depends("reservation_line_ids")
def _compute_count_alternative_free_rooms(self):
for record in self:
record.count_alternative_free_rooms = record.pms_property_id.with_context(
checkin=record.checkin,
checkout=record.checkout,
real_avail=True,
capacity=record.adults,
class_id=record.room_type_id.class_id.id,
current_lines=record.reservation_line_ids.ids,
).availability


def _search_allowed_checkin(self, operator, value):
if operator not in ("=",):
raise UserError(
Expand Down

0 comments on commit 66a764c

Please sign in to comment.