mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add several properties in query params
This commit is contained in:
committed by
Darío Lodeiros
parent
45f69330a7
commit
329f3e9186
@@ -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))
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user