From 3f97281dc47bbfe27188dc537e405f20ef9b94a1 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Thu, 3 Feb 2022 17:28:13 +0100 Subject: [PATCH] [IMP] pms_api_rest: show records with all properties when it isn't specified --- pms_api_rest/datamodels/pms_calendar.py | 2 +- .../services/pms_pricelist_service.py | 27 +++++++++++-------- .../services/pms_room_type_services.py | 27 +++++++++++-------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/pms_api_rest/datamodels/pms_calendar.py b/pms_api_rest/datamodels/pms_calendar.py index 878a11ca6..05d4cb7b4 100644 --- a/pms_api_rest/datamodels/pms_calendar.py +++ b/pms_api_rest/datamodels/pms_calendar.py @@ -14,7 +14,7 @@ class PmsCalendarSwapInfo(Datamodel): swapTo = fields.String(required=True, allow_none=False) roomIdA = fields.Integer(required=True, allow_none=False) roomIdB = fields.Integer(required=True, allow_none=False) - pms_property_id = fields.Integer(required=True, allow_none=False) + pms_property_id = fields.Integer(required=False, allow_none=True) class PmsCalendarSearchParam(Datamodel): diff --git a/pms_api_rest/services/pms_pricelist_service.py b/pms_api_rest/services/pms_pricelist_service.py index 6dfb243f9..179ef5a70 100644 --- a/pms_api_rest/services/pms_pricelist_service.py +++ b/pms_api_rest/services/pms_pricelist_service.py @@ -29,18 +29,23 @@ class PmsPricelistService(Component): pricelists_all_properties = self.env["product.pricelist"].search( [("pms_property_ids", "=", False)] ) - pricelists = set() - for index, prop in enumerate(pms_search_param.pms_property_ids): - pricelists_with_query_property = self.env["product.pricelist"].search( - [("pms_property_ids", "=", prop)] - ) - if index == 0: - pricelists = set(pricelists_with_query_property.ids) - else: - pricelists = pricelists.intersection( - set(pricelists_with_query_property.ids) + if pms_search_param.pms_property_ids: + pricelists = set() + for index, prop in enumerate(pms_search_param.pms_property_ids): + pricelists_with_query_property = self.env["product.pricelist"].search( + [("pms_property_ids", "=", prop)] ) - pricelists_total = list(set(list(pricelists) + pricelists_all_properties.ids)) + if index == 0: + pricelists = set(pricelists_with_query_property.ids) + else: + pricelists = pricelists.intersection( + set(pricelists_with_query_property.ids) + ) + pricelists_total = list( + set(list(pricelists) + pricelists_all_properties.ids) + ) + else: + pricelists_total = list(pricelists_all_properties.ids) domain = [ ("id", "in", pricelists_total), ] diff --git a/pms_api_rest/services/pms_room_type_services.py b/pms_api_rest/services/pms_room_type_services.py index ade44d8d7..544aea0a2 100644 --- a/pms_api_rest/services/pms_room_type_services.py +++ b/pms_api_rest/services/pms_room_type_services.py @@ -26,18 +26,23 @@ class PmsRoomTypeService(Component): room_type_all_properties = self.env["pms.room.type"].search( [("pms_property_ids", "=", False)] ) - room_types = set() - for index, prop in enumerate(room_type_search_param.pms_property_ids): - room_types_with_query_property = self.env["pms.room.type"].search( - [("pms_property_ids", "=", prop)] - ) - if index == 0: - room_types = set(room_types_with_query_property.ids) - else: - room_types = room_types.intersection( - set(room_types_with_query_property.ids) + if room_type_search_param.pms_property_ids: + room_types = set() + for index, prop in enumerate(room_type_search_param.pms_property_ids): + room_types_with_query_property = self.env["pms.room.type"].search( + [("pms_property_ids", "=", prop)] ) - room_types_total = list(set(list(room_types) + room_type_all_properties.ids)) + if index == 0: + room_types = set(room_types_with_query_property.ids) + else: + room_types = room_types.intersection( + set(room_types_with_query_property.ids) + ) + room_types_total = list( + set(list(room_types) + room_type_all_properties.ids) + ) + else: + room_types_total = list(room_type_all_properties.ids) domain = [ ("id", "in", room_types_total), ]