mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add room type class service
This commit is contained in:
@@ -4,6 +4,7 @@ from . import pms_folio
|
|||||||
|
|
||||||
from . import pms_room
|
from . import pms_room
|
||||||
from . import pms_room_type
|
from . import pms_room_type
|
||||||
|
from . import pms_room_type_class
|
||||||
|
|
||||||
from . import pms_reservation
|
from . import pms_reservation
|
||||||
|
|
||||||
|
|||||||
17
pms_api_rest/datamodels/pms_room_type_class.py
Normal file
17
pms_api_rest/datamodels/pms_room_type_class.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsRoomTypeClassSearchParam(Datamodel):
|
||||||
|
_name = "pms.room.type.class.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 PmsRoomTypeClassInfo(Datamodel):
|
||||||
|
_name = "pms.room.type.class.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)
|
||||||
@@ -9,3 +9,4 @@ from . import pms_property_service
|
|||||||
from . import pms_login_service
|
from . import pms_login_service
|
||||||
from . import pms_pricelist_service
|
from . import pms_pricelist_service
|
||||||
from . import pms_availability_plan_service
|
from . import pms_availability_plan_service
|
||||||
|
from . import pms_room_type_class_service
|
||||||
|
|||||||
63
pms_api_rest/services/pms_room_type_class_service.py
Normal file
63
pms_api_rest/services/pms_room_type_class_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 PmsRoomTypeClassService(Component):
|
||||||
|
_inherit = "base.rest.service"
|
||||||
|
_name = "pms.room.type.class.service"
|
||||||
|
_usage = "room-type-class"
|
||||||
|
_collection = "pms.services"
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.room.type.class.search.param"),
|
||||||
|
output_param=Datamodel("pms.room.type.class.info", is_list=True),
|
||||||
|
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.pms_property_ids:
|
||||||
|
room_type_class = set()
|
||||||
|
for index, prop in enumerate(room_type_class_search_param.pms_property_ids):
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
room_type_class_total = list(room_type_class_all_properties.ids)
|
||||||
|
domain = [
|
||||||
|
("id", "in", room_type_class_total),
|
||||||
|
]
|
||||||
|
|
||||||
|
result_room_type_class = []
|
||||||
|
PmsRoomTypeClassInfo = self.env.datamodels["pms.room.type.class.info"]
|
||||||
|
for room in self.env["pms.room.type.class"].search(
|
||||||
|
domain,
|
||||||
|
):
|
||||||
|
|
||||||
|
result_room_type_class.append(
|
||||||
|
PmsRoomTypeClassInfo(
|
||||||
|
id=room.id,
|
||||||
|
name=room.name,
|
||||||
|
pms_property_ids=room.pms_property_ids.mapped("id"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_room_type_class
|
||||||
Reference in New Issue
Block a user