mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add ubication service
This commit is contained in:
@@ -22,3 +22,4 @@ from . import pms_pricelist_item
|
||||
from . import pms_availability_plan
|
||||
from . import pms_availability_plan_rule
|
||||
from . import pms_search_param
|
||||
from . import pms_ubication
|
||||
|
||||
17
pms_api_rest/datamodels/pms_ubication.py
Normal file
17
pms_api_rest/datamodels/pms_ubication.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsUbicationSearchParam(Datamodel):
|
||||
_name = "pms.ubication.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 PmsUbicationInfo(Datamodel):
|
||||
_name = "pms.ubication.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)
|
||||
@@ -10,3 +10,4 @@ from . import pms_login_service
|
||||
from . import pms_pricelist_service
|
||||
from . import pms_availability_plan_service
|
||||
from . import pms_room_type_class_service
|
||||
from . import pms_ubication_service
|
||||
|
||||
63
pms_api_rest/services/pms_ubication_service.py
Normal file
63
pms_api_rest/services/pms_ubication_service.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsUbicationService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.ubication.service"
|
||||
_usage = "ubication"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.ubication.search.param"),
|
||||
output_param=Datamodel("pms.ubication.info", is_list=True),
|
||||
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.pms_property_ids:
|
||||
ubication = set()
|
||||
for index, prop in enumerate(ubication_search_param.pms_property_ids):
|
||||
ubication_with_query_property = self.env[
|
||||
"pms.ubication"
|
||||
].search([("pms_property_ids", "=", prop)])
|
||||
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)
|
||||
)
|
||||
else:
|
||||
ubication_total = list(ubication_all_properties.ids)
|
||||
domain = [
|
||||
("id", "in", ubication_total),
|
||||
]
|
||||
|
||||
result_ubications = []
|
||||
PmsUbicationInfo = self.env.datamodels["pms.ubication.info"]
|
||||
for room in self.env["pms.ubication"].search(
|
||||
domain,
|
||||
):
|
||||
|
||||
result_ubications.append(
|
||||
PmsUbicationInfo(
|
||||
id=room.id,
|
||||
name=room.name,
|
||||
pms_property_ids=room.pms_property_ids.mapped("id"),
|
||||
)
|
||||
)
|
||||
return result_ubications
|
||||
Reference in New Issue
Block a user