mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] pms_api_rest: add dashboard service
This commit is contained in:
committed by
Darío Lodeiros
parent
69bb04baa8
commit
21ce6ac762
@@ -60,3 +60,4 @@ from . import pms_mail
|
||||
from . import pms_notification
|
||||
from . import pms_reservation_message
|
||||
from . import pms_avail
|
||||
from . import pms_dashboard
|
||||
|
||||
18
pms_api_rest/datamodels/pms_dashboard.py
Normal file
18
pms_api_rest/datamodels/pms_dashboard.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsDashboardCheckinsSearchParam(Datamodel):
|
||||
_name = "pms.dashboard.checkins.search.param"
|
||||
dateTo = fields.String(required=False, allow_none=True)
|
||||
dateFrom = fields.String(required=False, allow_none=True)
|
||||
|
||||
|
||||
class PmsDashboardCheckins(Datamodel):
|
||||
_name = "pms.dashboard.checkins"
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
checkinPartnerState = fields.String(required=False, allow_none=True)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class PmsFolioSearchParam(Datamodel):
|
||||
dateTo = fields.String(required=False, allow_none=True)
|
||||
filter = fields.String(required=False, allow_none=True)
|
||||
filterByState = fields.String(required=False, allow_none=True)
|
||||
last = fields.Boolean(required=False, allow_none=True)
|
||||
|
||||
|
||||
class PmsFolioInfo(Datamodel):
|
||||
|
||||
@@ -42,3 +42,4 @@ from . import pms_invoice_service
|
||||
from . import pms_notification_service
|
||||
from . import pms_avail_service
|
||||
from . import pms_user_service
|
||||
from . import pms_dashboard_service
|
||||
|
||||
51
pms_api_rest/services/pms_dashboard_service.py
Normal file
51
pms_api_rest/services/pms_dashboard_service.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from odoo.addons.component.core import Component
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo import fields
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
class PmsDashboardServices(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.dashboard.service"
|
||||
_usage = "dashboard"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/checkins",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.dashboard.checkins.search.param"),
|
||||
output_param=Datamodel("pms.dashboard.checkins", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_checkins(self, pms_checkins_search_param):
|
||||
date_from = fields.Date.from_string(pms_checkins_search_param.dateFrom)
|
||||
date_to = fields.Date.from_string(pms_checkins_search_param.dateTo)
|
||||
|
||||
domain = [
|
||||
("checkin", ">=", date_from),
|
||||
("checkin", "<=", date_to),
|
||||
("state", "in", ("confirm", "arrival_delayed")),
|
||||
("reservation_type", "!=", "out")
|
||||
]
|
||||
reservations = self.env["pms.reservation"].search(domain)
|
||||
PmsDashboardCheckins = self.env.datamodels["pms.dashboard.checkins"]
|
||||
result_checkins = []
|
||||
for checkin_partner in reservations.checkin_partner_ids:
|
||||
result_checkins.append(
|
||||
PmsDashboardCheckins(
|
||||
id=checkin_partner.id,
|
||||
checkinPartnerState=checkin_partner.state,
|
||||
date=datetime.combine(
|
||||
checkin_partner.checkin, datetime.min.time()
|
||||
).isoformat(),
|
||||
)
|
||||
)
|
||||
return result_checkins
|
||||
@@ -99,6 +99,10 @@ class PmsFolioService(Component):
|
||||
domain_fields = list()
|
||||
pms_property_id = int(folio_search_param.pmsPropertyId)
|
||||
domain_fields.append(("pms_property_id", "=", pms_property_id))
|
||||
today = fields.Datetime.now()
|
||||
today = today.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if folio_search_param.last:
|
||||
domain_fields.append(("create_date", ">", today))
|
||||
|
||||
if folio_search_param.dateTo and folio_search_param.dateFrom:
|
||||
date_from = fields.Date.from_string(folio_search_param.dateFrom)
|
||||
@@ -182,11 +186,9 @@ class PmsFolioService(Component):
|
||||
else:
|
||||
domain = domain_fields
|
||||
result_folios = []
|
||||
|
||||
reservations_result = (
|
||||
self.env["pms.reservation"].search(domain).mapped("folio_id").ids
|
||||
)
|
||||
|
||||
PmsFolioShortInfo = self.env.datamodels["pms.folio.short.info"]
|
||||
for folio in self.env["pms.folio"].search(
|
||||
[("id", "in", reservations_result), ("reservation_type", "!=", "out")],
|
||||
|
||||
Reference in New Issue
Block a user