mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: improvements availability compute
This commit is contained in:
@@ -151,16 +151,20 @@ class PmsProperty(models.Model):
|
||||
@api.depends_context(
|
||||
"checkin",
|
||||
"checkout",
|
||||
"real_avail",
|
||||
"room_type_id",
|
||||
"ubication_id",
|
||||
"capacity",
|
||||
"amenity_ids",
|
||||
"pricelist_id",
|
||||
"class_id",
|
||||
"overnight_rooms",
|
||||
"current_lines",
|
||||
)
|
||||
def _compute_free_room_ids(self):
|
||||
checkin = self._context["checkin"]
|
||||
checkout = self._context["checkout"]
|
||||
|
||||
if isinstance(checkin, str):
|
||||
checkin = datetime.datetime.strptime(
|
||||
checkin, DEFAULT_SERVER_DATE_FORMAT
|
||||
@@ -175,11 +179,14 @@ class PmsProperty(models.Model):
|
||||
|
||||
pricelist_id = self.env.context.get("pricelist_id", False)
|
||||
room_type_id = self.env.context.get("room_type_id", False)
|
||||
class_id = self._context.get("class_id", False)
|
||||
real_avail = self._context.get("real_avail", False)
|
||||
overnight_rooms = self._context.get("overnight_rooms", False)
|
||||
for pms_property in self:
|
||||
free_rooms = pms_property.get_real_free_rooms(
|
||||
checkin, checkout, current_lines
|
||||
)
|
||||
if pricelist_id:
|
||||
if pricelist_id and not real_avail:
|
||||
# TODO: only closed_departure take account checkout date!
|
||||
domain_rules = [
|
||||
("date", ">=", checkin),
|
||||
@@ -208,6 +215,14 @@ class PmsProperty(models.Model):
|
||||
free_rooms = free_rooms.filtered(
|
||||
lambda x: x.room_type_id.id not in room_types_to_remove
|
||||
)
|
||||
if class_id:
|
||||
free_rooms = free_rooms.filtered(
|
||||
lambda x: x.room_type_id.class_id.id == class_id
|
||||
)
|
||||
if overnight_rooms:
|
||||
free_rooms = free_rooms.filtered(
|
||||
lambda x: x.room_type_id.overnight_room
|
||||
)
|
||||
if len(free_rooms) > 0:
|
||||
pms_property.free_room_ids = free_rooms.ids
|
||||
else:
|
||||
@@ -261,11 +276,14 @@ class PmsProperty(models.Model):
|
||||
@api.depends_context(
|
||||
"checkin",
|
||||
"checkout",
|
||||
"real_avail",
|
||||
"room_type_id",
|
||||
"ubication_id",
|
||||
"capacity",
|
||||
"amenity_ids",
|
||||
"pricelist_id",
|
||||
"class_id",
|
||||
"overnight_rooms",
|
||||
"current_lines",
|
||||
)
|
||||
def _compute_availability(self):
|
||||
@@ -283,12 +301,18 @@ class PmsProperty(models.Model):
|
||||
room_type_id = self.env.context.get("room_type_id", False)
|
||||
pricelist_id = self.env.context.get("pricelist_id", False)
|
||||
current_lines = self.env.context.get("current_lines", [])
|
||||
class_id = self._context.get("class_id", False)
|
||||
real_avail = self._context.get("real_avail", False)
|
||||
overnight_rooms = self._context.get("overnight_rooms", False)
|
||||
pms_property = record.with_context(
|
||||
checkin=checkin,
|
||||
checkout=checkout,
|
||||
room_type_id=room_type_id,
|
||||
current_lines=current_lines,
|
||||
pricelist_id=pricelist_id,
|
||||
class_id=class_id,
|
||||
real_avail=real_avail,
|
||||
overnight_rooms=overnight_rooms,
|
||||
)
|
||||
count_free_rooms = len(pms_property.free_room_ids)
|
||||
if current_lines and not isinstance(current_lines, list):
|
||||
@@ -305,7 +329,7 @@ class PmsProperty(models.Model):
|
||||
pricelist = False
|
||||
if pricelist_id:
|
||||
pricelist = self.env["product.pricelist"].browse(pricelist_id)
|
||||
if pricelist and pricelist.availability_plan_id:
|
||||
if pricelist and pricelist.availability_plan_id and not real_avail:
|
||||
domain_rules.append(
|
||||
("availability_plan_id", "=", pricelist.availability_plan_id.id)
|
||||
)
|
||||
|
||||
@@ -643,7 +643,6 @@ class PmsReservation(models.Model):
|
||||
comodel_name="res.partner",
|
||||
inverse_name="reservation_possible_customer_id",
|
||||
)
|
||||
|
||||
is_mail_send = fields.Boolean(string="Mail Sent", default=False)
|
||||
|
||||
is_modified_reservation = fields.Boolean(
|
||||
@@ -652,7 +651,10 @@ class PmsReservation(models.Model):
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
|
||||
overnight_room = fields.Boolean(
|
||||
related="room_type_id.overnight_room",
|
||||
store=True,
|
||||
)
|
||||
lang = fields.Many2one(
|
||||
string="Language", comodel_name="res.lang", compute="_compute_lang"
|
||||
)
|
||||
@@ -804,6 +806,7 @@ class PmsReservation(models.Model):
|
||||
"reservation_line_ids.room_id",
|
||||
"reservation_line_ids.occupies_availability",
|
||||
"preferred_room_id",
|
||||
"room_type_id",
|
||||
"pricelist_id",
|
||||
"pms_property_id",
|
||||
)
|
||||
@@ -812,7 +815,9 @@ class PmsReservation(models.Model):
|
||||
if reservation.checkin and reservation.checkout:
|
||||
if reservation.overbooking or reservation.state in ("cancel"):
|
||||
reservation.allowed_room_ids = self.env["pms.room"].search(
|
||||
[("active", "=", True)]
|
||||
[
|
||||
("active", "=", True),
|
||||
]
|
||||
)
|
||||
return
|
||||
pms_property = reservation.pms_property_id
|
||||
@@ -822,9 +827,12 @@ class PmsReservation(models.Model):
|
||||
room_type_id=False, # Allows to choose any available room
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
pricelist_id=reservation.pricelist_id.id,
|
||||
class_id=reservation.room_type_id.class_id
|
||||
if reservation.room_type_id
|
||||
else False,
|
||||
real_avail=True,
|
||||
)
|
||||
reservation.allowed_room_ids = pms_property.free_room_ids
|
||||
|
||||
else:
|
||||
reservation.allowed_room_ids = False
|
||||
|
||||
@@ -1045,6 +1053,7 @@ class PmsReservation(models.Model):
|
||||
True
|
||||
if (
|
||||
record.reservation_type != "out"
|
||||
and record.overnight_room
|
||||
and record.state in ["draft", "confirm", "arrival_delayed"]
|
||||
and record.checkin <= fields.Date.today()
|
||||
)
|
||||
@@ -1197,9 +1206,11 @@ class PmsReservation(models.Model):
|
||||
reservation.commission_amount = 0
|
||||
|
||||
# REVIEW: Dont run with set room_type_id -> room_id(compute)-> No set adults¿?
|
||||
@api.depends("preferred_room_id", "reservation_type")
|
||||
@api.depends("preferred_room_id", "reservation_type", "overnight_room")
|
||||
def _compute_adults(self):
|
||||
for reservation in self:
|
||||
if not reservation.overnight_room:
|
||||
reservation.adults = 0
|
||||
if reservation.preferred_room_id and reservation.reservation_type != "out":
|
||||
if reservation.adults == 0:
|
||||
reservation.adults = reservation.preferred_room_id.capacity
|
||||
@@ -1384,7 +1395,7 @@ class PmsReservation(models.Model):
|
||||
|
||||
def _compute_checkin_partner_count(self):
|
||||
for record in self:
|
||||
if record.reservation_type != "out":
|
||||
if record.reservation_type != "out" and record.overnight_room:
|
||||
record.checkin_partner_count = len(record.checkin_partner_ids)
|
||||
record.checkin_partner_pending_count = record.adults - len(
|
||||
record.checkin_partner_ids
|
||||
@@ -1488,6 +1499,7 @@ class PmsReservation(models.Model):
|
||||
return [
|
||||
("state", "in", ("draft", "confirm", "arrival_delayed")),
|
||||
("checkin", "<=", today),
|
||||
("adults", ">", 0),
|
||||
]
|
||||
|
||||
def _search_allowed_checkout(self, operator, value):
|
||||
@@ -1505,6 +1517,7 @@ class PmsReservation(models.Model):
|
||||
return [
|
||||
("state", "in", ("onboard", "departure_delayed")),
|
||||
("checkout", ">=", today),
|
||||
("adults", ">", 0),
|
||||
]
|
||||
|
||||
def _search_allowed_cancel(self, operator, value):
|
||||
@@ -2014,7 +2027,9 @@ class PmsReservation(models.Model):
|
||||
("checkin", "<", fields.Date.today()),
|
||||
]
|
||||
)
|
||||
arrival_delayed_reservations.state = "arrival_delayed"
|
||||
for record in arrival_delayed_reservations:
|
||||
if record.overnight_room:
|
||||
record.state = "arrival_delayed"
|
||||
|
||||
@api.model
|
||||
def auto_departure_delayed(self):
|
||||
@@ -2026,8 +2041,11 @@ class PmsReservation(models.Model):
|
||||
]
|
||||
)
|
||||
for reservation in reservations:
|
||||
if reservation.checkout_datetime <= fields.Datetime.now():
|
||||
reservations.state = "departure_delayed"
|
||||
if reservation.overnight_room:
|
||||
if reservation.checkout_datetime <= fields.Datetime.now():
|
||||
reservations.state = "departure_delayed"
|
||||
else:
|
||||
reservation.state = "done"
|
||||
|
||||
def preview_reservation(self):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -112,7 +112,10 @@ class PmsReservationLine(models.Model):
|
||||
store=True,
|
||||
compute="_compute_impacts_quota",
|
||||
)
|
||||
|
||||
overnight_room = fields.Boolean(
|
||||
related="reservation_id.overnight_room",
|
||||
store=True,
|
||||
)
|
||||
_sql_constraints = [
|
||||
(
|
||||
"rule_availability",
|
||||
@@ -184,6 +187,7 @@ class PmsReservationLine(models.Model):
|
||||
else False,
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
pricelist_id=reservation.pricelist_id.id,
|
||||
real_avail=True,
|
||||
)
|
||||
rooms_available = pms_property.free_room_ids
|
||||
|
||||
|
||||
@@ -86,6 +86,10 @@ class PmsRoomType(models.Model):
|
||||
"Use `-1` for managing no quota.",
|
||||
default=-1,
|
||||
)
|
||||
overnight_room = fields.Boolean(
|
||||
related="class_id.overnight",
|
||||
store=True,
|
||||
)
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
|
||||
@@ -57,6 +57,11 @@ class PmsRoomTypeClass(models.Model):
|
||||
help="Room type class identification code",
|
||||
required=True,
|
||||
)
|
||||
overnight = fields.Boolean(
|
||||
string="Use for overnight stays",
|
||||
help="Set False if if these types of spaces are not used for overnight stays",
|
||||
default=True,
|
||||
)
|
||||
|
||||
@api.model
|
||||
def get_unique_by_property_code(self, pms_property_id, default_code=None):
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
/>
|
||||
<field name="name" />
|
||||
<field name="default_code" />
|
||||
<field name="overnight" />
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="2">
|
||||
|
||||
@@ -179,6 +179,7 @@ class ReservationSplitJoinSwapWizard(models.TransientModel):
|
||||
room_type_id=False, # Allows to choose any available room
|
||||
current_lines=record.reservation_id.reservation_line_ids.ids,
|
||||
pricelist_id=record.reservation_id.pricelist_id.id,
|
||||
real_avail=True,
|
||||
)
|
||||
rooms_available = pms_property.free_room_ids
|
||||
|
||||
@@ -224,6 +225,8 @@ class ReservationSplitJoinSwapWizard(models.TransientModel):
|
||||
).date(),
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
pricelist_id=reservation.pricelist_id.id,
|
||||
real_avail=True,
|
||||
class_id=reservation.room_type_id.class_id,
|
||||
)
|
||||
rooms_available = pms_property.free_room_ids
|
||||
|
||||
@@ -242,6 +245,7 @@ class ReservationSplitJoinSwapWizard(models.TransientModel):
|
||||
checkout=reservation.checkout,
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
pricelist_id=reservation.pricelist_id.id,
|
||||
real_avail=True,
|
||||
)
|
||||
rooms_available = pms_property.free_room_ids
|
||||
|
||||
@@ -360,6 +364,8 @@ class ReservationLinesToSplit(models.TransientModel):
|
||||
checkout=line.date + datetime.timedelta(days=1),
|
||||
room_type_id=False, # Allows to choose any available room
|
||||
pricelist_id=reservation.pricelist_id.id,
|
||||
real_avail=True,
|
||||
class_id=reservation.room_type_id.class_id,
|
||||
)
|
||||
rooms_available = pms_property.free_room_ids
|
||||
rooms_available += line.room_id
|
||||
|
||||
Reference in New Issue
Block a user