mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] pms-pwa: nested reservation lines
This commit is contained in:
committed by
Darío Lodeiros
parent
04095199dc
commit
f1bfaf45ee
@@ -1,2 +1,2 @@
|
||||
from . import reservation_services
|
||||
from . import folio_services
|
||||
from . import room_services
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class PmsFolioService(Component):
|
||||
@@ -33,18 +34,32 @@ class PmsFolioService(Component):
|
||||
PmsFolioShortInfo = self.env.datamodels["pms.folio.short.info"]
|
||||
for folio in (
|
||||
self.env["pms.folio"]
|
||||
.sudo()
|
||||
.search(
|
||||
.sudo()
|
||||
.search(
|
||||
domain,
|
||||
)
|
||||
):
|
||||
reservations = []
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation_lines = []
|
||||
for reservation_line in reservation.reservation_line_ids:
|
||||
reservation_lines.append(
|
||||
{
|
||||
"id": reservation_line.id,
|
||||
"date": reservation_line.date,
|
||||
"roomId": reservation_line.room_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
reservations.append(
|
||||
{
|
||||
"id": reservation.id,
|
||||
"checkin": datetime.combine(reservation.checkin, datetime.min.time()).isoformat(),
|
||||
"checkout": datetime.combine(reservation.checkout, datetime.min.time()).isoformat(),
|
||||
"checkin": datetime.combine(
|
||||
reservation.checkin, datetime.min.time()
|
||||
).isoformat(),
|
||||
"checkout": datetime.combine(
|
||||
reservation.checkout, datetime.min.time()
|
||||
).isoformat(),
|
||||
"preferredRoomId": reservation.preferred_room_id.name
|
||||
if reservation.preferred_room_id
|
||||
else "",
|
||||
@@ -57,6 +72,7 @@ class PmsFolioService(Component):
|
||||
"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
|
||||
}
|
||||
)
|
||||
result_folios.append(
|
||||
@@ -66,7 +82,9 @@ class PmsFolioService(Component):
|
||||
partnerName=folio.partner_name if folio.partner_name else "",
|
||||
partnerPhone=folio.mobile if folio.mobile else "",
|
||||
partnerEmail=folio.email if folio.email else "",
|
||||
saleChannel=folio.channel_type_id.name if folio.channel_type_id else "",
|
||||
saleChannel=folio.channel_type_id.name
|
||||
if folio.channel_type_id
|
||||
else "",
|
||||
agency=folio.agency_id.name if folio.agency_id else "",
|
||||
state=dict(folio.fields_get(["state"])["state"]["selection"])[
|
||||
folio.state
|
||||
@@ -91,9 +109,7 @@ class PmsFolioService(Component):
|
||||
auth="public",
|
||||
)
|
||||
def get_reservations(self, folio_id):
|
||||
folio = (
|
||||
self.env["pms.folio"].sudo().search([("id", "=", folio_id)])
|
||||
)
|
||||
folio = self.env["pms.folio"].sudo().search([("id", "=", folio_id)])
|
||||
res = []
|
||||
if not folio.reservation_ids:
|
||||
pass
|
||||
@@ -117,23 +133,22 @@ class PmsFolioService(Component):
|
||||
partnerRequests=reservation.partner_requests
|
||||
if reservation.partner_requests
|
||||
else "",
|
||||
state=dict(reservation.fields_get(["state"])["state"]["selection"])[
|
||||
reservation.state
|
||||
],
|
||||
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 "",
|
||||
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,
|
||||
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
||||
if reservation.pwa_action_buttons
|
||||
else {},
|
||||
)
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
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
|
||||
|
||||
|
||||
class PmsReservationService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.reservation.service"
|
||||
_usage = "reservations"
|
||||
_collection = "pms.reservation.service"
|
||||
|
||||
# TODO: REMOVE
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.reservation.search.param"),
|
||||
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
||||
auth="public",
|
||||
)
|
||||
def get_reservations(self, reservation_search_param):
|
||||
domain = []
|
||||
if reservation_search_param.name:
|
||||
domain.append(("name", "like", reservation_search_param.name))
|
||||
if reservation_search_param.id:
|
||||
domain.append(("id", "=", reservation_search_param.id))
|
||||
res = []
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
for reservation in (
|
||||
self.env["pms.reservation"]
|
||||
.sudo()
|
||||
.search(
|
||||
domain,
|
||||
)
|
||||
):
|
||||
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
|
||||
# END TODO: REMOVE
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>/cancellation",
|
||||
],
|
||||
"POST",
|
||||
)
|
||||
],
|
||||
auth="public",
|
||||
)
|
||||
def cancel_reservation(self, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
reservation.sudo().action_cancel()
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.reservation.short.info"),
|
||||
auth="public",
|
||||
)
|
||||
def get_reservation(self, reservation_id):
|
||||
reservation = (
|
||||
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
|
||||
)
|
||||
res = False
|
||||
if not reservation:
|
||||
pass
|
||||
else:
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
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,
|
||||
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={},
|
||||
)
|
||||
return res
|
||||
|
||||
49
pms_api_rest/services/room_services.py
Normal file
49
pms_api_rest/services/room_services.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from datetime import datetime
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsFolioService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.room.service"
|
||||
_usage = "rooms"
|
||||
_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 get_rooms(self, room_search_param):
|
||||
domain = []
|
||||
if room_search_param.name:
|
||||
domain.append(("name", "like", room_search_param.name))
|
||||
if room_search_param.id:
|
||||
domain.append(("id", "=", room_search_param.id))
|
||||
result_rooms = []
|
||||
PmsRoomShortInfo = self.env.datamodels["pms.room.short.info"]
|
||||
for room in (
|
||||
self.env["pms.room"]
|
||||
.sudo()
|
||||
.search(
|
||||
domain,
|
||||
)
|
||||
):
|
||||
|
||||
result_rooms.append(
|
||||
PmsRoomShortInfo(
|
||||
id=room.id,
|
||||
name=room.name,
|
||||
)
|
||||
)
|
||||
return result_rooms
|
||||
Reference in New Issue
Block a user