[IMP] pms_api_rest: get_reservations in pms_dashboard_service

This commit is contained in:
Sara Lago
2023-09-01 10:27:54 +02:00
committed by Darío Lodeiros
parent 21ce6ac762
commit 7511af32fc
2 changed files with 25 additions and 23 deletions

View File

@@ -3,16 +3,17 @@ from marshmallow import fields
from odoo.addons.datamodel.core import Datamodel from odoo.addons.datamodel.core import Datamodel
class PmsDashboardCheckinsSearchParam(Datamodel): class PmsDashboardPendingReservationsSearchParam(Datamodel):
_name = "pms.dashboard.checkins.search.param" _name = "pms.dashboard.pending.reservations.search.param"
dateTo = fields.String(required=False, allow_none=True) dateTo = fields.String(required=False, allow_none=True)
dateFrom = fields.String(required=False, allow_none=True) dateFrom = fields.String(required=False, allow_none=True)
class PmsDashboardCheckins(Datamodel): class PmsDashboardPendingReservations(Datamodel):
_name = "pms.dashboard.checkins" _name = "pms.dashboard.pending.reservations"
id = fields.Integer(required=True, allow_none=False) id = fields.Integer(required=True, allow_none=False)
checkinPartnerState = fields.String(required=False, allow_none=True) state = fields.String(required=False, allow_none=True)
date = fields.String(required=False, allow_none=True) reservationType = fields.String(required=False, allow_none=True)
checkin = fields.String(required=False, allow_none=True)

View File

@@ -16,36 +16,37 @@ class PmsDashboardServices(Component):
[ [
( (
[ [
"/checkins", "/reservations",
], ],
"GET", "GET",
) )
], ],
input_param=Datamodel("pms.dashboard.checkins.search.param"), input_param=Datamodel("pms.dashboard.pending.reservations.search.param"),
output_param=Datamodel("pms.dashboard.checkins", is_list=True), output_param=Datamodel("pms.dashboard.pending.reservations", is_list=True),
auth="jwt_api_pms", auth="jwt_api_pms",
) )
def get_checkins(self, pms_checkins_search_param): def get_reservations(self, pms_reservations_search_param):
date_from = fields.Date.from_string(pms_checkins_search_param.dateFrom) date_from = fields.Date.from_string(pms_reservations_search_param.dateFrom)
date_to = fields.Date.from_string(pms_checkins_search_param.dateTo) date_to = fields.Date.from_string(pms_reservations_search_param.dateTo)
domain = [ domain = [
("checkin", ">=", date_from), ("checkin", ">=", date_from),
("checkin", "<=", date_to), ("checkin", "<=", date_to),
("state", "in", ("confirm", "arrival_delayed")), ("state", "!=", "cancel"),
("reservation_type", "!=", "out") ("reservation_type", "!=", "out")
] ]
reservations = self.env["pms.reservation"].search(domain) reservations = self.env["pms.reservation"].search(domain)
PmsDashboardCheckins = self.env.datamodels["pms.dashboard.checkins"] PmsDashboardPendingReservations = self.env.datamodels["pms.dashboard.pending.reservations"]
result_checkins = [] result = []
for checkin_partner in reservations.checkin_partner_ids: for reservation in reservations:
result_checkins.append( result.append(
PmsDashboardCheckins( PmsDashboardPendingReservations(
id=checkin_partner.id, id=reservation.id,
checkinPartnerState=checkin_partner.state, state=reservation.state,
date=datetime.combine( checkin=datetime.combine(
checkin_partner.checkin, datetime.min.time() reservation.checkin, datetime.min.time()
).isoformat(), ).isoformat(),
reservationType=reservation.reservation_type,
) )
) )
return result_checkins return result