Skip to content

Commit

Permalink
[ADD] l10n_jp_partner_postcode_address
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jan 30, 2024
1 parent 429b68b commit d0d9948
Show file tree
Hide file tree
Showing 12 changed files with 617 additions and 0 deletions.
71 changes: 71 additions & 0 deletions l10n_jp_partner_postcode_address/README.rst
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.
1 change: 1 addition & 0 deletions l10n_jp_partner_postcode_address/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions l10n_jp_partner_postcode_address/__manifest__.py
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,
}
2 changes: 2 additions & 0 deletions l10n_jp_partner_postcode_address/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import zip_code_search_mixin
from . import res_partner
9 changes: 9 additions & 0 deletions l10n_jp_partner_postcode_address/models/res_partner.py
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 l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py
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)

Check warning on line 13 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L12-L13

Added lines #L12 - L13 were not covered by tests


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()

Check warning on line 25 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L22-L25

Added lines #L22 - L25 were not covered by tests
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)}"}

Check warning on line 29 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L27-L29

Added lines #L27 - L29 were not covered by tests

@api.onchange("zipcode")
def _onchange_zipcode(self):
if self.zipcode:
self.zipcode, msg = self.check_zipcode(self.zipcode)

Check warning on line 34 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L34

Added line #L34 was not covered by tests
if not self.zipcode:
return msg
request_url = (

Check warning on line 37 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L36-L37

Added lines #L36 - L37 were not covered by tests
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

Check warning on line 44 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L40-L44

Added lines #L40 - L44 were not covered by tests
if response_data["status"] != 200:
self.zipcode = False
return {

Check warning on line 47 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L46-L47

Added lines #L46 - L47 were not covered by tests
"warning": {
"title": _("Error"),
"message": response_data["message"],
}
}
else:
address_data = response_data["results"]

Check warning on line 54 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L54

Added line #L54 was not covered by tests
if address_data:
self.state_id = self.env["res.country.state"].search(

Check warning on line 56 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L56

Added line #L56 was not covered by tests
[("name", "=", address_data[0]["address1"])], limit=1
)
self.city = address_data[0]["address2"]
self.street = address_data[0]["address3"]

Check warning on line 60 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L59-L60

Added lines #L59 - L60 were not covered by tests

def check_zipcode(self, zipcode):
msg = {}
field = jaconv.z2h(zipcode, ascii=True, digit=True).replace("-", "")

Check warning on line 64 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L63-L64

Added lines #L63 - L64 were not covered by tests
if not field.isdigit():
field = False
msg = {

Check warning on line 67 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L66-L67

Added lines #L66 - L67 were not covered by tests
"warning": {
"title": _("Error"),
"message": _("Only digits are allowed."),
}
}
elif len(field) != 7:
field = False
msg = {

Check warning on line 75 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L74-L75

Added lines #L74 - L75 were not covered by tests
"warning": {
"title": _("Error"),
"message": _("Post code should be 7 digits."),
}
}
return field, msg

Check warning on line 81 in l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py

View check run for this annotation

Codecov / codecov/patch

l10n_jp_partner_postcode_address/models/zip_code_search_mixin.py#L81

Added line #L81 was not covered by tests
1 change: 1 addition & 0 deletions l10n_jp_partner_postcode_address/readme/DESCRIPTION.rst
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.
Loading

0 comments on commit d0d9948

Please sign in to comment.