Skip to content

Commit

Permalink
[IMP] pms: calendar, service & rooms service
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Nov 24, 2021
2 parents 75b51bb + d6e6a66 commit acdb6a4
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 41 deletions.
3 changes: 3 additions & 0 deletions pms_api_rest/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"external_dependencies": {
"python": ["jwt", "simplejson", "marshmallow"],
},
"data": [
"security/ir.model.access.csv",
],
"installable": True,
}
2 changes: 1 addition & 1 deletion pms_api_rest/datamodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
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 changes: 18 additions & 0 deletions pms_api_rest/datamodels/pms_checkin_partner_short_info.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 10 additions & 1 deletion pms_api_rest/datamodels/pms_reservation_short_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
class PmsReservationShortInfo(Datamodel):
_name = "pms.reservation.short.info"
id = fields.Integer(required=False, allow_none=True)
price = fields.Float(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))
8 changes: 6 additions & 2 deletions pms_api_rest/services/calendar_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ class PmsCalendarService(Component):
)
def get_calendar(self, calendar_search_param):
domain = list()
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))
)
result_lines = []
PmsCalendarShortInfo = self.env.datamodels["pms.calendar.short.info"]
for line in (
Expand Down
143 changes: 106 additions & 37 deletions pms_api_rest/services/folio_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ def get_folios(self, folio_search_param):
"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(
Expand Down Expand Up @@ -102,55 +107,119 @@ def get_folios(self, folio_search_param):
[
(
[
"/<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

0 comments on commit acdb6a4

Please sign in to comment.