[IMP]pms_api_rest: added get address by display_name service

This commit is contained in:
braisab
2023-07-20 20:40:28 +02:00
committed by Darío Lodeiros
parent 9236e1ca6c
commit ee0bed363c
2 changed files with 42 additions and 0 deletions

View File

@@ -3,8 +3,14 @@ from marshmallow import fields
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):
_name = "res.city.zip.info"
resZipId = fields.Integer(required=False, allow_none=True)
cityId = fields.String(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)
zipCode = fields.String(required=False, allow_none=True)

View File

@@ -9,6 +9,42 @@ class ResCityZipService(Component):
_usage = "zips"
_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(
[
(