Skip to content
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
wants to merge 5 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions shopinvader_base_address_city/README.rst
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.
Copy link
Collaborator

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???

Copy link
Author

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.


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.
4 changes: 4 additions & 0 deletions shopinvader_base_address_city/__init__.py
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
18 changes: 18 additions & 0 deletions shopinvader_base_address_city/__manifest__.py
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"],
}
1 change: 1 addition & 0 deletions shopinvader_base_address_city/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Cristiano Rodrigues <[email protected]>
1 change: 1 addition & 0 deletions shopinvader_base_address_city/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* KMEE INFORMATICA LTDA (http://www.kmee.com.br).
1 change: 1 addition & 0 deletions shopinvader_base_address_city/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REST Services for To list Brazilian cities.
1 change: 1 addition & 0 deletions shopinvader_base_address_city/readme/USAGE.rst
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.
7 changes: 7 additions & 0 deletions shopinvader_base_address_city/services/__init__.py
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
50 changes: 50 additions & 0 deletions shopinvader_base_address_city/services/address.py
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 shopinvader_base_address_city/services/res_city_abstract.py
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 shopinvader_base_address_city/services/res_city_component.py
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"
Loading
Loading