mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms_api_rest: amenities and amenity types services
This commit is contained in:
@@ -30,3 +30,6 @@ from . import res_city_zip
|
||||
from . import pms_search_param
|
||||
from . import pms_ubication
|
||||
from . import pms_extra_bed
|
||||
|
||||
from . import pms_amenity_type
|
||||
from . import pms_amenity
|
||||
|
||||
18
pms_api_rest/datamodels/pms_amenity.py
Normal file
18
pms_api_rest/datamodels/pms_amenity.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsAmenitySearchParam(Datamodel):
|
||||
_name = "pms.amenity.search.param"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
pmsPropertyId = fields.Integer(required=True, allow_none=False)
|
||||
|
||||
|
||||
class PmsAmenityInfo(Datamodel):
|
||||
_name = "pms.amenity.info"
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
name = fields.String(required=True, allow_none=False)
|
||||
defaultCode = fields.String(required=False, allow_none=True)
|
||||
pmsAmenityTypeId = fields.Integer(required=True, allow_none=False)
|
||||
17
pms_api_rest/datamodels/pms_amenity_type.py
Normal file
17
pms_api_rest/datamodels/pms_amenity_type.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsAmenityTypeSearchParam(Datamodel):
|
||||
_name = "pms.amenity.type.search.param"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
pmsPropertyId = fields.Integer(required=True, allow_none=False)
|
||||
|
||||
|
||||
class PmsAmenityTypeInfo(Datamodel):
|
||||
_name = "pms.amenity.type.info"
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
name = fields.String(required=True, allow_none=False)
|
||||
pmsAmenityIds = fields.List(fields.Integer(), required=False)
|
||||
@@ -20,3 +20,4 @@ class PmsRoomInfo(Datamodel):
|
||||
roomTypeClassId = fields.Integer(required=False, allow_none=True)
|
||||
ubicationId = fields.Integer(required=False, allow_none=True)
|
||||
extraBedsAllowed = fields.Integer(required=False, allow_none=True)
|
||||
roomAmenityIds = fields.List(fields.Integer(), required=False)
|
||||
|
||||
@@ -16,3 +16,6 @@ from . import res_city_zip_service
|
||||
from . import pms_room_type_class_service
|
||||
from . import pms_ubication_service
|
||||
from . import pms_extra_beds_service
|
||||
|
||||
from . import pms_amenity_service
|
||||
from . import pms_amenity_type_service
|
||||
|
||||
82
pms_api_rest/services/pms_amenity_service.py
Normal file
82
pms_api_rest/services/pms_amenity_service.py
Normal file
@@ -0,0 +1,82 @@
|
||||
from odoo import _
|
||||
from odoo.exceptions import MissingError
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsAmenityService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.amenity.service"
|
||||
_usage = "amenities"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.amenity.search.param"),
|
||||
output_param=Datamodel("pms.amenity.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_amenities(self, amenities_search_param):
|
||||
domain = []
|
||||
if amenities_search_param.name:
|
||||
domain.append(("name", "like", amenities_search_param.name))
|
||||
if amenities_search_param.id:
|
||||
domain.append(("id", "=", amenities_search_param.id))
|
||||
if amenities_search_param.pmsPropertyId:
|
||||
domain.extend(
|
||||
[
|
||||
"|",
|
||||
("pms_property_ids", "in", amenities_search_param.pmsPropertyId),
|
||||
("pms_property_ids", "=", False),
|
||||
]
|
||||
)
|
||||
|
||||
result_amenities = []
|
||||
PmsAmenityInfo = self.env.datamodels["pms.amenity.info"]
|
||||
for amenity in self.env["pms.amenity"].search(
|
||||
domain,
|
||||
):
|
||||
|
||||
result_amenities.append(
|
||||
PmsAmenityInfo(
|
||||
id=amenity.id,
|
||||
name=amenity.name,
|
||||
defaultCode=amenity.default_code,
|
||||
pmsAmenityTypeId=amenity.pms_amenity_type_id.id,
|
||||
)
|
||||
)
|
||||
return result_amenities
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:amenity_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.amenity.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_amenity(self, amenity_id):
|
||||
amenity = self.env["pms.amenity"].search([("id", "=", amenity_id)])
|
||||
if amenity:
|
||||
PmsAmenityInfo = self.env.datamodels["pms.amenity.info"]
|
||||
return PmsAmenityInfo(
|
||||
id=amenity.id,
|
||||
name=amenity.name,
|
||||
defaultCode=amenity.default_code,
|
||||
pmsAmenityTypeId=amenity.pms_amenity_type_id.id,
|
||||
)
|
||||
else:
|
||||
raise MissingError(_("Amenity not found"))
|
||||
86
pms_api_rest/services/pms_amenity_type_service.py
Normal file
86
pms_api_rest/services/pms_amenity_type_service.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from odoo import _
|
||||
from odoo.exceptions import MissingError
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class PmsAmenityTypeService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.amenity.type.service"
|
||||
_usage = "amenity-types"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.amenity.type.search.param"),
|
||||
output_param=Datamodel("pms.amenity.type.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_amenity_types(self, amenity_types_search_param):
|
||||
domain = []
|
||||
if amenity_types_search_param.name:
|
||||
domain.append(("name", "like", amenity_types_search_param.name))
|
||||
if amenity_types_search_param.id:
|
||||
domain.append(("id", "=", amenity_types_search_param.id))
|
||||
if amenity_types_search_param.pmsPropertyId:
|
||||
domain.extend(
|
||||
[
|
||||
"|",
|
||||
(
|
||||
"pms_property_ids",
|
||||
"in",
|
||||
amenity_types_search_param.pmsPropertyId,
|
||||
),
|
||||
("pms_property_ids", "=", False),
|
||||
]
|
||||
)
|
||||
|
||||
result_amenity_types = []
|
||||
PmsAmenityTypeInfo = self.env.datamodels["pms.amenity.type.info"]
|
||||
for amenity_type in self.env["pms.amenity.type"].search(
|
||||
domain,
|
||||
):
|
||||
|
||||
result_amenity_types.append(
|
||||
PmsAmenityTypeInfo(
|
||||
id=amenity_type.id,
|
||||
name=amenity_type.name,
|
||||
pmsAmenityIds=amenity_type.pms_amenity_ids.ids,
|
||||
)
|
||||
)
|
||||
return result_amenity_types
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:amenity_type_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.amenity.type.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_amenity_type(self, amenity_type_id):
|
||||
amenity_type = self.env["pms.amenity.type"].search(
|
||||
[("id", "=", amenity_type_id)]
|
||||
)
|
||||
if amenity_type:
|
||||
PmsAmenityTypeInfo = self.env.datamodels["pms.amenity.type.info"]
|
||||
return PmsAmenityTypeInfo(
|
||||
id=amenity_type.id,
|
||||
name=amenity_type.name,
|
||||
pmsAmenityIds=amenity_type.pms_amenity_ids.ids,
|
||||
)
|
||||
else:
|
||||
raise MissingError(_("Amenity Type not found"))
|
||||
Reference in New Issue
Block a user