mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: added get address by display_name service
This commit is contained in:
@@ -3,8 +3,14 @@ from marshmallow import fields
|
|||||||
from odoo.addons.datamodel.core import Datamodel
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class ResCityZipSearchParam(Datamodel):
|
||||||
|
_name = "res.city.zip.search.param"
|
||||||
|
address = fields.String(required=False, allow_none=False)
|
||||||
class ResCityZipInfo(Datamodel):
|
class ResCityZipInfo(Datamodel):
|
||||||
_name = "res.city.zip.info"
|
_name = "res.city.zip.info"
|
||||||
|
resZipId = fields.Integer(required=False, allow_none=True)
|
||||||
cityId = fields.String(required=False, allow_none=True)
|
cityId = fields.String(required=False, allow_none=True)
|
||||||
stateId = fields.Integer(required=False, allow_none=True)
|
stateId = fields.Integer(required=False, allow_none=True)
|
||||||
|
stateName = fields.String(required=False, allow_none=True)
|
||||||
countryId = fields.Integer(required=False, allow_none=True)
|
countryId = fields.Integer(required=False, allow_none=True)
|
||||||
|
zipCode = fields.String(required=False, allow_none=True)
|
||||||
|
|||||||
@@ -9,6 +9,42 @@ class ResCityZipService(Component):
|
|||||||
_usage = "zips"
|
_usage = "zips"
|
||||||
_collection = "pms.services"
|
_collection = "pms.services"
|
||||||
|
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("res.city.zip.search.param", is_list=False),
|
||||||
|
output_param=Datamodel("res.city.zip.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_address_data(self, zip_search_param):
|
||||||
|
result_res_zip = []
|
||||||
|
if not zip_search_param.address:
|
||||||
|
return result_res_zip
|
||||||
|
ResCityZipInfo = self.env.datamodels["res.city.zip.info"]
|
||||||
|
res_zip = self.env["res.city.zip"].search([("display_name", "ilike", zip_search_param.address)], limit=10)
|
||||||
|
|
||||||
|
if res_zip:
|
||||||
|
for address in res_zip:
|
||||||
|
result_res_zip.append(
|
||||||
|
ResCityZipInfo(
|
||||||
|
resZipId=address.id,
|
||||||
|
cityId=address.city_id.name if address.city_id else None,
|
||||||
|
stateId=address.state_id.id if address.state_id else None,
|
||||||
|
stateName=address.state_id.name if address.state_id else None,
|
||||||
|
countryId=address.country_id.id if address.country_id else None,
|
||||||
|
zipCode=address.name if address.name else None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_res_zip
|
||||||
|
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user