-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][ADD] shopinvader_base_address_city: module for localization of cities #1394
Open
cristiano-one
wants to merge
5
commits into
shopinvader:14.0
Choose a base branch
from
kmee:14.0-api-search-cities
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
908fc81
[ADD] shopinvader_base_address_city: module for localization of citie…
917eb26
[ADD]shopinvader_base_address_city: use city_id in address service
sadamo d58f627
[FIX] shopinvader_base_address_city: Removed field city
506e6f5
[FIX] shopinvader_base_address_city: Condition for city
0d4a097
[FIX] Adaptation to respond to any country
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
============================= | ||
Shopinvader Base Address City | ||
============================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:df08260bb029cf91a4dddf225b7ccffeb710a7bc21b57ceb0790ccbc6f400b8a | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github | ||
:target: https://github.com/shopinvader/odoo-shopinvader/tree/14.0/shopinvader_list_cities | ||
:alt: shopinvader/odoo-shopinvader | ||
|
||
|
||
|badge1| |badge2| |badge3| | ||
|
||
REST Services for To list Brazilian cities. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
Call this endpoint every time you need to fetch Brazilian cities from a state. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/shopinvader/odoo-shopinvader/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%20shopinvader_lead%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* KMEE INFORMATICA LTDA | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Cristiano Rodrigues <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
||
* KMEE INFORMATICA LTDA (http://www.kmee.com.br). | ||
|
||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/14.0/shopinvader_list_cities>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
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,4 @@ | ||
# Copyright 2022 KMEE | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import services |
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,18 @@ | ||
# Copyright 2023 KMEE INFORMATICA LTDA (http://www.kmee.com.br). | ||
# @author Cristiano Rodrigues <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Shopinvader Base Address City", | ||
"summary": ( | ||
"Shopinvader, call this endpoint every time you " | ||
"need to fetch cities from a state" | ||
), | ||
"version": "14.0.0.0.0", | ||
"category": "e-commerce", | ||
"website": "https://github.com/shopinvader/odoo-shopinvader", | ||
"author": "KMEE INFORMATICA LTDA", | ||
"license": "AGPL-3", | ||
"external_dependencies": {"python": ["cerberus"]}, | ||
"depends": ["shopinvader", "base_address_city"], | ||
} |
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 @@ | ||
* Cristiano Rodrigues <[email protected]> |
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 @@ | ||
* KMEE INFORMATICA LTDA (http://www.kmee.com.br). |
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 @@ | ||
REST Services for To list Brazilian cities. |
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 @@ | ||
Call this endpoint every time you need to fetch Brazilian cities from a state. |
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,7 @@ | ||
# Copyright 2023 KMEE INFORMATICA LTDA (http://www.kmee.com.br). | ||
# @author Cristiano Rodrigues <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import address | ||
from . import res_city_abstract | ||
from . import res_city_component |
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,50 @@ | ||
# Copyright 2022 KMEE (http://www.kmee.com.br). | ||
# @author Cristiano Rodrigues <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.base_rest.components.service import to_int | ||
from odoo.addons.component.core import Component | ||
|
||
|
||
class AddressService(Component): | ||
_inherit = "shopinvader.address.service" | ||
|
||
def _json_parser(self): | ||
res = super()._json_parser() | ||
if "city" in res: | ||
res.remove("city") | ||
res.append(("city_id", ["id", "name"])) | ||
|
||
return res | ||
|
||
def _validator_create(self): | ||
res = super()._validator_create() | ||
|
||
if "city" in res: | ||
del res["city"] | ||
|
||
res["city_id"] = { | ||
"type": "dict", | ||
"schema": { | ||
"id": { | ||
"coerce": to_int, | ||
"nullable": False, | ||
"type": "integer", | ||
}, | ||
"name": { | ||
"type": "string", | ||
"nullable": True, | ||
}, | ||
}, | ||
} | ||
|
||
return res | ||
|
||
def _prepare_params(self, params, mode="create"): | ||
if params.get("city_id"): | ||
params["city_id"] = ( | ||
params.get("city_id")["id"] | ||
if type(params["city_id"]) == dict | ||
else params.get("city_id") | ||
) | ||
return super(AddressService, self)._prepare_params(params, mode) |
64 changes: 64 additions & 0 deletions
64
shopinvader_base_address_city/services/res_city_abstract.py
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,64 @@ | ||
# Copyright 2023 KMEE INFORMATICA LTDA (http://www.kmee.com.br). | ||
# @author Cristiano Rodrigues <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import UserError, ValidationError | ||
|
||
from odoo.addons.base_rest import restapi | ||
from odoo.addons.component.core import AbstractComponent | ||
|
||
|
||
class SearchServiceCities(AbstractComponent): | ||
_name = "search.service.cities" | ||
_inherit = "base.rest.service" | ||
_usage = "city" | ||
_description = "REST Services for Search cities across the state" | ||
|
||
@restapi.method( | ||
[(["/"], "GET")], | ||
input_param=restapi.CerberusValidator("_validator_search"), | ||
output_param=restapi.CerberusValidator("_validator_return_search"), | ||
cors="*", | ||
) | ||
def search(self, **params): | ||
state = params.get("state") | ||
try: | ||
country_id = self.shopinvader_backend.company_id.country_id | ||
if country_id: | ||
state_id = self.env["res.country.state"].search( | ||
[("country_id", "=", country_id.id), ("code", "=", state)] | ||
) | ||
city_ids = self.env["res.city"].search( | ||
[("country_id", "=", country_id.id), ("state_id", "=", state_id.id)] | ||
) | ||
cities = [] | ||
for x in city_ids: | ||
cities.append({"name": x.name, "id": x.id}) | ||
except (UserError, ValidationError) as e: | ||
return {"result": False, "error": str(e)} | ||
|
||
return {"result": cities} | ||
|
||
def _validator_search(self): | ||
return { | ||
"state": {"type": "string", "required": True}, | ||
} | ||
|
||
def _validator_return_search(self): | ||
return { | ||
"result": { | ||
"type": "list", | ||
"required": True, | ||
"schema": { | ||
"type": "dict", | ||
"schema": { | ||
"name": { | ||
"type": "string", | ||
"required": True, | ||
"nullable": True, | ||
}, | ||
"id": {"type": "integer", "required": True}, | ||
}, | ||
}, | ||
}, | ||
} |
14 changes: 14 additions & 0 deletions
14
shopinvader_base_address_city/services/res_city_component.py
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,14 @@ | ||
# Copyright 2023 KMEE INFORMATICA LTDA (http://www.kmee.com.br). | ||
# @author Cristiano Rodrigues <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class SearchServiceCitiesShopinvader(Component): | ||
"""Expose Search Cities across the state service under /shopinvader endpoint""" | ||
|
||
_name = "search.service.cities.shopinvader" | ||
_inherit = ["search.service.cities", "base.shopinvader.service"] | ||
_usage = "city" | ||
_collection = "shopinvader.backend" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristiano-one I've the feeling that the description is not too restrictive... Are you sure we can only get Branzilian Cities???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adapted it to respond to any country, depending on what is contained in the base.