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,4 +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
|
||||
from . import pms_room_short_info
|
||||
from . import pms_room_search_param
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from marshmallow import Schema, fields
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsReservationSchema(Schema):
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
|
||||
|
||||
class PmsFolioShortInfo(Datamodel):
|
||||
_name = "pms.folio.short.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsReservationShortInfo(Datamodel):
|
||||
_name = "pms.reservation.short.info"
|
||||
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
partner = fields.String(required=False, allow_none=True)
|
||||
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)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
partnerRequests = fields.String(required=False, allow_none=True)
|
||||
state = fields.String(required=False, allow_none=True)
|
||||
priceTotal = fields.Float(required=False, allow_none=True)
|
||||
adults = fields.Integer(required=False, allow_none=True)
|
||||
channelTypeId = fields.String(required=False, allow_none=True)
|
||||
agencyId = fields.String(required=False, allow_none=True)
|
||||
boardServiceId = fields.String(required=False, allow_none=True)
|
||||
checkinsRatio = fields.Float(required=False, allow_none=True)
|
||||
outstanding = fields.Float(required=False, allow_none=True)
|
||||
pricelist = fields.String(required=False, allow_none=True)
|
||||
folioId = fields.Integer(required=False, allow_none=True)
|
||||
pwaActionButtons = fields.Dict(required=False, allow_none=True)
|
||||
@@ -3,8 +3,8 @@ from marshmallow import fields
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsReservationSearchParam(Datamodel):
|
||||
_name = "pms.reservation.search.param"
|
||||
class PmsRoomSearchParam(Datamodel):
|
||||
_name = "pms.room.search.param"
|
||||
|
||||
id = fields.Integer(required=False, allow_none=False)
|
||||
name = fields.String(required=False, allow_none=False)
|
||||
9
pms_api_rest/datamodels/pms_room_short_info.py
Normal file
9
pms_api_rest/datamodels/pms_room_short_info.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsRoomShortInfo(Datamodel):
|
||||
_name = "pms.room.short.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
@@ -1,3 +1,2 @@
|
||||
from . import res_users
|
||||
from . import jwt_access_token
|
||||
from . import pms_reservation
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import json
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PmsReservation(models.Model):
|
||||
_inherit = "pms.reservation"
|
||||
|
||||
pwa_action_buttons = fields.Char(compute="_compute_pwa_action_buttons")
|
||||
|
||||
def _compute_pwa_action_buttons(self):
|
||||
"""Return ordered button list, where the first button is
|
||||
the preditive action, the next are active actions:
|
||||
- "Assign": Predictive: Reservation by assign
|
||||
Active- Idem
|
||||
- "checkin": Predictive- state 'confirm' and checkin day
|
||||
Active- Idem and assign
|
||||
- "checkout": Predictive- Pay, onboard and checkout day
|
||||
Active- Onboard and checkout day
|
||||
- "Paymen": Predictive- Onboard and pending amount > 0
|
||||
Active- pending amount > 0
|
||||
- "Invoice": Predictive- qty invoice > 0, onboard, pending amount = 0
|
||||
Active- qty invoice > 0
|
||||
- "Cancel": Predictive- Never
|
||||
Active- state in draft, confirm, onboard, full onboard
|
||||
"""
|
||||
for reservation in self:
|
||||
active_buttons = {}
|
||||
for k in ["Assign", "Checkin", "Checkout", "Payment", "Invoice", "Cancel"]:
|
||||
if k == "Assign":
|
||||
if reservation.to_assign:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Checkin":
|
||||
if reservation.allowed_checkin:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Checkout":
|
||||
if reservation.allowed_checkout:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Payment":
|
||||
if reservation.folio_pending_amount > 0:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Invoice":
|
||||
if reservation.invoice_status == "to invoice":
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Cancel":
|
||||
if reservation.allowed_cancel:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
|
||||
reservation.pwa_action_buttons = json.dumps(active_buttons)
|
||||
@@ -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