Skip to content

Commit

Permalink
[ADD] pms_api_rest: add room type services
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Nov 25, 2021
1 parent d5c9d6e commit e60cf71
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions pms_api_rest/datamodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import pms_folio_info

from . import pms_room_info
from . import pms_room_type_info
from . import pms_room_search_param

from . import pms_reservation_info
Expand Down
9 changes: 9 additions & 0 deletions pms_api_rest/datamodels/pms_room_type_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


class PmsRoomTypeInfo(Datamodel):
_name = "pms.room.type.info"
id = fields.Integer(required=False, allow_none=True)
name = fields.String(required=False, allow_none=True)
9 changes: 9 additions & 0 deletions pms_api_rest/datamodels/pms_room_type_search_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


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)
1 change: 1 addition & 0 deletions pms_api_rest/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import folio_services
from . import room_services
from . import room_type_services
from . import calendar_service
from . import partner_services

Expand Down
47 changes: 47 additions & 0 deletions pms_api_rest/services/room_type_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component


class PmsRoomTypeService(Component):
_inherit = "base.rest.service"
_name = "pms.room.type.service"
_usage = "room-types"
_collection = "pms.reservation.service"

@restapi.method(
[
(
[
"/",
],
"GET",
)
],
input_param=Datamodel("pms.room.search.param"),
output_param=Datamodel("pms.room.info", is_list=True),
auth="public",
)
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))
result_rooms = []
PmsRoomTypeInfo = self.env.datamodels["pms.room.type.info"]
for room in (
self.env["pms.room.type"]
.sudo()
.search(
domain,
)
):

result_rooms.append(
PmsRoomTypeInfo(
id=room.id,
name=room.name,
)
)
return result_rooms

0 comments on commit e60cf71

Please sign in to comment.