mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[RFC] Booking Engine (#89)
This commit is contained in:
@@ -214,7 +214,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
|
|
||||||
# force pricelist load
|
# force pricelist load
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -295,7 +294,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -366,7 +364,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
# }
|
# }
|
||||||
# )
|
# )
|
||||||
# wizard_folio.flush()
|
# wizard_folio.flush()
|
||||||
# wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# # availability items belonging to test property
|
# # availability items belonging to test property
|
||||||
# lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
# lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -426,7 +423,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -476,7 +472,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -528,7 +523,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -586,7 +580,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
@@ -657,7 +650,6 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard_folio.flush()
|
wizard_folio.flush()
|
||||||
wizard_folio.availability_results._compute_dynamic_selection()
|
|
||||||
|
|
||||||
# availability items belonging to test property
|
# availability items belonging to test property
|
||||||
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
lines_availability_test = self.env["pms.folio.availability.wizard"].search(
|
||||||
|
|||||||
@@ -115,7 +115,6 @@ class FolioWizard(models.TransientModel):
|
|||||||
"pricelist_id",
|
"pricelist_id",
|
||||||
)
|
)
|
||||||
def _compute_availability_results(self):
|
def _compute_availability_results(self):
|
||||||
|
|
||||||
for record in self:
|
for record in self:
|
||||||
record.availability_results = False
|
record.availability_results = False
|
||||||
|
|
||||||
|
|||||||
@@ -40,24 +40,26 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
compute="_compute_num_rooms_available",
|
compute="_compute_num_rooms_available",
|
||||||
store="true",
|
store="true",
|
||||||
)
|
)
|
||||||
price_per_room = fields.Float(
|
|
||||||
string="Price per room",
|
|
||||||
default=0,
|
|
||||||
)
|
|
||||||
num_rooms_selected = fields.Many2one(
|
num_rooms_selected = fields.Many2one(
|
||||||
comodel_name="pms.num.rooms.selection",
|
comodel_name="pms.num.rooms.selection",
|
||||||
inverse_name="folio_wizard_id",
|
inverse_name="folio_wizard_id",
|
||||||
string="Selected rooms",
|
string="Selected rooms",
|
||||||
compute="_compute_dynamic_selection",
|
compute="_compute_num_rooms_selected",
|
||||||
store=True,
|
store=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
domain="[('value', '<=', num_rooms_available), "
|
domain="[('value', '<=', num_rooms_available), "
|
||||||
"('room_type_id', '=', room_type_id)]",
|
"('room_type_id', '=', room_type_id)]",
|
||||||
)
|
)
|
||||||
value_num_rooms_selected = fields.Integer(default=0)
|
value_num_rooms_selected = fields.Integer(
|
||||||
price_total = fields.Float(
|
compute="_compute_value_num_rooms_selected",
|
||||||
string="Total price", default=0, compute="_compute_price_total"
|
store=True,
|
||||||
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
price_per_room = fields.Float(
|
||||||
|
string="Price per room",
|
||||||
|
compute="_compute_price_per_room",
|
||||||
|
)
|
||||||
|
price_total = fields.Float(string="Total price", compute="_compute_price_total")
|
||||||
pms_property_id = fields.Many2one(
|
pms_property_id = fields.Many2one(
|
||||||
related="folio_wizard_id.pms_property_id",
|
related="folio_wizard_id.pms_property_id",
|
||||||
string="Property",
|
string="Property",
|
||||||
@@ -70,14 +72,53 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
tracking=True,
|
tracking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends("num_rooms_selected", "checkin", "checkout", "board_service_room_id")
|
@api.depends("room_type_id", "checkin", "checkout")
|
||||||
def _compute_price_total(self):
|
def _compute_num_rooms_available(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
record.price_total = 0
|
record.num_rooms_available = self.env[
|
||||||
|
"pms.availability.plan"
|
||||||
|
].get_count_rooms_available(
|
||||||
|
record.checkin,
|
||||||
|
record.checkout,
|
||||||
|
room_type_id=record.room_type_id.id,
|
||||||
|
pricelist_id=record.folio_wizard_id.pricelist_id.id,
|
||||||
|
pms_property_id=record.folio_wizard_id.pms_property_id.id,
|
||||||
|
)
|
||||||
|
|
||||||
# this field refresh is just to update it and take into account @ xml
|
@api.depends("num_rooms_available")
|
||||||
record.value_num_rooms_selected = record.num_rooms_selected.value
|
def _compute_num_rooms_selected(self):
|
||||||
|
for record in self:
|
||||||
|
for elem_to_insert in range(0, record.num_rooms_available + 1):
|
||||||
|
if (
|
||||||
|
self.env["pms.num.rooms.selection"].search_count(
|
||||||
|
[
|
||||||
|
("value", "=", elem_to_insert),
|
||||||
|
("room_type_id", "=", record.room_type_id.id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
== 0
|
||||||
|
):
|
||||||
|
self.env["pms.num.rooms.selection"].create(
|
||||||
|
{
|
||||||
|
"value": elem_to_insert,
|
||||||
|
"room_type_id": record.room_type_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
record.num_rooms_selected = self.env["pms.num.rooms.selection"].search(
|
||||||
|
[("value", "=", 0), ("room_type_id", "=", record.room_type_id.id)]
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends("num_rooms_selected")
|
||||||
|
def _compute_value_num_rooms_selected(self):
|
||||||
|
for record in self:
|
||||||
|
if record.num_rooms_selected and record.num_rooms_selected.value:
|
||||||
|
record.value_num_rooms_selected = record.num_rooms_selected.value
|
||||||
|
elif not record.value_num_rooms_selected:
|
||||||
|
record.value_num_rooms_selected = 0
|
||||||
|
|
||||||
|
@api.depends("room_type_id", "board_service_room_id", "checkin", "checkout")
|
||||||
|
def _compute_price_per_room(self):
|
||||||
|
for record in self:
|
||||||
room_type_total_price_per_room = 0
|
room_type_total_price_per_room = 0
|
||||||
|
|
||||||
for date_iterator in [
|
for date_iterator in [
|
||||||
@@ -105,59 +146,9 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
record.board_service_room_id.amount * nights
|
record.board_service_room_id.amount * nights
|
||||||
)
|
)
|
||||||
|
|
||||||
# udpate the price per room
|
|
||||||
record.price_per_room = room_type_total_price_per_room
|
record.price_per_room = room_type_total_price_per_room
|
||||||
|
|
||||||
# if there's no rooms available
|
@api.depends("price_per_room", "value_num_rooms_selected")
|
||||||
if record.num_rooms_available == 0:
|
def _compute_price_total(self):
|
||||||
# change the selector num_rooms_availabe to 0
|
|
||||||
value_selected = self.env["pms.num.rooms.selection"].search(
|
|
||||||
[
|
|
||||||
("room_type_id", "=", record.room_type_id.id),
|
|
||||||
("value", "=", 0),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if value_selected:
|
|
||||||
record.num_rooms_selected = value_selected
|
|
||||||
record.value_num_rooms_selected = 0
|
|
||||||
|
|
||||||
# change the price per room to 0
|
|
||||||
record.price_per_room = 0
|
|
||||||
|
|
||||||
record.price_total = record.price_per_room * record.num_rooms_selected.value
|
|
||||||
|
|
||||||
@api.depends("room_type_id", "checkin", "checkout")
|
|
||||||
def _compute_num_rooms_available(self):
|
|
||||||
for record in self:
|
for record in self:
|
||||||
record.num_rooms_available = self.env[
|
record.price_total = record.price_per_room * record.value_num_rooms_selected
|
||||||
"pms.availability.plan"
|
|
||||||
].get_count_rooms_available(
|
|
||||||
record.checkin,
|
|
||||||
record.checkout,
|
|
||||||
room_type_id=record.room_type_id.id,
|
|
||||||
pricelist_id=record.folio_wizard_id.pricelist_id.id,
|
|
||||||
pms_property_id=record.folio_wizard_id.pms_property_id.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _compute_dynamic_selection(self):
|
|
||||||
for record in self:
|
|
||||||
for elem_to_insert in range(0, record.num_rooms_available + 1):
|
|
||||||
if (
|
|
||||||
self.env["pms.num.rooms.selection"].search_count(
|
|
||||||
[
|
|
||||||
("value", "=", elem_to_insert),
|
|
||||||
("room_type_id", "=", record.room_type_id.id),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
== 0
|
|
||||||
):
|
|
||||||
self.env["pms.num.rooms.selection"].create(
|
|
||||||
{
|
|
||||||
"value": elem_to_insert,
|
|
||||||
"room_type_id": record.room_type_id.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
default = self.env["pms.num.rooms.selection"].search(
|
|
||||||
[("value", "=", 0), ("room_type_id", "=", record.room_type_id.id)]
|
|
||||||
)
|
|
||||||
record.num_rooms_selected = default
|
|
||||||
|
|||||||
Reference in New Issue
Block a user