-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] l10n_jp_partner_postcode_address
- Loading branch information
1 parent
429b68b
commit d0d9948
Showing
12 changed files
with
617 additions
and
0 deletions.
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,71 @@ | ||
============================== | ||
Japan Partner Postcode Address | ||
============================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:9cf00c1ae529de14f57d45329b7c37e0e0dfd9325c4f9c633ca39919cedf32e2 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-OCA%2Fl10n--japan-lightgray.png?logo=github | ||
:target: https://github.com/OCA/l10n-japan/tree/15.0/l10n_jp_partner_postcode_address | ||
:alt: OCA/l10n-japan | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/l10n-japan-15-0/l10n-japan-15-0-l10n_jp_partner_postcode_address | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-japan&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows users to input a zip code and automatically fills in the corresponding address details of the partner. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-japan/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/l10n-japan/issues/new?body=module:%20l10n_jp_partner_postcode_address%0Aversion:%2015.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 | ||
~~~~~~~ | ||
|
||
* Quartile Limited | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/l10n-japan <https://github.com/OCA/l10n-japan/tree/15.0/l10n_jp_partner_postcode_address>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/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 @@ | ||
from . import models |
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,16 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Japan Partner Postcode Address", | ||
"version": "15.0.1.0.0", | ||
"author": "Quartile Limited, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/l10n-japan", | ||
"category": "Localization", | ||
"depends": ["base"], | ||
"external_dependencies": {"python": ["jaconv"]}, | ||
"data": [ | ||
"views/res_partner_views.xml", | ||
], | ||
"installable": True, | ||
} |
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,2 @@ | ||
from . import zip_code_search_mixin | ||
from . import res_partner |
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,9 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_name = "res.partner" | ||
_inherit = ["res.partner", "zip.code.search.mixin"] |
81 changes: 81 additions & 0 deletions
81
l10n_jp_partner_postcode_address/models/zip_code_search_mixin.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,81 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
import requests | ||
|
||
from odoo import _, api, fields, models | ||
|
||
try: | ||
import jaconv | ||
except (ImportError, IOError) as err: | ||
logging.getLogger(__name__).warning(err) | ||
|
||
|
||
class ZipCodeSearchMixin(models.AbstractModel): | ||
_name = "zip.code.search.mixin" | ||
|
||
zipcode = fields.Char(string="Post Code (Search)") | ||
|
||
def _make_zipcode_request(self, request_url): | ||
try: | ||
response = requests.get(request_url) | ||
response.raise_for_status() # Raise HTTPError for bad responses | ||
return response.json() | ||
except requests.exceptions.HTTPError as http_err: | ||
return {"status": response.status_code, "message": str(http_err)} | ||
except requests.exceptions.RequestException as req_err: | ||
return {"status": 500, "message": f"Request error: {str(req_err)}"} | ||
|
||
@api.onchange("zipcode") | ||
def _onchange_zipcode(self): | ||
if self.zipcode: | ||
self.zipcode, msg = self.check_zipcode(self.zipcode) | ||
if not self.zipcode: | ||
return msg | ||
request_url = ( | ||
f"http://zipcloud.ibsnet.co.jp/api/search?zipcode={self.zipcode}" | ||
) | ||
response_data = self._make_zipcode_request(request_url) | ||
self.state_id = False | ||
self.city = False | ||
self.street = False | ||
self.street2 = False | ||
if response_data["status"] != 200: | ||
self.zipcode = False | ||
return { | ||
"warning": { | ||
"title": _("Error"), | ||
"message": response_data["message"], | ||
} | ||
} | ||
else: | ||
address_data = response_data["results"] | ||
if address_data: | ||
self.state_id = self.env["res.country.state"].search( | ||
[("name", "=", address_data[0]["address1"])], limit=1 | ||
) | ||
self.city = address_data[0]["address2"] | ||
self.street = address_data[0]["address3"] | ||
|
||
def check_zipcode(self, zipcode): | ||
msg = {} | ||
field = jaconv.z2h(zipcode, ascii=True, digit=True).replace("-", "") | ||
if not field.isdigit(): | ||
field = False | ||
msg = { | ||
"warning": { | ||
"title": _("Error"), | ||
"message": _("Only digits are allowed."), | ||
} | ||
} | ||
elif len(field) != 7: | ||
field = False | ||
msg = { | ||
"warning": { | ||
"title": _("Error"), | ||
"message": _("Post code should be 7 digits."), | ||
} | ||
} | ||
return field, msg | ||
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 @@ | ||
This module allows users to input a zip code and automatically fills in the corresponding address details of the partner. |
Oops, something went wrong.