mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Add folio services
This commit is contained in:
committed by
Darío Lodeiros
parent
a706b7a308
commit
308c35f878
@@ -1,4 +1,6 @@
|
|||||||
from odoo.addons.base_rest.controllers import main
|
from odoo.addons.base_rest.controllers import main
|
||||||
|
from ..lib_jwt.jwt_http import jwt_http
|
||||||
|
from ..lib_jwt.validator import validator
|
||||||
|
|
||||||
|
|
||||||
class BaseRestDemoPublicApiController(main.RestController):
|
class BaseRestDemoPublicApiController(main.RestController):
|
||||||
@@ -7,13 +9,13 @@ class BaseRestDemoPublicApiController(main.RestController):
|
|||||||
_default_auth = "public"
|
_default_auth = "public"
|
||||||
|
|
||||||
# RestController OVERRIDE method
|
# RestController OVERRIDE method
|
||||||
# def _process_method(self, service_name, method_name, *args, params=None):
|
def _process_method(self, service_name, method_name, *args, params=None):
|
||||||
#
|
|
||||||
# http_method, body, headers, token = jwt_http.parse_request()
|
http_method, body, headers, token = jwt_http.parse_request()
|
||||||
# result = validator.verify_token(token)
|
result = validator.verify_token(token)
|
||||||
# if not result["status"]:
|
if not result["status"]:
|
||||||
# return jwt_http.errcode(code=result["code"], message=result["message"])
|
return jwt_http.errcode(code=result["code"], message=result["message"])
|
||||||
# else:
|
else:
|
||||||
# return super(BaseRestDemoPublicApiController, self)._process_method(
|
return super(BaseRestDemoPublicApiController, self)._process_method(
|
||||||
# service_name, method_name, *args, params=params
|
service_name, method_name, *args, params=params
|
||||||
# )
|
)
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
from . import pms_reservation_short_info
|
from . import pms_reservation_short_info
|
||||||
from . import pms_reservation_search_param
|
from . import pms_reservation_search_param
|
||||||
|
from . import pms_folio_short_info
|
||||||
|
from . import pms_folio_search_param
|
||||||
|
|||||||
10
pms_api_rest/datamodels/pms_folio_search_param.py
Normal file
10
pms_api_rest/datamodels/pms_folio_search_param.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsFolioSearchParam(Datamodel):
|
||||||
|
_name = "pms.folio.search.param"
|
||||||
|
|
||||||
|
id = fields.Integer(required=False, allow_none=False)
|
||||||
|
name = fields.String(required=False, allow_none=False)
|
||||||
34
pms_api_rest/datamodels/pms_folio_short_info.py
Normal file
34
pms_api_rest/datamodels/pms_folio_short_info.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from marshmallow import fields, Schema
|
||||||
|
from typing import List
|
||||||
|
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))
|
||||||
|
|
||||||
@@ -7,19 +7,21 @@ class PmsReservationShortInfo(Datamodel):
|
|||||||
_name = "pms.reservation.short.info"
|
_name = "pms.reservation.short.info"
|
||||||
|
|
||||||
id = fields.Integer(required=True, allow_none=False)
|
id = fields.Integer(required=True, allow_none=False)
|
||||||
partner = fields.String(required=True, allow_none=False)
|
partner = fields.String(required=False, allow_none=True)
|
||||||
checkin = fields.String(required=True, allow_none=False)
|
checkin = fields.String(required=True, allow_none=True)
|
||||||
checkout = fields.String(required=True, allow_none=False)
|
checkout = fields.String(required=True, allow_none=True)
|
||||||
preferredRoomId = fields.String(required=True, allow_none=False)
|
preferredRoomId = fields.String(required=False, allow_none=True)
|
||||||
roomTypeId = fields.String(required=True, allow_none=False)
|
roomTypeId = fields.String(required=False, allow_none=True)
|
||||||
name = fields.String(required=True, allow_none=False)
|
name = fields.String(required=False, allow_none=True)
|
||||||
partnerRequests = fields.String(required=False, allow_none=True)
|
partnerRequests = fields.String(required=False, allow_none=True)
|
||||||
state = fields.String(required=True, allow_none=False)
|
state = fields.String(required=False, allow_none=True)
|
||||||
priceTotal = fields.Float(required=True, allow_none=True)
|
priceTotal = fields.Float(required=False, allow_none=True)
|
||||||
adults = fields.Integer(required=True, allow_none=False)
|
adults = fields.Integer(required=False, allow_none=True)
|
||||||
channelTypeId = fields.String(required=False, allow_none=True)
|
channelTypeId = fields.String(required=False, allow_none=True)
|
||||||
agencyId = fields.String(required=False, allow_none=True)
|
agencyId = fields.String(required=False, allow_none=True)
|
||||||
boardServiceId = fields.String(required=False, allow_none=True)
|
boardServiceId = fields.String(required=False, allow_none=True)
|
||||||
checkinsRatio = fields.Float(required=True, allow_none=False)
|
checkinsRatio = fields.Float(required=False, allow_none=True)
|
||||||
outstanding = fields.Float(required=True, allow_none=False)
|
outstanding = fields.Float(required=False, allow_none=True)
|
||||||
pwaActionButtons = fields.Dict(required=True, allow_none=False)
|
pricelist = fields.String(required=False, allow_none=True)
|
||||||
|
folioId = fields.Integer(required=False, allow_none=True)
|
||||||
|
pwaActionButtons = fields.Dict(required=False, allow_none=True)
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class JwtHttp:
|
|||||||
|
|
||||||
# login success, generate token
|
# login success, generate token
|
||||||
user = request.env.user.read(return_fields)[0]
|
user = request.env.user.read(return_fields)[0]
|
||||||
exp = datetime.datetime.utcnow() + datetime.timedelta(minutes=3)
|
exp = datetime.datetime.utcnow() + datetime.timedelta(minutes=30000)
|
||||||
token = validator.create_token(user, exp)
|
token = validator.create_token(user, exp)
|
||||||
|
|
||||||
return self.response(
|
return self.response(
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from . import reservation_services
|
from . import reservation_services
|
||||||
|
from . import folio_services
|
||||||
|
|||||||
179
pms_api_rest/services/folio_services.py
Normal file
179
pms_api_rest/services/folio_services.py
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
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"
|
||||||
|
_name = "pms.folio.service"
|
||||||
|
_usage = "folios"
|
||||||
|
_collection = "pms.reservation.service"
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.folio.search.param"),
|
||||||
|
output_param=Datamodel("pms.folio.short.info", is_list=True),
|
||||||
|
auth="public",
|
||||||
|
)
|
||||||
|
def search(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 = []
|
||||||
|
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(
|
||||||
|
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
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
|
||||||
|
res.append(
|
||||||
|
PmsFolioShortInfo(
|
||||||
|
id=folio.id,
|
||||||
|
name=folio.name,
|
||||||
|
partnerName=folio.partner_name if folio.partner_name else "",
|
||||||
|
partnerPhone=folio.mobile if folio.mobile else "",
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:id>/reservations",
|
||||||
|
],
|
||||||
|
"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,
|
||||||
|
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
||||||
|
if reservation.pwa_action_buttons
|
||||||
|
else {},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return res
|
||||||
@@ -69,6 +69,8 @@ class PmsReservationService(Component):
|
|||||||
else "",
|
else "",
|
||||||
checkinsRatio=reservation.checkins_ratio,
|
checkinsRatio=reservation.checkins_ratio,
|
||||||
outstanding=reservation.folio_id.pending_amount,
|
outstanding=reservation.folio_id.pending_amount,
|
||||||
|
pricelist=reservation.pricelist_id.name,
|
||||||
|
folioId=reservation.folio_id.id,
|
||||||
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
||||||
if reservation.pwa_action_buttons
|
if reservation.pwa_action_buttons
|
||||||
else {},
|
else {},
|
||||||
@@ -105,13 +107,14 @@ class PmsReservationService(Component):
|
|||||||
"GET",
|
"GET",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
output_param=Datamodel("pms.reservation.short.info"),
|
||||||
auth="public",
|
auth="public",
|
||||||
)
|
)
|
||||||
def get_reservation(self, reservation_id):
|
def get_reservation(self, reservation_id):
|
||||||
reservation = (
|
reservation = (
|
||||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||||
)
|
)
|
||||||
res = []
|
res = False
|
||||||
if not reservation:
|
if not reservation:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -145,8 +148,70 @@ class PmsReservationService(Component):
|
|||||||
else "",
|
else "",
|
||||||
checkinsRatio=reservation.checkins_ratio,
|
checkinsRatio=reservation.checkins_ratio,
|
||||||
outstanding=reservation.folio_id.pending_amount,
|
outstanding=reservation.folio_id.pending_amount,
|
||||||
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
pricelist=reservation.pricelist_id.name,
|
||||||
if reservation.pwa_action_buttons
|
folioId=reservation.folio_id.id,
|
||||||
else {},
|
pwaActionButtons={},
|
||||||
)
|
)
|
||||||
return res
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user