-
-
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_corporate_number
- Loading branch information
1 parent
9f06c6c
commit 3dbfe07
Showing
15 changed files
with
940 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,98 @@ | ||
=========================== | ||
JP Partner Corporate Number | ||
=========================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:bed290b070d13a23b9cf15549ee6e845d7ce10bdae34fd7f5c08478ccc0e09a1 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/16.0/l10n_jp_partner_corporate_number | ||
: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-16-0/l10n-japan-16-0-l10n_jp_partner_corporate_number | ||
: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=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module add a corporate registration number by Japanese government | ||
and get it information through API. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
Install module and set a corporate registration number in a contact. | ||
|
||
Access token for gBizINFO | ||
========================= | ||
|
||
Get corporate information through gBizINFO API. Prepare an access token | ||
before use the API from following web site. | ||
|
||
https://info.gbiz.go.jp/api/index.html | ||
|
||
Set access token in a system parameter | ||
-------------------------------------- | ||
|
||
Create a system parameter as ``gbizinfo_access_token`` in the system | ||
parameter setting. Set a value to the access token. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
Change the current implementation: | ||
|
||
- Initial release | ||
|
||
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_corporate_number%0Aversion:%2016.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/16.0/l10n_jp_partner_corporate_number>`_ 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,18 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "JP Partner Corporate Number", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Quartile Limited, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/l10n-japan", | ||
"depends": ["base", "base_country_state_translatable"], | ||
"data": [ | ||
"views/res_company_views.xml", | ||
"views/res_partner_views.xml", | ||
], | ||
"demo": [], | ||
"installable": True, | ||
"application": False, | ||
"auto_install": False, | ||
} |
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,108 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_jp_partner_corporate_number | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-04-16 03:20+0000\n" | ||
"PO-Revision-Date: 2024-04-16 03:20+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_corporate_number | ||
#: model:ir.model,name:l10n_jp_partner_corporate_number.model_res_company | ||
msgid "Companies" | ||
msgstr "会社" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model,name:l10n_jp_partner_corporate_number.model_res_partner | ||
msgid "Contact" | ||
msgstr "連絡先" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_partner__corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_users__corporate_number | ||
#: model_terms:ir.ui.view,arch_db:l10n_jp_partner_corporate_number.view_res_partner_search_inherit | ||
msgid "Corporate Number" | ||
msgstr "法人番号" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#. odoo-python | ||
#: code:addons/l10n_jp_partner_corporate_number/models/res_partner.py:0 | ||
#, python-format | ||
msgid "Corporate Number must be 13 digits." | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,help:l10n_jp_partner_corporate_number.field_res_company__error_message | ||
msgid "" | ||
"Custom error message to display when a duplicate corporate number is " | ||
"detected and behavior is set to 'Error'." | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,help:l10n_jp_partner_corporate_number.field_res_company__warning_message | ||
msgid "" | ||
"Custom warning message to display when a duplicate corporate number is " | ||
"detected and behavior is set to 'Warning'." | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,help:l10n_jp_partner_corporate_number.field_res_company__duplicate_corp_number_behavior | ||
msgid "" | ||
"Define the behavior when a duplicate corporate number is detected: 'Error' " | ||
"will block the operation, 'Warning' will allow but notify." | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_company__duplicate_corp_number_behavior | ||
msgid "Duplicate Corp Number Behavior" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model_terms:ir.ui.view,arch_db:l10n_jp_partner_corporate_number.view_company_form_inherit | ||
msgid "Duplicate Corp Number Settings" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_partner__duplicate_corp_number_warning_message | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_users__duplicate_corp_number_warning_message | ||
msgid "Duplicate Corp Number Warning Message" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields.selection,name:l10n_jp_partner_corporate_number.selection__res_company__duplicate_corp_number_behavior__error | ||
msgid "Error" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_company__error_message | ||
msgid "Error Message for Duplicate Corp Number" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model_terms:ir.ui.view,arch_db:l10n_jp_partner_corporate_number.view_partner_form_corporate_number | ||
msgid "Get corp. info." | ||
msgstr "法人情報取得" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,help:l10n_jp_partner_corporate_number.field_res_partner__corporate_number | ||
#: model:ir.model.fields,help:l10n_jp_partner_corporate_number.field_res_users__corporate_number | ||
msgid "Japanese Corporate Registration Number" | ||
msgstr "日本の法人番号" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields.selection,name:l10n_jp_partner_corporate_number.selection__res_company__duplicate_corp_number_behavior__warning | ||
msgid "Warning" | ||
msgstr "" | ||
|
||
#. module: l10n_jp_partner_corporate_number | ||
#: model:ir.model.fields,field_description:l10n_jp_partner_corporate_number.field_res_company__warning_message | ||
msgid "Warning Message for Duplicate Corp Number" | ||
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 res_company | ||
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,28 @@ | ||
# Copyright 2024 Quartile Limited | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
duplicate_corp_number_behavior = fields.Selection( | ||
[("error", "Error"), ("warning", "Warning")], | ||
help="Define the behavior when a duplicate corporate number is detected: " | ||
"'Error' will block the operation, " | ||
"'Warning' will allow but notify.", | ||
) | ||
|
||
error_message = fields.Text( | ||
string="Error Message for Duplicate Corp Number", | ||
default="A partner with this corporate number already exists.", | ||
help="Custom error message to display when a duplicate corporate number " | ||
"is detected and behavior is set to 'Error'.", | ||
) | ||
|
||
warning_message = fields.Text( | ||
string="Warning Message for Duplicate Corp Number", | ||
default="Warning: A partner with this corporate number already exists.", | ||
help="Custom warning message to display when a duplicate corporate number " | ||
"is detected and behavior is set to 'Warning'.", | ||
) |
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,131 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
import re | ||
|
||
import requests | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
_timeout = 10 | ||
|
||
corporate_number = fields.Char(help="Japanese Corporate Registration Number") | ||
duplicate_corp_number_warning_message = fields.Text( | ||
compute="_compute_duplicate_corp_number_warning_message" | ||
) | ||
|
||
@api.depends("corporate_number") | ||
def _compute_duplicate_corp_number_warning_message(self): | ||
for rec in self: | ||
rec.duplicate_corp_number_warning_message = False | ||
if rec.corporate_number: | ||
domain = [("corporate_number", "=", rec.corporate_number)] | ||
if ( | ||
rec.id | ||
): # Exclude the current record from the search to avoid self-detection | ||
domain.append(("id", "!=", rec.id)) | ||
duplicates = self.env["res.partner"].search(domain, limit=1) | ||
company = self.env.company | ||
if duplicates and company.duplicate_corp_number_behavior == "warning": | ||
rec.duplicate_corp_number_warning_message = company.warning_message | ||
|
||
@api.constrains("corporate_number") | ||
def _check_corporate_number(self): | ||
for record in self: | ||
duplicate_rec = self.env["res.partner"].search( | ||
[ | ||
("corporate_number", "=", record.corporate_number), | ||
("id", "!=", record.id), | ||
], | ||
limit=1, | ||
) | ||
company = self.env.company | ||
if duplicate_rec and company.duplicate_corp_number_behavior == "error": | ||
raise ValidationError(_(company.error_message)) | ||
if record.corporate_number and not re.match( | ||
r"^\d{13}$", record.corporate_number | ||
): | ||
raise ValidationError(_("Corporate Number must be 13 digits.")) | ||
|
||
def fetch_corporate_info(self): | ||
self.ensure_one() | ||
if self.corporate_number: | ||
data = self._fetch_gbizinfo(self.corporate_number) | ||
hojin_info = data.get("hojin-infos", [{}])[0] # get a first element | ||
address_vals = self._split_address(hojin_info.get("location")) | ||
partner_vals = { | ||
"name": hojin_info.get("name"), | ||
"street": hojin_info.get("location"), | ||
**address_vals, | ||
} | ||
self.write(partner_vals) | ||
|
||
def _split_address(self, location): | ||
# in Japan | ||
country_id = self.env.ref("base.jp").id | ||
# remove Japanese ZIP code | ||
address_without_zip = re.sub(r"\d{3}-\d{4}", "", location).strip() | ||
pattern = """(...??[都道府県])((?:旭川|伊達|石狩|盛岡|奥州|田村|南相馬|那須塩原|東村山|武蔵村山|羽村|十日町|上越| | ||
富山|野々市|大町|蒲郡|四日市|姫路|大和郡山|廿日市|下松|岩国|田川|大村|宮古|富良野|別府|佐伯|黒部|小諸|塩尻|玉野| | ||
周南)市|(?:余市|高市|[^市]{2,3}?)郡(?:玉村|大町|.{1,5}?)[町村]|(?:.{1,4}市)?[^町]{1,4}?区|.{1,7}?[市町村])(.+)""" | ||
result = re.match(pattern, address_without_zip) | ||
if result: | ||
state_name = result.group(1) | ||
city = result.group(2) | ||
street = result.group(3) | ||
# Stateの取得(存在しない場合はNone) | ||
# 都道府県を日本語化するモジュール(base_country_state_translatable)依存 | ||
# 都道府県名は日本語翻訳済とする | ||
state_id = ( | ||
self.env["res.country.state"] | ||
.search( | ||
[("name", "like", state_name), ("country_id", "=", country_id)], limit=1 | ||
) | ||
.id | ||
) | ||
return { | ||
"country_id": country_id, | ||
"state_id": state_id, | ||
"city": city, | ||
"street": street, | ||
} | ||
|
||
def _fetch_gbizinfo(self, corporate_number): | ||
# gBizINFOのエンドポイントURL + 法人番号 | ||
endpoint = f"https://info.gbiz.go.jp/hojin/v1/hojin/{corporate_number}" | ||
access_token = ( | ||
self.env["ir.config_parameter"].sudo().get_param("gbizinfo_access_token") | ||
) | ||
headers = { | ||
"Accept": "application/json", | ||
"X-hojinInfo-api-token": access_token, | ||
} | ||
|
||
# APIリクエストを実行 | ||
try: | ||
response = requests.get( | ||
endpoint, headers=headers, timeout=(self._timeout, self._timeout) | ||
) | ||
if response.status_code == 200: | ||
# 成功した場合、JSONデータを抽出 | ||
return response.json() | ||
else: | ||
# エラーがあった場合、問題をログに記録 | ||
error_msg = ( | ||
f"Failed to fetch data from gBizINFO: {response.status_code}" | ||
) | ||
_logger.error(error_msg) | ||
return None | ||
except requests.Timeout: | ||
_logger.error("Request timed out.") | ||
return None | ||
except requests.RequestException as e: | ||
_logger.error(f"An error occurred: {e}") | ||
return None |
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 add a corporate registration number by Japanese government and get it information through API. |
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,3 @@ | ||
Change the current implementation: | ||
|
||
- Initial release |
Oops, something went wrong.