-
-
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.
- Loading branch information
1 parent
d0d9948
commit a88200a
Showing
16 changed files
with
136 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
l10n_jp_partner_postcode_address/views/res_partner_views.xml
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
5 changes: 1 addition & 4 deletions
5
..._partner_postcode_address/__manifest__.py → l10n_jp_partner_zip_address/__manifest__.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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Japan Partner Postcode Address", | ||
"name": "Japan Partner Zip 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,38 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_jp_partner_zip_address | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-02-03 10:03+0000\n" | ||
"PO-Revision-Date: 2024-02-03 10:03+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: l10n_jp_partner_zip_address | ||
#: model:ir.model,name:l10n_jp_partner_zip_address.model_res_partner | ||
msgid "Contact" | ||
msgstr "連絡先" | ||
|
||
#. module: l10n_jp_partner_zip_address | ||
#: code:addons/l10n_jp_partner_zip_address/models/zip_search_mixin.py:0 | ||
#, python-format | ||
msgid "Only digits are allowed." | ||
msgstr "数値のみで入力してください。" | ||
|
||
#. module: l10n_jp_partner_zip_address | ||
#: code:addons/l10n_jp_partner_zip_address/models/zip_search_mixin.py:0 | ||
#, python-format | ||
msgid "Postcode should be 7 digits." | ||
msgstr "郵便番号には7桁の数値を入れてください。" | ||
|
||
#. module: l10n_jp_partner_zip_address | ||
#: model:ir.model,name:l10n_jp_partner_zip_address.model_zip_search_mixin | ||
msgid "zip.search.mixin" | ||
msgstr "" |
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_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
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,59 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
import requests | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
try: | ||
import jaconv | ||
except (ImportError, IOError) as err: | ||
logging.getLogger(__name__).warning(err) | ||
|
||
|
||
class ZipSearchMixin(models.AbstractModel): | ||
_name = "zip.search.mixin" | ||
|
||
def sanitize_zip(self, zipcode): | ||
field = jaconv.z2h(zipcode, ascii=True, digit=True).replace("-", "") | ||
if not field.isdigit(): | ||
raise UserError(_("Only digits are allowed.")) | ||
elif len(field) != 7: | ||
field = False | ||
raise UserError(_("Postcode should be 7 digits.")) | ||
return field | ||
|
||
def _make_zip_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("zip") | ||
def _onchange_zip(self): | ||
japan = self.env.ref("base.jp") | ||
if (self.country_id and self.country_id != japan) or not self.zip: | ||
return | ||
self.zip = self.sanitize_zip(self.zip) | ||
request_url = f"http://zipcloud.ibsnet.co.jp/api/search?zipcode={self.zip}" | ||
response_data = self._make_zip_request(request_url) | ||
if response_data["status"] != 200: | ||
raise UserError(response_data["message"]) | ||
self.state_id = False | ||
self.city = False | ||
self.street = False | ||
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"] | ||
self.country_id = japan | ||
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,6 @@ | ||
This module introduces a function that automatically retrieves and fills in the Japanese | ||
address details for a partner using the zipcloud service, provided that the following | ||
conditions are met. | ||
|
||
* Country is Japan or no country is set for the partner. | ||
* A valid postcode is entered for the 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
1 change: 0 additions & 1 deletion
1
setup/l10n_jp_partner_postcode_address/odoo/addons/l10n_jp_partner_postcode_address
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
setup/l10n_jp_partner_zip_address/odoo/addons/l10n_jp_partner_zip_address
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 @@ | ||
../../../../l10n_jp_partner_zip_address |
File renamed without changes.