mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: add capacity in compute_availability on pms_property and new field count_alternative_free_rooms in pms_reservation
This commit is contained in:
committed by
Darío Lodeiros
parent
b11d2a8542
commit
66a764c343
@@ -272,6 +272,7 @@ class PmsProperty(models.Model):
|
||||
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
|
||||
@@ -313,6 +314,10 @@ class PmsProperty(models.Model):
|
||||
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:
|
||||
@@ -398,6 +403,7 @@ class PmsProperty(models.Model):
|
||||
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,
|
||||
@@ -407,6 +413,7 @@ class PmsProperty(models.Model):
|
||||
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):
|
||||
|
||||
@@ -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:
|
||||
@@ -1698,6 +1701,19 @@ class PmsReservation(models.Model):
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user