mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add get_reservation and get_checkin_partners
This commit is contained in:
committed by
Darío Lodeiros
parent
d615fbf8b4
commit
d0c03f47c0
@@ -15,5 +15,8 @@
|
||||
"external_dependencies": {
|
||||
"python": ["jwt", "simplejson", "marshmallow"],
|
||||
},
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ from . import pms_folio_short_info
|
||||
from . import pms_room_short_info
|
||||
from . import pms_room_search_param
|
||||
|
||||
from . import pms_partner_short_info
|
||||
from . import pms_reservation_short_info
|
||||
|
||||
from . import pms_checkin_partner_short_info
|
||||
|
||||
18
pms_api_rest/datamodels/pms_checkin_partner_short_info.py
Normal file
18
pms_api_rest/datamodels/pms_checkin_partner_short_info.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsCheckinPartnerShortInfo(Datamodel):
|
||||
_name = "pms.checkin.partner.short.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
# partner = fields.String(required=False, allow_none=True)
|
||||
reservationId = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
email = fields.String(required=False, allow_none=True)
|
||||
mobile = fields.String(required=False, allow_none=True)
|
||||
nationality = fields.String(required=False, allow_none=True)
|
||||
documentType = fields.String(required=False, allow_none=True)
|
||||
documentNumber = fields.String(required=False, allow_none=True)
|
||||
gender = fields.String(required=False, allow_none=True)
|
||||
state = fields.String(required=False, allow_none=True)
|
||||
@@ -6,6 +6,21 @@ from odoo.addons.datamodel.core import Datamodel
|
||||
class PmsReservationShortInfo(Datamodel):
|
||||
_name = "pms.reservation.short.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
<<<<<<< HEAD
|
||||
price = fields.Float(required=False, allow_none=True)
|
||||
checkin = fields.String(required=False, allow_none=True)
|
||||
checkout = fields.String(required=False, allow_none=True)
|
||||
=======
|
||||
partner = fields.String(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
checkin = fields.String(required=False, allow_none=True)
|
||||
checkout = fields.String(required=False, allow_none=True)
|
||||
roomTypeId = fields.String(required=False, allow_none=True)
|
||||
preferredRoomId = fields.String(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)
|
||||
pricelist = fields.String(required=False, allow_none=True)
|
||||
services = fields.List(fields.Dict(required=False, allow_none=True))
|
||||
messages = fields.List(fields.Dict(required=False, allow_none=True))
|
||||
>>>>>>> d6e6a667... [IMP] pms_api_rest: add get_reservation and get_checkin_partners
|
||||
|
||||
@@ -26,8 +26,17 @@ class PmsCalendarService(Component):
|
||||
)
|
||||
def get_calendar(self, calendar_search_param):
|
||||
domain = list()
|
||||
<<<<<<< HEAD
|
||||
domain.append(("date", ">=", datetime.fromisoformat(calendar_search_param.date_from)))
|
||||
domain.append(("date", "<=", datetime.fromisoformat(calendar_search_param.date_to)))
|
||||
=======
|
||||
domain.append(
|
||||
("date", ">", datetime.fromisoformat(calendar_search_param.date_from))
|
||||
)
|
||||
domain.append(
|
||||
("date", "<=", datetime.fromisoformat(calendar_search_param.date_to))
|
||||
)
|
||||
>>>>>>> d6e6a667... [IMP] pms_api_rest: add get_reservation and get_checkin_partners
|
||||
result_lines = []
|
||||
PmsCalendarShortInfo = self.env.datamodels["pms.calendar.short.info"]
|
||||
for line in (
|
||||
|
||||
@@ -69,12 +69,17 @@ class PmsFolioService(Component):
|
||||
"priceTotal": reservation.price_total,
|
||||
"adults": reservation.adults,
|
||||
"pricelist": reservation.pricelist_id.name,
|
||||
"boardService": reservation.board_service_room_id.pms_board_service_id.name
|
||||
"boardService": (
|
||||
reservation.board_service_room_id.pms_board_service_id.name
|
||||
)
|
||||
if reservation.board_service_room_id
|
||||
else "",
|
||||
"reservationLines": []
|
||||
if not reservation_lines
|
||||
else reservation_lines,
|
||||
"folioId": reservation.folio_id.id
|
||||
if reservation.folio_id
|
||||
else "",
|
||||
}
|
||||
)
|
||||
result_folios.append(
|
||||
@@ -102,55 +107,119 @@ class PmsFolioService(Component):
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>/reservations",
|
||||
"/<int:id>/reservations/<int:reservation_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.folio.short.info", is_list=True),
|
||||
output_param=Datamodel("pms.reservation.short.info"),
|
||||
auth="public",
|
||||
)
|
||||
def get_reservations(self, folio_id):
|
||||
folio = self.env["pms.folio"].sudo().search([("id", "=", folio_id)])
|
||||
def get_reservation(self, folio_id, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
res = []
|
||||
if not folio.reservation_ids:
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
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
|
||||
|
||||
for reservation in folio.reservation_ids:
|
||||
res.append(
|
||||
PmsReservationShortInfo(
|
||||
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
|
||||
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 = PmsReservationShortInfo(
|
||||
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 "",
|
||||
roomTypeId=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,
|
||||
pricelist=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.short.info", is_list=True),
|
||||
auth="public",
|
||||
)
|
||||
def get_checkin_partners(self, folio_id, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
checkin_partners = []
|
||||
PmsCheckinPartnerShortInfo = self.env.datamodels[
|
||||
"pms.checkin.partner.short.info"
|
||||
]
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
for checkin_partner in reservation.checkin_partner_ids:
|
||||
checkin_partners.append(
|
||||
PmsCheckinPartnerShortInfo(
|
||||
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 "",
|
||||
roomTypeId=reservation.room_type_id.name
|
||||
if reservation.room_type_id
|
||||
documentType=checkin_partner.document_type.name
|
||||
if checkin_partner.document_type
|
||||
else "",
|
||||
name=reservation.name,
|
||||
partnerRequests=reservation.partner_requests
|
||||
if reservation.partner_requests
|
||||
documentNumber=checkin_partner.document_number
|
||||
if checkin_partner.document_number
|
||||
else "",
|
||||
gender=checkin_partner.gender if checkin_partner.gender else "",
|
||||
state=dict(
|
||||
reservation.fields_get(["state"])["state"]["selection"]
|
||||
)[reservation.state],
|
||||
priceTotal=reservation.price_total,
|
||||
adults=reservation.adults,
|
||||
channelTypeId=reservation.channel_type_id.name
|
||||
if reservation.channel_type_id
|
||||
else "",
|
||||
agencyId=reservation.agency_id.name
|
||||
if reservation.agency_id
|
||||
else "",
|
||||
boardServiceId=reservation.board_service_room_id.pms_board_service_id.name
|
||||
if reservation.board_service_room_id
|
||||
else "",
|
||||
checkinsRatio=reservation.checkins_ratio,
|
||||
outstanding=reservation.folio_id.pending_amount,
|
||||
checkin_partner.fields_get(["state"])["state"]["selection"]
|
||||
)[checkin_partner.state],
|
||||
)
|
||||
)
|
||||
return res
|
||||
return checkin_partners
|
||||
|
||||
Reference in New Issue
Block a user