mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms-api-rest: fix property, feeds, folio & dashboard services 4 dashboard
This commit is contained in:
committed by
Darío Lodeiros
parent
561f0c4b18
commit
381fa0f555
@@ -67,6 +67,7 @@ class PmsFolioShortInfo(Datamodel):
|
||||
paymentStateCode = fields.String(required=False, allow_none=True)
|
||||
paymentStateDescription = fields.String(required=False, allow_none=True)
|
||||
reservations = fields.List(fields.Dict(required=False, allow_none=True))
|
||||
numReservations = fields.Integer(required=False, allow_none=True)
|
||||
reservationType = fields.String(required=False, allow_none=True)
|
||||
closureReasonId = fields.Integer(required=False, allow_none=True)
|
||||
agencyId = fields.Integer(required=False, allow_none=True)
|
||||
|
||||
@@ -12,6 +12,7 @@ class PmsPropertyInfo(Datamodel):
|
||||
_name = "pms.property.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
stateName = fields.String(required=False, allow_none=True)
|
||||
company = fields.String(required=False, allow_none=True)
|
||||
defaultPricelistId = fields.Integer(required=False, allow_none=True)
|
||||
colorOptionConfig = fields.String(required=False, allow_none=True)
|
||||
|
||||
@@ -33,7 +33,7 @@ class PmsFeedRss(Component):
|
||||
description=rss.description,
|
||||
publishDate=str(rss.publish_date),
|
||||
author=rss.author if rss.author else "",
|
||||
imageUrl=rss.image_url if rss.image_url else "",
|
||||
imageUrl="https://www.roomdoo.com/wp-content/uploads/2021/09/hotel-roomdoo.png"
|
||||
)
|
||||
)
|
||||
return result_rss
|
||||
|
||||
@@ -74,7 +74,6 @@ class PmsDashboardServices(Component):
|
||||
)
|
||||
return pending_reservations
|
||||
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -133,7 +132,7 @@ class PmsDashboardServices(Component):
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
|
||||
auth="jwt_api_pms",
|
||||
input_param=Datamodel("pms.dashboard.range.dates.search.param"),
|
||||
output_param=Datamodel("pms.dashboard.state.rooms", is_list=True),
|
||||
)
|
||||
@@ -210,9 +209,9 @@ class PmsDashboardServices(Component):
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
|
||||
input_param=Datamodel("pms.dashboard.range.dates.search.param"),
|
||||
output_param=Datamodel("pms.dashboard.state.rooms", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_reservations_by_sale_channel(self, pms_dashboard_search_param):
|
||||
dateFrom = fields.Date.from_string(pms_dashboard_search_param.dateFrom)
|
||||
@@ -373,7 +372,7 @@ class PmsDashboardServices(Component):
|
||||
f"""
|
||||
SELECT COUNT(1) new_folios
|
||||
FROM pms_folio f
|
||||
WHERE f.create_date = %s
|
||||
WHERE DATE(f.create_date) = %s
|
||||
AND f.state != 'cancel'
|
||||
AND f.pms_property_id = %s
|
||||
AND f.reservation_type NOT IN ('out', 'staff')
|
||||
@@ -523,6 +522,7 @@ class PmsDashboardServices(Component):
|
||||
|
||||
input_param=Datamodel("pms.dashboard.range.dates.search.param"),
|
||||
output_param=Datamodel("pms.dashboard.state.rooms", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_occupied_rooms(self, pms_dashboard_search_param):
|
||||
dateFrom = fields.Date.from_string(pms_dashboard_search_param.dateFrom)
|
||||
@@ -565,18 +565,17 @@ class PmsDashboardServices(Component):
|
||||
)
|
||||
return occupied_rooms_result
|
||||
|
||||
|
||||
@restapi.method([
|
||||
(
|
||||
[
|
||||
"/daily-billings",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
|
||||
(
|
||||
[
|
||||
"/daily-billings",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.dashboard.range.dates.search.param"),
|
||||
output_param=Datamodel("pms.dashboard.state.rooms", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_daily_billings(self, pms_dashboard_search_param):
|
||||
dateFrom = fields.Date.from_string(pms_dashboard_search_param.dateFrom)
|
||||
@@ -618,3 +617,78 @@ class PmsDashboardServices(Component):
|
||||
)
|
||||
)
|
||||
return result_daily_billings
|
||||
|
||||
@restapi.method([
|
||||
(
|
||||
[
|
||||
"/last-received-folios",
|
||||
],
|
||||
"GET",
|
||||
),
|
||||
],
|
||||
input_param=Datamodel("pms.folio.search.param", is_list=False),
|
||||
output_param=Datamodel("pms.folio.short.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_last_received_folios(self, pms_folio_search_param):
|
||||
result_folios = []
|
||||
PmsFolioShortInfo = self.env.datamodels["pms.folio.short.info"]
|
||||
for folio in self.env['pms.folio'].search(
|
||||
[
|
||||
("first_checkin", ">=", datetime.now().date()),
|
||||
("pms_property_id", "=", pms_folio_search_param.pmsPropertyId),
|
||||
],
|
||||
limit=pms_folio_search_param.limit,
|
||||
offset=pms_folio_search_param.offset,
|
||||
order="create_date desc",
|
||||
):
|
||||
print(folio.id)
|
||||
result_folios.append(
|
||||
PmsFolioShortInfo(
|
||||
id=folio.id,
|
||||
name=folio.name,
|
||||
state=folio.state,
|
||||
partnerName=folio.partner_name if folio.partner_name else None,
|
||||
partnerPhone=folio.mobile if folio.mobile else None,
|
||||
partnerEmail=folio.email if folio.email else None,
|
||||
amountTotal=round(folio.amount_total, 2),
|
||||
pendingAmount=round(folio.pending_amount, 2),
|
||||
paymentStateCode=folio.payment_state,
|
||||
paymentStateDescription=dict(
|
||||
folio.fields_get(["payment_state"])["payment_state"][
|
||||
"selection"
|
||||
]
|
||||
)[folio.payment_state],
|
||||
numReservations=len(folio.reservation_ids),
|
||||
reservationType=folio.reservation_type,
|
||||
closureReasonId=folio.closure_reason_id,
|
||||
agencyId=folio.agency_id.id if folio.agency_id else None,
|
||||
pricelistId=folio.pricelist_id.id if folio.pricelist_id else None,
|
||||
saleChannelId=folio.sale_channel_origin_id.id
|
||||
if folio.sale_channel_origin_id
|
||||
else None,
|
||||
firstCheckin=str(folio.first_checkin),
|
||||
lastCheckout=str(folio.last_checkout),
|
||||
createHour=folio.create_date.strftime("%H:%M"),
|
||||
)
|
||||
)
|
||||
return result_folios
|
||||
|
||||
@restapi.method([
|
||||
(
|
||||
[
|
||||
"/num-last-received-folios",
|
||||
],
|
||||
"GET",
|
||||
),
|
||||
],
|
||||
input_param=Datamodel("pms.folio.search.param", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_num_last_received_folios(self, pms_folio_search_param):
|
||||
return self.env['pms.folio'].search_count(
|
||||
[
|
||||
("first_checkin", ">=", datetime.now().date()),
|
||||
("pms_property_id", "=", pms_folio_search_param.pmsPropertyId),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -132,6 +132,13 @@ class PmsFolioService(Component):
|
||||
domain_fields.append(("folio_id", "in", folio_ids))
|
||||
|
||||
domain_filter = list()
|
||||
if folio_search_param.last:
|
||||
domain_filter.append(
|
||||
[
|
||||
("checkin", ">=", fields.Date.today())
|
||||
]
|
||||
)
|
||||
|
||||
if folio_search_param.filter:
|
||||
target = folio_search_param.filter
|
||||
if "@" in target:
|
||||
|
||||
@@ -29,10 +29,14 @@ class PmsPropertyService(Component):
|
||||
for prop in self.env["pms.property"].search(
|
||||
domain,
|
||||
):
|
||||
state_name = False
|
||||
if prop.state_id:
|
||||
state_name = self.env['res.country.state'].search([('id', '=', prop.state_id.id)]).name
|
||||
result_properties.append(
|
||||
PmsPropertyInfo(
|
||||
id=prop.id,
|
||||
name=prop.name,
|
||||
stateName=state_name if state_name else None,
|
||||
defaultPricelistId=prop.default_pricelist_id.id,
|
||||
colorOptionConfig=prop.color_option_config,
|
||||
preReservationColor=prop.pre_reservation_color,
|
||||
|
||||
Reference in New Issue
Block a user