mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: imrpovemente performance issues on folio sale lines compute
This commit is contained in:
@@ -796,13 +796,14 @@ class PmsFolio(models.Model):
|
|||||||
"reservation_ids.tax_ids",
|
"reservation_ids.tax_ids",
|
||||||
)
|
)
|
||||||
def _compute_sale_line_ids(self):
|
def _compute_sale_line_ids(self):
|
||||||
for folio in self:
|
for folio in self.filtered(lambda f: isinstance(f.id, int)):
|
||||||
sale_lines_vals = []
|
sale_lines_vals = []
|
||||||
if folio.reservation_type == "normal":
|
if folio.reservation_type == "normal":
|
||||||
sale_lines_vals_to_drop = []
|
sale_lines_vals_to_drop = []
|
||||||
seq = 0
|
seq = 0
|
||||||
for reservation in sorted(
|
for reservation in sorted(
|
||||||
folio.reservation_ids, key=lambda r: r.folio_sequence
|
folio.reservation_ids.filtered(lambda r: isinstance(r.id, int)),
|
||||||
|
key=lambda r: r.folio_sequence,
|
||||||
):
|
):
|
||||||
seq += reservation.folio_sequence
|
seq += reservation.folio_sequence
|
||||||
# RESERVATION LINES
|
# RESERVATION LINES
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class PmsReservationLine(models.Model):
|
|||||||
copy=False,
|
copy=False,
|
||||||
comodel_name="pms.reservation",
|
comodel_name="pms.reservation",
|
||||||
ondelete="cascade",
|
ondelete="cascade",
|
||||||
|
index=True,
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
room_id = fields.Many2one(
|
room_id = fields.Many2one(
|
||||||
|
|||||||
@@ -250,24 +250,33 @@ class BookingEngine(models.TransientModel):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
folio = record.folio_id
|
folio = record.folio_id
|
||||||
|
reservation_values = []
|
||||||
for line in record.availability_results:
|
for line in record.availability_results:
|
||||||
for _reservations_to_create in range(0, line.value_num_rooms_selected):
|
for _reservations_to_create in range(0, line.value_num_rooms_selected):
|
||||||
res = self.env["pms.reservation"].create(
|
res_dict = {
|
||||||
{
|
"folio_id": folio.id,
|
||||||
"folio_id": folio.id,
|
"checkin": line.checkin,
|
||||||
"checkin": line.checkin,
|
"checkout": line.checkout,
|
||||||
"checkout": line.checkout,
|
"room_type_id": line.room_type_id.id,
|
||||||
"room_type_id": line.room_type_id.id,
|
"partner_id": record.partner_id.id
|
||||||
"partner_id": record.partner_id.id
|
if record.partner_id
|
||||||
if record.partner_id
|
else False,
|
||||||
else False,
|
"partner_name": record.partner_name,
|
||||||
"partner_name": record.partner_name,
|
"pricelist_id": record.pricelist_id.id,
|
||||||
"pricelist_id": record.pricelist_id.id,
|
"pms_property_id": folio.pms_property_id.id,
|
||||||
"pms_property_id": folio.pms_property_id.id,
|
"board_service_room_id": line.board_service_room_id.id,
|
||||||
"board_service_room_id": line.board_service_room_id.id,
|
}
|
||||||
}
|
reservation_values.append((0, 0, res_dict))
|
||||||
)
|
folio.write(
|
||||||
res.reservation_line_ids.discount = record.discount * 100
|
{
|
||||||
|
"reservation_ids": reservation_values,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if record.discount:
|
||||||
|
# TODO: Refact compute discount in reservation and service lines
|
||||||
|
folio.reservation_ids.reservation_line_ids.discount = (
|
||||||
|
record.discount * 100
|
||||||
|
)
|
||||||
action = self.env.ref("pms.open_pms_folio1_form_tree_all").read()[0]
|
action = self.env.ref("pms.open_pms_folio1_form_tree_all").read()[0]
|
||||||
action["views"] = [(self.env.ref("pms.pms_folio_view_form").id, "form")]
|
action["views"] = [(self.env.ref("pms.pms_folio_view_form").id, "form")]
|
||||||
action["res_id"] = folio.id
|
action["res_id"] = folio.id
|
||||||
|
|||||||
Reference in New Issue
Block a user