-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
322 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from . import pms_reservation_short_info | ||
from . import pms_reservation_search_param | ||
from . import pms_folio_short_info | ||
from . import pms_folio_search_param |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import reservation_services | ||
from . import folio_services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.