From f5316c3fba6fca0100ccf85241024f502ce83987 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Fri, 21 Jul 2023 18:13:11 +0200 Subject: [PATCH] [IMP] pms-api-rest: add free rooms by type @ calendar pricelist and rules service --- pms_api_rest/services/pms_calendar_service.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pms_api_rest/services/pms_calendar_service.py b/pms_api_rest/services/pms_calendar_service.py index 2697a149a..c8f1e2c7c 100644 --- a/pms_api_rest/services/pms_calendar_service.py +++ b/pms_api_rest/services/pms_calendar_service.py @@ -419,7 +419,22 @@ class PmsCalendarService(Component): AND ipp.record = pp.product_tmpl_id AND ipp.pms_property_id = %s ) - ) price + ) price, + (SELECT COUNT (1) + FROM pms_room r + WHERE r.room_type_id = dr.room_type_id AND r.active = true AND r.pms_property_id = 1 + AND NOT EXISTS (SELECT 1 + FROM pms_reservation_line + WHERE date = dr.date + AND occupies_availability = true + AND room_id = r.id + AND r.is_shared_room = false) + AND EXISTS (SELECT 1 + FROM pms_room + WHERE active = true + AND room_type_id = dr.room_type_id + AND pms_property_id = %s) + ) free_rooms FROM ( SELECT dates.date, rt_r.room_type_id, rt_r.product_id, rt_r.default_max_avail, rt_r.default_quota @@ -436,7 +451,9 @@ class PmsCalendarService(Component): FROM pms_room_type rt WHERE EXISTS ( SELECT 1 FROM pms_room - WHERE pms_property_id = %s AND room_type_id = rt.id) + WHERE pms_property_id = %s + AND room_type_id = rt.id + AND active = true) ) rt_r ) dr INNER JOIN product_product pp ON pp.id = dr.product_id @@ -452,6 +469,7 @@ class PmsCalendarService(Component): ORDER BY dr.room_type_id, dr.date; """, ( + calendar_search_param.pmsPropertyId, calendar_search_param.pmsPropertyId, date_from, date_to, @@ -468,6 +486,7 @@ class PmsCalendarService(Component): for index, item in enumerate(result): date = { "date": datetime.combine(item['date'], datetime.min.time()).isoformat(), + "freeRooms": item['free_rooms'], "pricelistItemId": item['pricelist_item_id'], "price": item['price'],