mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: added services and datamodels for get and patch checkin_partners
This commit is contained in:
60
pms_api_rest/services/res_country_services.py
Normal file
60
pms_api_rest/services/res_country_services.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
|
||||
class ResCountryService(Component):
|
||||
_inherit = "base.rest.service"
|
||||
_name = "res.country.services"
|
||||
_usage = "countries"
|
||||
_collection = "pms.services"
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("res.country.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_countries(self):
|
||||
result_countries = []
|
||||
ResCountriesInfo = self.env.datamodels["res.country.info"]
|
||||
for country in self.env["res.country"].search([]):
|
||||
result_countries.append(
|
||||
ResCountriesInfo(
|
||||
id=country.id,
|
||||
name=country.name,
|
||||
)
|
||||
)
|
||||
return result_countries
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:country_id>/country_states",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("res.country_state.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_states(self, country_id):
|
||||
result_country_states = []
|
||||
ResCountryStatesInfo = self.env.datamodels["res.country_state.info"]
|
||||
for country_states in self.env["res.country.state"].search(
|
||||
[("country_id", "=", country_id)]
|
||||
):
|
||||
result_country_states.append(
|
||||
ResCountryStatesInfo(
|
||||
id=country_states.id,
|
||||
name=country_states.name,
|
||||
)
|
||||
)
|
||||
return result_country_states
|
||||
Reference in New Issue
Block a user