mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms-pwa: service folios
This commit is contained in:
committed by
Darío Lodeiros
parent
308c35f878
commit
0393752058
@@ -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
|
||||
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
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)
|
||||
@@ -27,8 +16,6 @@ class PmsFolioShortInfo(Datamodel):
|
||||
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))
|
||||
|
||||
@@ -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"
|
||||
@@ -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,
|
||||
@@ -106,17 +65,14 @@ class PmsFolioService(Component):
|
||||
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(
|
||||
[
|
||||
|
||||
@@ -11,6 +11,7 @@ class PmsReservationService(Component):
|
||||
_usage = "reservations"
|
||||
_collection = "pms.reservation.service"
|
||||
|
||||
# TODO: REMOVE
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -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))
|
||||
@@ -77,6 +78,7 @@ class PmsReservationService(Component):
|
||||
)
|
||||
)
|
||||
return res
|
||||
# END TODO: REMOVE
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
@@ -154,64 +156,3 @@ class PmsReservationService(Component):
|
||||
)
|
||||
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
|
||||
|
||||
BIN
pms_l10n_es/static/Models&ReservationCajonv2xD.zip
Normal file
BIN
pms_l10n_es/static/Models&ReservationCajonv2xD.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user