Browse Source

Merge PR #1167 into 14.0

Signed-off-by dreispt
14.0
OCA-git-bot 3 years ago
parent
commit
88d13ff1a0
  1. 59
      partner_identification_gln/README.rst
  2. 1
      partner_identification_gln/__init__.py
  3. 17
      partner_identification_gln/__manifest__.py
  4. 25
      partner_identification_gln/data/partner_identification_gln.xml
  5. 31
      partner_identification_gln/i18n/sl.po
  6. 1
      partner_identification_gln/models/__init__.py
  7. 69
      partner_identification_gln/models/res_partner_id_category.py
  8. 5
      partner_identification_gln/readme/CONTRIBUTORS.rst
  9. 3
      partner_identification_gln/readme/DESCRIPTION.rst
  10. 1
      partner_identification_gln/readme/INSTALL.rst
  11. 79
      partner_identification_gln/static/description/icon.svg
  12. 1
      partner_identification_gln/tests/__init__.py
  13. 72
      partner_identification_gln/tests/test_gln.py
  14. 1
      requirements.txt
  15. 1
      setup/partner_identification_gln/odoo/addons/partner_identification_gln
  16. 6
      setup/partner_identification_gln/setup.py

59
partner_identification_gln/README.rst

@ -0,0 +1,59 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==========================
Partner Identification Gln
==========================
This addon extends "Partner Identification Numbers" to provide a number category for GLN registration
see: http://www.gs1.org/1/glnrules/en/
Installation
============
This module depends on 'stdnum' python module
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/repo/github-com-oca-partner-contact-134
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Alvaro Estebanez <alvaro.estebanez@braintec-group.com>
* Denis Roussel <denis.roussel@acsone.eu>
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

1
partner_identification_gln/__init__.py

@ -0,0 +1 @@
from . import models

17
partner_identification_gln/__manifest__.py

@ -0,0 +1,17 @@
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Partner Identification GLN",
"summary": """
This addon extends "Partner Identification Numbers"
to provide a number category for GLN registration""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Acsone S.A.,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"external_dependencies": {"python": ["stdnum"]},
"depends": ["partner_identification"],
"data": ["data/partner_identification_gln.xml"],
"installable": True,
}

25
partner_identification_gln/data/partner_identification_gln.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record
id="partner_identification_gln_number_category"
model="res.partner.id_category"
>
<field name="name">GLN Identification Number</field>
<field name="code">gln_id_number</field>
<field
name="validation_code"
><![CDATA[failed = self.validate_res_partner_gln(id_number)]]></field>
</record>
<record
id="partner_identification_gcp_number_category"
model="res.partner.id_category"
>
<field name="name">GCP Identification Number</field>
<field name="code">gcp_id_number</field>
<field
name="validation_code"
><![CDATA[failed = self.validate_res_partner_gcp(id_number)]]></field>
</record>
</odoo>

31
partner_identification_gln/i18n/sl.po

@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_identification_gln
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-11 11:05+0000\n"
"PO-Revision-Date: 2019-09-11 11:05+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>, 2017\n"
"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#. module: partner_identification_gln
#: model:res.partner.id_category,name:partner_identification_gln.partner_identification_gcp_number_category
msgid "GCP Identification Number"
msgstr "GCP identifikacijska številka"
#. module: partner_identification_gln
#: model:res.partner.id_category,name:partner_identification_gln.partner_identification_gln_number_category
msgid "GLN Identification Number"
msgstr "GLN identifikacijska številka"
#. module: partner_identification_gln
#: model:ir.model,name:partner_identification_gln.model_res_partner_id_category
msgid "Partner ID Category"
msgstr "Partnerjeve ID kategorije"

1
partner_identification_gln/models/__init__.py

@ -0,0 +1 @@
from . import res_partner_id_category

69
partner_identification_gln/models/res_partner_id_category.py

@ -0,0 +1,69 @@
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, models
_logger = logging.getLogger(__name__)
try:
from stdnum import ean
from stdnum.exceptions import InvalidChecksum
except ImportError:
_logger.debug("Cannot `import external dependency python stdnum package`.")
class ResPartnerIdCategory(models.Model):
_inherit = "res.partner.id_category"
@api.model
def _search_duplicate(self, category_id, id_number, force_active=False):
domain = [
("category_id", "=", category_id),
("name", "=", id_number.name),
("name", "!=", False),
("id", "!=", id_number.id),
]
if force_active:
domain.append(("partner_id.active", "=", True))
return self.env["res.partner.id_number"].search(domain)
def validate_res_partner_gln(self, id_number):
self.ensure_one()
if not id_number:
return False
try:
ean.validate(id_number.name)
except InvalidChecksum:
return True
cat = self.env.ref(
"partner_identification_gln." "partner_identification_gln_number_category"
).id
duplicate_gln = self._search_duplicate(cat, id_number, True)
if duplicate_gln:
return True
return False
def validate_res_partner_gcp(self, id_number):
self.ensure_one()
if not id_number:
return False
if len(id_number.name) < 1 or len(id_number.name) > 12:
return True
cat = self.env.ref(
"partner_identification_gln." "partner_identification_gcp_number_category"
).id
duplicate_gln = self._search_duplicate(cat, id_number)
if duplicate_gln:
return True
return False

5
partner_identification_gln/readme/CONTRIBUTORS.rst

@ -0,0 +1,5 @@
* Alvaro Estebanez <alvaro.estebanez@braintec-group.com>
* Denis Roussel <denis.roussel@acsone.eu>
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
* Bejaoui Souheil <souheil.bejaoui@acsone.eu>
* Simone Orsi <simone.orsi@camptocamp.com>

3
partner_identification_gln/readme/DESCRIPTION.rst

@ -0,0 +1,3 @@
This addon extends "Partner Identification Numbers" to provide a number category for GLN registration
see: http://www.gs1.org/1/glnrules/en/

1
partner_identification_gln/readme/INSTALL.rst

@ -0,0 +1 @@
This module depends on 'stdnum' python module

79
partner_identification_gln/static/description/icon.svg
File diff suppressed because it is too large
View File

1
partner_identification_gln/tests/__init__.py

@ -0,0 +1 @@
from . import test_gln

72
partner_identification_gln/tests/test_gln.py

@ -0,0 +1,72 @@
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
class TestGLN(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env["res.partner"].create({"name": "TestGLN"})
cls.partner2 = cls.env["res.partner"].create({"name": "TestGLN2"})
pc = cls.env.ref(
"partner_identification_gln.partner_identification_gln_number_category"
)
cls.partner_id_category = pc
pc_gcp = cls.env.ref(
"partner_identification_gln.partner_identification_gcp_number_category"
)
cls.partner_id_gcp_category = pc_gcp
def test_gln(self):
# Good GLN
vals = {"name": "5450534005852", "category_id": self.partner_id_category.id}
self.partner.write({"id_numbers": [(0, 0, vals)]})
id_number = self.partner.id_numbers[0]
self.assertEqual(id_number.name, "5450534005852")
# Duplicate GLN
vals = {"name": "5450534005852", "category_id": self.partner_id_category.id}
with self.assertRaises(ValidationError):
self.partner2.write({"id_numbers": [(0, 0, vals)]})
# Bad GLN
vals = {"name": "5450534001716", "category_id": self.partner_id_category.id}
with self.assertRaises(ValidationError):
self.partner.write({"id_numbers": [(0, 0, vals)]})
def test_gln_with_no_number(self):
self.assertFalse(
self.partner_id_category.validate_res_partner_gln(id_number=None)
)
def test_gcp(self):
# Good GLN
vals = {"name": "545053", "category_id": self.partner_id_gcp_category.id}
self.partner.write({"id_numbers": [(0, 0, vals)]})
id_number = self.partner.id_numbers[0]
self.assertEqual(id_number.name, "545053")
# Duplicate GLN
vals = {"name": "545053", "category_id": self.partner_id_gcp_category.id}
with self.assertRaises(ValidationError):
self.partner2.write({"id_numbers": [(0, 0, vals)]})
# Bad GLN
vals = {"name": "5450534001716", "category_id": self.partner_id_gcp_category.id}
with self.assertRaises(ValidationError):
self.partner.write({"id_numbers": [(0, 0, vals)]})
def test_gcp_with_no_number(self):
self.assertFalse(
self.partner_id_gcp_category.validate_res_partner_gln(id_number=None)
)

1
requirements.txt

@ -1,2 +1,3 @@
# generated from manifests external_dependencies # generated from manifests external_dependencies
email-validator email-validator
python-stdnum

1
setup/partner_identification_gln/odoo/addons/partner_identification_gln

@ -0,0 +1 @@
../../../../partner_identification_gln

6
setup/partner_identification_gln/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save