-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] pms_api_rest: add room type services
- Loading branch information
1 parent
d5c9d6e
commit e60cf71
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |