mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms_api_rest: add rest service agencies
This commit is contained in:
@@ -41,3 +41,4 @@ from . import pms_board_service_line
|
||||
from . import pms_product
|
||||
from . import pms_sale_channel
|
||||
from . import pms_cancelation_rule
|
||||
from . import pms_agency
|
||||
|
||||
14
pms_api_rest/datamodels/pms_agency.py
Normal file
14
pms_api_rest/datamodels/pms_agency.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsAgencySearchParam(Datamodel):
|
||||
_name = "pms.agency.search.param"
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
|
||||
|
||||
class PmsAgencyInfo(Datamodel):
|
||||
_name = "pms.agency.info"
|
||||
id = fields.Integer(required=True, allow_none=False)
|
||||
name = fields.String(required=True, allow_none=False)
|
||||
@@ -27,3 +27,5 @@ from . import pms_board_service_service
|
||||
from . import pms_product_service
|
||||
from . import pms_sale_channel_service
|
||||
from . import pms_cancelation_rule_service
|
||||
|
||||
from . import pms_agency_service
|
||||
|
||||
70
pms_api_rest/services/pms_agency_service.py
Normal file
70
pms_api_rest/services/pms_agency_service.py
Normal file
@@ -0,0 +1,70 @@
|
||||
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 PmsAgencyService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "pms.agency.service"
|
||||
_usage = "agencies"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.agency.search.param"),
|
||||
output_param=Datamodel("pms.agency.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_agencies(self, agencies_search_param):
|
||||
domain = [("is_agency", "=", True)]
|
||||
if agencies_search_param.name:
|
||||
domain.append(("name", "like", agencies_search_param.name))
|
||||
result_agencies = []
|
||||
PmsAgencyInfo = self.env.datamodels["pms.agency.info"]
|
||||
for agency in self.env["res.partner"].search(
|
||||
domain,
|
||||
):
|
||||
|
||||
result_agencies.append(
|
||||
PmsAgencyInfo(
|
||||
id=agency.id,
|
||||
name=agency.name,
|
||||
)
|
||||
)
|
||||
return result_agencies
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:agency_id>",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.agency.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_agency(self, agency_id):
|
||||
agency = self.env["res.partner"].search([
|
||||
("id", "=", agency_id),
|
||||
("is_agency", "=", True),
|
||||
])
|
||||
if agency:
|
||||
PmsAgencieInfo = self.env.datamodels["pms.agency.info"]
|
||||
return PmsAgencieInfo(
|
||||
id=agency.id,
|
||||
name=agency.name,
|
||||
)
|
||||
else:
|
||||
raise MissingError(_("Agency not found"))
|
||||
Reference in New Issue
Block a user