mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF] pms_api_rest: refactor folio_services
This commit is contained in:
committed by
Darío Lodeiros
parent
fca390f2bf
commit
8fb04c9179
@@ -12,7 +12,8 @@ class PmsReservationInfo(Datamodel):
|
||||
checkout = fields.String(required=False, allow_none=True)
|
||||
roomTypeId = fields.Integer(required=False, allow_none=True)
|
||||
roomTypeName = fields.String(required=False, allow_none=True)
|
||||
preferredRoomId = fields.String(required=False, allow_none=True)
|
||||
preferredRoomName = fields.String(required=False, allow_none=True)
|
||||
preferredRoomId = fields.Integer(required=False, allow_none=True)
|
||||
priceTotal = fields.Float(required=False, allow_none=True)
|
||||
priceOnlyServices = fields.Float(required=False, allow_none=True)
|
||||
priceOnlyRoom = fields.Float(required=False, allow_none=True)
|
||||
@@ -22,4 +23,6 @@ class PmsReservationInfo(Datamodel):
|
||||
messages = fields.List(fields.Dict(required=False, allow_none=True))
|
||||
property = fields.Integer(required=False, allow_none=True)
|
||||
boardServiceId = fields.Integer(required=False, allow_none=True)
|
||||
boardServiceName = fields.String(required=False, allow_none=True)
|
||||
channelTypeId = fields.Integer(required=False, allow_none=True)
|
||||
adults = fields.Integer(required=False, allow_none=True)
|
||||
|
||||
@@ -114,125 +114,6 @@ class PmsFolioService(Component):
|
||||
)
|
||||
return result_folios
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>/reservations/<int:reservation_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.reservation.info"),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_reservation(self, folio_id, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
res = []
|
||||
PmsReservationInfo = self.env.datamodels["pms.reservation.info"]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
services = []
|
||||
for service in reservation.service_ids:
|
||||
if service.is_board_service:
|
||||
services.append(
|
||||
{
|
||||
"id": service.id,
|
||||
"name": service.name,
|
||||
"quantity": service.product_qty,
|
||||
"priceTotal": service.price_total,
|
||||
"priceSubtotal": service.price_subtotal,
|
||||
"priceTaxes": service.price_tax,
|
||||
"discount": service.discount,
|
||||
}
|
||||
)
|
||||
messages = []
|
||||
import re
|
||||
|
||||
text = re.compile("<.*?>")
|
||||
for message in reservation.message_ids.sorted(key=lambda x: x.date):
|
||||
messages.append(
|
||||
{
|
||||
"author": message.author_id.name,
|
||||
"date": str(message.date),
|
||||
# print(self.env["ir.fields.converter"].text_from_html(message.body))
|
||||
"body": re.sub(text, "", message.body),
|
||||
}
|
||||
)
|
||||
res = PmsReservationInfo(
|
||||
id=reservation.id,
|
||||
partner=reservation.partner_id.name,
|
||||
checkin=str(reservation.checkin),
|
||||
checkout=str(reservation.checkout),
|
||||
preferredRoomId=reservation.preferred_room_id.name
|
||||
if reservation.preferred_room_id
|
||||
else "",
|
||||
roomTypeName=reservation.room_type_id.name
|
||||
if reservation.room_type_id
|
||||
else "",
|
||||
name=reservation.name,
|
||||
priceTotal=reservation.price_room_services_set,
|
||||
priceOnlyServices=reservation.price_services
|
||||
if reservation.price_services
|
||||
else 0.0,
|
||||
priceOnlyRoom=reservation.price_total,
|
||||
pricelistName=reservation.pricelist_id.name
|
||||
if reservation.pricelist_id
|
||||
else "",
|
||||
services=services if services else [],
|
||||
messages=messages,
|
||||
)
|
||||
return res
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>/reservations/<int:reservation_id>/checkinpartners",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.checkin.partner.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_checkin_partners(self, folio_id, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
checkin_partners = []
|
||||
PmsCheckinPartnerInfo = self.env.datamodels["pms.checkin.partner.info"]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
for checkin_partner in reservation.checkin_partner_ids:
|
||||
checkin_partners.append(
|
||||
PmsCheckinPartnerInfo(
|
||||
id=checkin_partner.id,
|
||||
reservationId=checkin_partner.reservation_id.id,
|
||||
name=checkin_partner.name if checkin_partner.name else "",
|
||||
email=checkin_partner.email if checkin_partner.email else "",
|
||||
mobile=checkin_partner.mobile if checkin_partner.mobile else "",
|
||||
nationality=checkin_partner.nationality_id.name
|
||||
if checkin_partner.nationality_id
|
||||
else "",
|
||||
documentType=checkin_partner.document_type.name
|
||||
if checkin_partner.document_type
|
||||
else "",
|
||||
documentNumber=checkin_partner.document_number
|
||||
if checkin_partner.document_number
|
||||
else "",
|
||||
gender=checkin_partner.gender if checkin_partner.gender else "",
|
||||
state=dict(
|
||||
checkin_partner.fields_get(["state"])["state"]["selection"]
|
||||
)[checkin_partner.state],
|
||||
)
|
||||
)
|
||||
return checkin_partners
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
@@ -15,35 +15,94 @@ class PmsRoomService(Component):
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
"/<int:reservation_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.reservation.info", is_list=True),
|
||||
output_param=Datamodel("pms.reservation.info"),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_reservations(self):
|
||||
domain = []
|
||||
def get_reservation(self, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
res = []
|
||||
PmsReservationInfo = self.env.datamodels["pms.reservation.info"]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
services = []
|
||||
for service in reservation.service_ids:
|
||||
if service.is_board_service:
|
||||
services.append(
|
||||
{
|
||||
"id": service.id,
|
||||
"name": service.name,
|
||||
"quantity": service.product_qty,
|
||||
"priceTotal": service.price_total,
|
||||
"priceSubtotal": service.price_subtotal,
|
||||
"priceTaxes": service.price_tax,
|
||||
"discount": service.discount,
|
||||
}
|
||||
)
|
||||
messages = []
|
||||
import re
|
||||
|
||||
result_reservations = []
|
||||
PmsReservationInfo = self.env.datamodels["pms.reservation..info"]
|
||||
for reservation in (
|
||||
self.env["pms.reservation"]
|
||||
.sudo()
|
||||
.search(
|
||||
domain,
|
||||
)
|
||||
):
|
||||
result_reservations.append(
|
||||
PmsReservationInfo(
|
||||
id=reservation.id,
|
||||
price=reservation.price_subtotal,
|
||||
checkin=datetime.combine(reservation.checkin, datetime.min.time()).isoformat(),
|
||||
checkout=datetime.combine(reservation.checkout, datetime.min.time()).isoformat(),
|
||||
text = re.compile("<.*?>")
|
||||
for message in reservation.message_ids.sorted(key=lambda x: x.date):
|
||||
messages.append(
|
||||
{
|
||||
"author": message.author_id.name,
|
||||
"date": str(message.date),
|
||||
# print(self.env["ir.fields.converter"].text_from_html(message.body))
|
||||
"body": re.sub(text, "", message.body),
|
||||
}
|
||||
)
|
||||
res = PmsReservationInfo(
|
||||
id=reservation.id,
|
||||
partner=reservation.partner_id.name,
|
||||
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,
|
||||
priceTotal=reservation.price_room_services_set,
|
||||
priceOnlyServices=reservation.price_services
|
||||
if reservation.price_services
|
||||
else 0.0,
|
||||
priceOnlyRoom=reservation.price_total,
|
||||
pricelistName=reservation.pricelist_id.name
|
||||
if reservation.pricelist_id
|
||||
else "",
|
||||
pricelistId=reservation.pricelist_id.id
|
||||
if reservation.pricelist_id
|
||||
else 0,
|
||||
services=services if services else [],
|
||||
messages=messages,
|
||||
boardServiceId=reservation.board_service_room_id.id
|
||||
if reservation.board_service_room_id
|
||||
else 0,
|
||||
boardServiceName=reservation.board_service_room_id.pms_board_service_id.name
|
||||
if reservation.board_service_room_id
|
||||
else "",
|
||||
# review if its an agency
|
||||
channelTypeId=reservation.channel_type_id.id
|
||||
if reservation.channel_type_id
|
||||
else 0,
|
||||
adults=reservation.adults,
|
||||
)
|
||||
return result_reservations
|
||||
return res
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
@@ -57,7 +116,7 @@ class PmsRoomService(Component):
|
||||
input_param=Datamodel("pms.calendar.changes", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def move_reservation_line(self, reservation_id, reservation_lines_changes):
|
||||
def update_reservation(self, reservation_id, reservation_lines_changes):
|
||||
|
||||
# get date of first reservation id to change
|
||||
first_reservation_line_id_to_change = (
|
||||
@@ -108,3 +167,49 @@ class PmsRoomService(Component):
|
||||
reservation = self.env["pms.reservation"].browse(reservation_id)
|
||||
reservation.checkin = min_value
|
||||
reservation.checkout = max_value
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:reservation_id>/checkinpartners",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.checkin.partner.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_checkin_partners(self, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
checkin_partners = []
|
||||
PmsCheckinPartnerInfo = self.env.datamodels["pms.checkin.partner.info"]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
for checkin_partner in reservation.checkin_partner_ids:
|
||||
checkin_partners.append(
|
||||
PmsCheckinPartnerInfo(
|
||||
id=checkin_partner.id,
|
||||
reservationId=checkin_partner.reservation_id.id,
|
||||
name=checkin_partner.name if checkin_partner.name else "",
|
||||
email=checkin_partner.email if checkin_partner.email else "",
|
||||
mobile=checkin_partner.mobile if checkin_partner.mobile else "",
|
||||
nationality=checkin_partner.nationality_id.name
|
||||
if checkin_partner.nationality_id
|
||||
else "",
|
||||
documentType=checkin_partner.document_type.name
|
||||
if checkin_partner.document_type
|
||||
else "",
|
||||
documentNumber=checkin_partner.document_number
|
||||
if checkin_partner.document_number
|
||||
else "",
|
||||
gender=checkin_partner.gender if checkin_partner.gender else "",
|
||||
state=dict(
|
||||
checkin_partner.fields_get(["state"])["state"]["selection"]
|
||||
)[checkin_partner.state],
|
||||
)
|
||||
)
|
||||
return checkin_partners
|
||||
|
||||
Reference in New Issue
Block a user