diff --git a/pms_api_rest/datamodels/pms_pricelist.py b/pms_api_rest/datamodels/pms_pricelist.py index 6f2fd1d43..0b67c86b5 100644 --- a/pms_api_rest/datamodels/pms_pricelist.py +++ b/pms_api_rest/datamodels/pms_pricelist.py @@ -7,4 +7,4 @@ class PmsPricelistInfo(Datamodel): _name = "pms.pricelist.info" id = fields.Integer(required=False, allow_none=True) name = fields.String(required=False, allow_none=True) - pms_property_id = fields.Integer(required=False, allow_none=True) + pms_property_ids = fields.List(fields.Integer(required=False, allow_none=True)) diff --git a/pms_api_rest/datamodels/pms_room.py b/pms_api_rest/datamodels/pms_room.py index ae9ed3ace..61825ea49 100644 --- a/pms_api_rest/datamodels/pms_room.py +++ b/pms_api_rest/datamodels/pms_room.py @@ -7,7 +7,7 @@ class PmsRoomSearchParam(Datamodel): _name = "pms.room.search.param" id = fields.Integer(required=False, allow_none=True) name = fields.String(required=False, allow_none=True) - pms_property_id = fields.Integer(required=True, allow_none=False) + pms_property_id = fields.Integer(required=False, allow_none=True) class PmsRoomInfo(Datamodel): diff --git a/pms_api_rest/datamodels/pms_room_type.py b/pms_api_rest/datamodels/pms_room_type.py index c1bd369dc..f0f65e216 100644 --- a/pms_api_rest/datamodels/pms_room_type.py +++ b/pms_api_rest/datamodels/pms_room_type.py @@ -7,9 +7,11 @@ class PmsRoomTypeSearchParam(Datamodel): _name = "pms.room.type.search.param" id = fields.Integer(required=False, allow_none=True) name = fields.String(required=False, allow_none=True) + pms_property_ids = fields.List(fields.Integer(), required=False) class PmsRoomTypeInfo(Datamodel): _name = "pms.room.type.info" id = fields.Integer(required=False, allow_none=True) name = fields.String(required=False, allow_none=True) + pms_property_ids = fields.List(fields.Integer(), required=False) diff --git a/pms_api_rest/datamodels/pms_search_param.py b/pms_api_rest/datamodels/pms_search_param.py index 03bdd07b5..f71a4fe2d 100644 --- a/pms_api_rest/datamodels/pms_search_param.py +++ b/pms_api_rest/datamodels/pms_search_param.py @@ -6,4 +6,5 @@ from odoo.addons.datamodel.core import Datamodel class PmsSearchParam(Datamodel): _name = "pms.search.param" - pms_property_id = fields.Integer(required=True, allow_none=False) + pms_property_id = fields.Integer(required=False, allow_none=True) + pms_property_ids = fields.List(fields.Integer(), required=False) diff --git a/pms_api_rest/services/pms_pricelist_service.py b/pms_api_rest/services/pms_pricelist_service.py index fa044f284..6dfb243f9 100644 --- a/pms_api_rest/services/pms_pricelist_service.py +++ b/pms_api_rest/services/pms_pricelist_service.py @@ -20,20 +20,31 @@ class PmsPricelistService(Component): "GET", ) ], - input_param=Datamodel("pms.pricelist.info", is_list=False), + input_param=Datamodel("pms.search.param", is_list=False), output_param=Datamodel("pms.pricelist.info", is_list=True), auth="jwt_api_pms", ) - def get_pricelists(self, pricelist_info_search_param, **args): - domain = [] - if pricelist_info_search_param.pms_property_id: - domain.append( - ( - "pms_property_ids", - "in", - [pricelist_info_search_param.pms_property_id], - ) + def get_pricelists(self, pms_search_param, **args): + + 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) + ) + pricelists_total = list(set(list(pricelists) + pricelists_all_properties.ids)) + domain = [ + ("id", "in", pricelists_total), + ] + PmsPricelistInfo = self.env.datamodels["pms.pricelist.info"] result_pricelists = [] for pricelist in self.env["product.pricelist"].search(domain): @@ -41,6 +52,7 @@ class PmsPricelistService(Component): PmsPricelistInfo( id=pricelist.id, name=pricelist.name, + pms_property_ids=pricelist.pms_property_ids.mapped("id"), ) ) return result_pricelists diff --git a/pms_api_rest/services/pms_room_type_services.py b/pms_api_rest/services/pms_room_type_services.py index a15645f70..ade44d8d7 100644 --- a/pms_api_rest/services/pms_room_type_services.py +++ b/pms_api_rest/services/pms_room_type_services.py @@ -18,16 +18,30 @@ class PmsRoomTypeService(Component): "GET", ) ], - input_param=Datamodel("pms.room.search.param"), + input_param=Datamodel("pms.room.type.search.param"), output_param=Datamodel("pms.room.info", is_list=True), auth="jwt_api_pms", ) def get_room_types(self, room_type_search_param): - domain = [] - if room_type_search_param.name: - domain.append(("name", "like", room_type_search_param.name)) - if room_type_search_param.id: - domain.append(("id", "=", room_type_search_param.id)) + 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) + ) + room_types_total = list(set(list(room_types) + room_type_all_properties.ids)) + domain = [ + ("id", "in", room_types_total), + ] + result_rooms = [] PmsRoomTypeInfo = self.env.datamodels["pms.room.type.info"] for room in self.env["pms.room.type"].search( @@ -38,6 +52,7 @@ class PmsRoomTypeService(Component): PmsRoomTypeInfo( id=room.id, name=room.name, + pms_property_ids=room.pms_property_ids.mapped("id"), ) ) return result_rooms