From f220a3d42c5722be55e0942c237e140d9a75b2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 15 Nov 2022 01:18:12 +0100 Subject: [PATCH] [FIX]pms_api_rest: ubications&room_type_class GET services by property --- .../services/pms_room_type_class_service.py | 42 ++++++++----------- .../services/pms_ubication_service.py | 31 +++++--------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/pms_api_rest/services/pms_room_type_class_service.py b/pms_api_rest/services/pms_room_type_class_service.py index 876ac23f9..8566d6d6e 100644 --- a/pms_api_rest/services/pms_room_type_class_service.py +++ b/pms_api_rest/services/pms_room_type_class_service.py @@ -23,36 +23,28 @@ class PmsRoomTypeClassService(Component): auth="jwt_api_pms", ) def get_room_type_class(self, room_type_class_search_param): - room_type_class_all_properties = self.env["pms.room.type.class"].search( - [("pms_property_ids", "=", False)] - ) if room_type_class_search_param.pmsPropertyIds: - room_type_class = set() - for index, prop in enumerate(room_type_class_search_param.pmsPropertyds): - room_type_class_with_query_property = self.env[ - "pms.room.type.class" - ].search([("pms_property_ids", "=", prop)]) - if index == 0: - room_type_class = set(room_type_class_with_query_property.ids) - else: - room_type_class = room_type_class.intersection( - set(room_type_class_with_query_property.ids) - ) - room_type_class_total = list( - set(list(room_type_class) + room_type_class_all_properties.ids) + room_type_classes = ( + self.env["pms.room"] + .search( + [ + ( + "pms_property_id", + "in", + room_type_class_search_param.pmsPropertyIds, + ) + ] + ) + .mapped("room_type_id") + .mapped("class_id") ) else: - room_type_class_total = list(room_type_class_all_properties.ids) - domain = [ - ("id", "in", room_type_class_total), - ] - + room_type_classes = self.env["pms.room.type.class"].search( + [("pms_property_ids", "=", False)] + ) result_room_type_class = [] PmsRoomTypeClassInfo = self.env.datamodels["pms.room.type.class.info"] - for room in self.env["pms.room.type.class"].search( - domain, - ): - + for room in room_type_classes: result_room_type_class.append( PmsRoomTypeClassInfo( id=room.id, diff --git a/pms_api_rest/services/pms_ubication_service.py b/pms_api_rest/services/pms_ubication_service.py index 124dd30e4..4e47d362a 100644 --- a/pms_api_rest/services/pms_ubication_service.py +++ b/pms_api_rest/services/pms_ubication_service.py @@ -23,33 +23,22 @@ class PmsUbicationService(Component): auth="jwt_api_pms", ) def get_ubications(self, ubication_search_param): - ubication_all_properties = self.env["pms.ubication"].search( - [("pms_property_ids", "=", False)] - ) if ubication_search_param.pmsPropertyIds: - ubication = set() - for index, prop in enumerate(ubication_search_param.pmsPropertyIds): - ubication_with_query_property = self.env["pms.ubication"].search( - [("pms_property_ids", "=", prop)] + ubications = ( + self.env["pms.room"] + .search( + [("pms_property_id", "in", ubication_search_param.pmsPropertyIds)] ) - if index == 0: - ubication = set(ubication_with_query_property.ids) - else: - ubication = ubication.intersection( - set(ubication_with_query_property.ids) - ) - ubication_total = list(set(list(ubication) + ubication_all_properties.ids)) + .mapped("ubication_id") + ) else: - ubication_total = list(ubication_all_properties.ids) - domain = [ - ("id", "in", ubication_total), - ] + ubications = self.env["pms.ubication"].search( + [("pms_property_ids", "=", False)] + ) result_ubications = [] PmsUbicationInfo = self.env.datamodels["pms.ubication.info"] - for ubication in self.env["pms.ubication"].search( - domain, - ): + for ubication in ubications: result_ubications.append( PmsUbicationInfo(