mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: Add service reservation/reservation-lines
This commit is contained in:
@@ -73,20 +73,6 @@ class PmsFolioService(Component):
|
|||||||
for folio in self.env["pms.folio"].search(
|
for folio in self.env["pms.folio"].search(
|
||||||
[("id", "in", reservations_result)],
|
[("id", "in", reservations_result)],
|
||||||
):
|
):
|
||||||
for reservation in folio.reservation_ids:
|
|
||||||
reservation_lines = []
|
|
||||||
for reservation_line in reservation.reservation_line_ids:
|
|
||||||
reservation_lines.append(
|
|
||||||
{
|
|
||||||
"id": reservation_line.id,
|
|
||||||
"date": datetime.combine(
|
|
||||||
reservation_line.date, datetime.min.time()
|
|
||||||
).isoformat(),
|
|
||||||
"roomId": reservation_line.room_id.id,
|
|
||||||
"roomName": reservation_line.room_id.name,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
result_folios.append(
|
result_folios.append(
|
||||||
PmsFolioInfo(
|
PmsFolioInfo(
|
||||||
id=folio.id,
|
id=folio.id,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from odoo.exceptions import MissingError
|
||||||
|
from odoo import _
|
||||||
|
|
||||||
|
|
||||||
from odoo.addons.base_rest import restapi
|
from odoo.addons.base_rest import restapi
|
||||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||||
@@ -35,75 +38,80 @@ class PmsReservationService(Component):
|
|||||||
if not reservation:
|
if not reservation:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
services = []
|
# services = []
|
||||||
for service in reservation.service_ids:
|
# for service in reservation.service_ids:
|
||||||
if service.is_board_service:
|
# if service.is_board_service:
|
||||||
services.append(
|
# services.append(
|
||||||
{
|
# {
|
||||||
"id": service.id,
|
# "id": service.id,
|
||||||
"name": service.name,
|
# "name": service.name,
|
||||||
"quantity": service.product_qty,
|
# "quantity": service.product_qty,
|
||||||
"priceTotal": service.price_total,
|
# "priceTotal": service.price_total,
|
||||||
"priceSubtotal": service.price_subtotal,
|
# "priceSubtotal": service.price_subtotal,
|
||||||
"priceTaxes": service.price_tax,
|
# "priceTaxes": service.price_tax,
|
||||||
"discount": service.discount,
|
# "discount": service.discount,
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
messages = []
|
# messages = []
|
||||||
import re
|
# import re
|
||||||
|
|
||||||
text = re.compile("<.*?>")
|
# text = re.compile("<.*?>")
|
||||||
for message in reservation.message_ids.sorted(key=lambda x: x.date):
|
# for message in reservation.message_ids.sorted(key=lambda x: x.date):
|
||||||
messages.append(
|
# messages.append(
|
||||||
{
|
# {
|
||||||
"author": message.author_id.name,
|
# "author": message.author_id.name,
|
||||||
"date": str(message.date),
|
# "date": str(message.date),
|
||||||
# print(self.env["ir.fields.converter"].text_from_html(message.body))
|
# # print(self.env["ir.fields.converter"].text_from_html(message.body))
|
||||||
"body": re.sub(text, "", message.body),
|
# "body": re.sub(text, "", message.body),
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
res = PmsReservationInfo(
|
res = PmsReservationInfo(
|
||||||
id=reservation.id,
|
id=reservation.id,
|
||||||
partner=reservation.partner_id.name if reservation.partner_id else "",
|
|
||||||
checkin=str(reservation.checkin),
|
|
||||||
checkout=str(reservation.checkout),
|
|
||||||
preferredRoomId=reservation.preferred_room_id.id
|
|
||||||
if reservation.preferred_room_id
|
|
||||||
else 0,
|
|
||||||
preferredRoomName=reservation.preferred_room_id.name
|
|
||||||
if reservation.preferred_room_id
|
|
||||||
else "",
|
|
||||||
roomTypeId=reservation.room_type_id.id
|
|
||||||
if reservation.room_type_id
|
|
||||||
else 0,
|
|
||||||
roomTypeName=reservation.room_type_id.name
|
|
||||||
if reservation.room_type_id
|
|
||||||
else "",
|
|
||||||
name=reservation.name,
|
name=reservation.name,
|
||||||
priceTotal=reservation.price_room_services_set,
|
folioId=reservation.folio_id.id,
|
||||||
priceOnlyServices=reservation.price_services
|
folioSequence=reservation.folio_sequence,
|
||||||
if reservation.price_services
|
partnerName=reservation.partner_name,
|
||||||
else 0.0,
|
pmsPropertyId=reservation.pms_property_id.id,
|
||||||
priceOnlyRoom=reservation.price_total,
|
boardServiceId=reservation.board_service_room_id.id or None,
|
||||||
pricelistName=reservation.pricelist_id.name
|
saleChannelId=reservation.channel_type_id.id or None,
|
||||||
if reservation.pricelist_id
|
agencyId=reservation.agency_id.id or None,
|
||||||
else "",
|
checkin=datetime.combine(
|
||||||
pricelistId=reservation.pricelist_id.id
|
reservation.checkin, datetime.min.time()
|
||||||
if reservation.pricelist_id
|
).isoformat(),
|
||||||
else 0,
|
checkout=datetime.combine(
|
||||||
services=services if services else [],
|
reservation.checkout, datetime.min.time()
|
||||||
messages=messages,
|
).isoformat(),
|
||||||
boardServiceId=reservation.board_service_room_id.id
|
arrivalHour=reservation.arrival_hour,
|
||||||
if reservation.board_service_room_id
|
departureHour=reservation.departure_hour,
|
||||||
else 0,
|
roomTypeId=reservation.room_type_id.id or None,
|
||||||
boardServiceName=reservation.board_service_room_id.pms_board_service_id.name
|
preferredRoomId=reservation.preferred_room_id.id or None,
|
||||||
if reservation.board_service_room_id
|
pricelistId=reservation.pricelist_id.id,
|
||||||
else "",
|
|
||||||
# review if its an agency
|
|
||||||
channelTypeId=reservation.channel_type_id.id
|
|
||||||
if reservation.channel_type_id
|
|
||||||
else 0,
|
|
||||||
adults=reservation.adults,
|
adults=reservation.adults,
|
||||||
|
overbooking=reservation.overbooking,
|
||||||
|
externalReference=reservation.external_reference or None,
|
||||||
|
state=reservation.state,
|
||||||
|
children=reservation.children or None,
|
||||||
|
readyForCheckin=reservation.ready_for_checkin,
|
||||||
|
allowedCheckout=reservation.allowed_checkout,
|
||||||
|
isSplitted=reservation.splitted,
|
||||||
|
pendingCheckinData=reservation.pending_checkin_data,
|
||||||
|
createDate=datetime.combine(
|
||||||
|
reservation.create_date, datetime.min.time()
|
||||||
|
).isoformat(),
|
||||||
|
segmentationId=reservation.segmentation_ids[0].id
|
||||||
|
if reservation.segmentation_ids
|
||||||
|
else None,
|
||||||
|
cancellationPolicyId=reservation.pricelist_id.cancelation_rule_id.id
|
||||||
|
or None,
|
||||||
|
toAssign=reservation.to_assign,
|
||||||
|
reservationType=reservation.reservation_type,
|
||||||
|
priceTotal=reservation.price_room_services_set,
|
||||||
|
discount=reservation.discount,
|
||||||
|
commissionAmount=reservation.commission_amount or None,
|
||||||
|
commissionPercent=reservation.commission_percent or None,
|
||||||
|
priceOnlyServices=reservation.price_services,
|
||||||
|
priceOnlyRoom=reservation.price_total,
|
||||||
|
pendingAmount=reservation.folio_pending_amount,
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -208,6 +216,41 @@ class PmsReservationService(Component):
|
|||||||
)
|
)
|
||||||
reservation_to_update.write(reservation_vals)
|
reservation_to_update.write(reservation_vals)
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:reservation_id>/reservation-lines",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.reservation.line.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_reservation_line(self, reservation_id):
|
||||||
|
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
|
||||||
|
if not reservation:
|
||||||
|
raise MissingError(_("Reservation not found"))
|
||||||
|
result_lines = []
|
||||||
|
PmsReservationLineInfo = self.env.datamodels["pms.reservation.line.info"]
|
||||||
|
for reservation_line in reservation.reservation_line_ids:
|
||||||
|
result_lines.append(
|
||||||
|
PmsReservationLineInfo(
|
||||||
|
id=reservation_line.id,
|
||||||
|
date=datetime.combine(
|
||||||
|
reservation_line.date, datetime.min.time()
|
||||||
|
).isoformat(),
|
||||||
|
price=reservation_line.price,
|
||||||
|
discount=reservation_line.discount,
|
||||||
|
cancelDiscount=reservation_line.cancel_discount,
|
||||||
|
roomId=reservation_line.room_id.id,
|
||||||
|
reservationId=reservation_line.reservation_id.id,
|
||||||
|
pmsPropertyId=reservation_line.pms_property_id.id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_lines
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user