From fb4c9a83c139e780c1c42a9495af2c2fa2adc782 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Wed, 2 Nov 2022 19:49:57 +0100 Subject: [PATCH] [IMP] pms-api-rest: res. lines add price_day_total & price_day_total_services --- pms_api_rest/datamodels/pms_calendar.py | 3 ++- pms_api_rest/services/pms_calendar_service.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pms_api_rest/datamodels/pms_calendar.py b/pms_api_rest/datamodels/pms_calendar.py index 77ce98749..cb3575313 100644 --- a/pms_api_rest/datamodels/pms_calendar.py +++ b/pms_api_rest/datamodels/pms_calendar.py @@ -68,7 +68,8 @@ class PmsCalendarInfo(Datamodel): nextLineSplitted = fields.Boolean(required=False, allow_none=True) previousLineSplitted = fields.Boolean(required=False, allow_none=True) closureReason = fields.String(required=False, allow_none=True) - + priceDayTotal = fields.Number(required=False, allow_none=True) + priceDayTotalServices = fields.Number(required=False, allow_none=True) class PmsCalendarAlertsPerDay(Datamodel): _name = "pms.calendar.alerts.per.day" diff --git a/pms_api_rest/services/pms_calendar_service.py b/pms_api_rest/services/pms_calendar_service.py index 43ebcf0da..3222318b8 100644 --- a/pms_api_rest/services/pms_calendar_service.py +++ b/pms_api_rest/services/pms_calendar_service.py @@ -30,7 +30,12 @@ class PmsCalendarService(Component): count_nights = (date_to - date_from).days + 1 target_dates = [date_from + timedelta(days=x) for x in range(count_nights)] pms_property_id = calendar_search_param.pmsPropertyId - + subselect_sum_services_price = "(" \ + " SELECT COALESCE(SUM(s.price_day_total),0) price_day_total_services " \ + " FROM pms_service_line s " \ + " WHERE s.reservation_id = night.reservation_id " \ + " AND s.date = night.date AND NOT s.is_board_service " \ + " ) " selected_fields_mapper = { "id": "night.id", "state": "night.state", @@ -50,6 +55,8 @@ class PmsCalendarService(Component): "price_total": "reservation.price_total", "folio_pending_amount": "folio.pending_amount", "adults": "reservation.adults", + "price_day_total": "night.price_day_total", + "price_day_total_services": subselect_sum_services_price } selected_fields_sql = list(selected_fields_mapper.values()) selected_fields = list(selected_fields_mapper.keys()) @@ -132,6 +139,8 @@ class PmsCalendarService(Component): isLastNight=is_last_night, totalPrice=round(line["price_total"], 2), pendingPayment=round(line["folio_pending_amount"], 2), + priceDayTotal=round(line["price_day_total"], 0), + priceDayTotalServices=round(line["price_day_total_services"], 0), # TODO: line.reservation_id.message_needaction_counter is computed field, numNotifications=0, adults=line["adults"],