Skip to content

Commit

Permalink
[IMP] pms-pwa: service folios
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Aug 31, 2021
1 parent a91bc67 commit 70720b0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 139 deletions.
1 change: 1 addition & 0 deletions pms_api_rest/controllers/pms_rest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo.addons.base_rest.controllers import main

from ..lib_jwt.jwt_http import jwt_http
from ..lib_jwt.validator import validator

Expand Down
19 changes: 3 additions & 16 deletions pms_api_rest/datamodels/pms_folio_short_info.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
from marshmallow import fields, Schema
from typing import List
from marshmallow import Schema, fields

from odoo.addons.datamodel.core import Datamodel
from .pms_reservation_short_info import PmsReservationShortInfo


class PmsReservationSchema(Schema):

id = fields.Integer(required=True, allow_none=False)
checkin = fields.String(required=True, allow_none=True)
checkout = fields.String(required=True, allow_none=True)
preferredRoomId = fields.String(required=False, allow_none=True)
roomTypeId = fields.String(required=False, allow_none=True)
priceTotal = fields.Float(required=False, allow_none=True)
adults = fields.Integer(required=False, allow_none=True)
pricelist = fields.String(required=False, allow_none=True)



class PmsFolioShortInfo(Datamodel):
_name = "pms.folio.short.info"

id = fields.Integer(required=False, allow_none=True)
name = fields.String(required=False, allow_none=True)
partnerName = fields.String(required=False, allow_none=True)
partnerPhone = fields.String(required=False, allow_none=True)
partnerEmail = fields.String(required=False, allow_none=True)
channelType = fields.String(required=False, allow_none=True)
agency = fields.String(required=False, allow_none=True)
# paymentState = fields.String(required=False, allow_none=True)
state = fields.String(required=False, allow_none=True)
pendingAmount = fields.Float(required=False, allow_none=True)
reservations = fields.List(fields.Nested(PmsReservationSchema))

reservations = fields.List(fields.Dict(required=False, allow_none=True))
78 changes: 17 additions & 61 deletions pms_api_rest/services/folio_services.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import json

from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component

from ..datamodels.pms_folio_short_info import PmsReservationSchema


class PmsFolioService(Component):
_inherit = "base.rest.service"
Expand All @@ -26,78 +22,41 @@ class PmsFolioService(Component):
output_param=Datamodel("pms.folio.short.info", is_list=True),
auth="public",
)
def search(self, folio_search_param):
def get_folios(self, folio_search_param):
domain = []
if folio_search_param.name:
domain.append(("name", "like", folio_search_param.name))
if folio_search_param.id:
domain.append(("id", "=", folio_search_param.id))
res = []
result_folios = []
PmsFolioShortInfo = self.env.datamodels["pms.folio.short.info"]
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
for folio in (
self.env["pms.folio"]
.sudo()
.search(
.sudo()
.search(
domain,
)
):
reservations = []
for reservation in folio.reservation_ids:
reservation_schema = PmsReservationSchema()
room = reservation.preferred_room_id.name if reservation.preferred_room_id else ""
room_type = reservation.room_type_id.name if reservation.room_type_id else ""
data = {
"id": reservation.id,
"checkin": str(reservation.checkin),
"checkout": str(reservation.checkout),
"preferredRoomId": room,
"roomTypeId": room_type,
"priceTotal": reservation.price_total,
"adults": reservation.adults,
"pricelist": reservation.pricelist_id.name,
}
reservations.append(reservation_schema.load(data))
'''{
"id": reservation.id,
"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 "",
"priceTotal": reservation.price_total,
"adults": reservation.adults,
"pricelist": reservation.pricelist_id.name,
}'''






'''
reservations.append(
PmsReservationSchema(
"id":reservation.id,
checkin=str(reservation.checkin),
checkout=str(reservation.checkout),
preferredRoomId=reservation.preferred_room_id.name
{
"id": reservation.id,
"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
"roomTypeId": reservation.room_type_id.name
if reservation.room_type_id
else "",
priceTotal=reservation.price_total,
adults=reservation.adults,
pricelist=reservation.pricelist_id.name,
)
"priceTotal": reservation.price_total,
"adults": reservation.adults,
"pricelist": reservation.pricelist_id.name,
}
)
'''

res.append(
result_folios.append(
PmsFolioShortInfo(
id=folio.id,
name=folio.name,
Expand All @@ -106,17 +65,14 @@ def search(self, folio_search_param):
partnerEmail=folio.email if folio.email else "",
channelType=folio.channel_type_id if folio.channel_type_id else "",
agency=folio.agency_id if folio.agency_id else "",
# paymentState=dict(folio.fields_get(["payment_state"])["payment_state"]["selection"])[
# folio.payment_state
# ],
state=dict(folio.fields_get(["state"])["state"]["selection"])[
folio.state
],
pendingAmount=folio.pending_amount,
reservations=reservations,
reservations=[] if not reservations else reservations,
)
)
return res
return result_folios

@restapi.method(
[
Expand Down
65 changes: 3 additions & 62 deletions pms_api_rest/services/reservation_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PmsReservationService(Component):
_usage = "reservations"
_collection = "pms.reservation.service"

# TODO: REMOVE
@restapi.method(
[
(
Expand All @@ -24,7 +25,7 @@ class PmsReservationService(Component):
output_param=Datamodel("pms.reservation.short.info", is_list=True),
auth="public",
)
def search(self, reservation_search_param):
def get_reservations(self, reservation_search_param):
domain = []
if reservation_search_param.name:
domain.append(("name", "like", reservation_search_param.name))
Expand Down Expand Up @@ -77,6 +78,7 @@ def search(self, reservation_search_param):
)
)
return res
# END TODO: REMOVE

@restapi.method(
[
Expand Down Expand Up @@ -154,64 +156,3 @@ def get_reservation(self, reservation_id):
)
return res

@restapi.method(
[
(
[
"/folio/<int:id>",
],
"GET",
)
],
output_param=Datamodel("pms.reservation.short.info", is_list=True),
auth="public",
)
def get_reservations(self, folio_id):
folio = (
self.env["pms.folio"].sudo().search([("id", "=", folio_id)])
)
res = []
if not folio.reservation_ids:
pass
else:
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]

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
else "",
roomTypeId=reservation.room_type_id.name
if reservation.room_type_id
else "",
name=reservation.name,
partnerRequests=reservation.partner_requests
if reservation.partner_requests
else "",
state=dict(reservation.fields_get(["state"])["state"]["selection"])[
reservation.state
],
priceTotal=reservation.price_total,
adults=reservation.adults,
channelTypeId=reservation.channel_type_id
if reservation.channel_type_id
else "",
agencyId=reservation.agency_id 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,
pricelist=reservation.pricelist_id.name,
folioId=reservation.folio_id.id,
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
if reservation.pwa_action_buttons
else {},
)
)
return res
Binary file not shown.

0 comments on commit 70720b0

Please sign in to comment.