diff --git a/partner_identification_gln/__init__.py b/partner_identification_gln/__init__.py index a9e337226..0650744f6 100644 --- a/partner_identification_gln/__init__.py +++ b/partner_identification_gln/__init__.py @@ -1,2 +1 @@ - from . import models diff --git a/partner_identification_gln/__manifest__.py b/partner_identification_gln/__manifest__.py index 62482104e..4aa0917a8 100644 --- a/partner_identification_gln/__manifest__.py +++ b/partner_identification_gln/__manifest__.py @@ -2,24 +2,16 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Partner Identification Gln', - 'summary': """ + "name": "Partner Identification Gln", + "summary": """ This addon extends "Partner Identification Numbers" to provide a number category for GLN registration""", - 'version': '12.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, + "version": "13.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, } diff --git a/partner_identification_gln/data/partner_identification_gln.xml b/partner_identification_gln/data/partner_identification_gln.xml index 132d539d4..d917e776a 100644 --- a/partner_identification_gln/data/partner_identification_gln.xml +++ b/partner_identification_gln/data/partner_identification_gln.xml @@ -1,15 +1,25 @@ - + - + GLN Identification Number gln_id_number - + - + GCP Identification Number gcp_id_number - + diff --git a/partner_identification_gln/models/__init__.py b/partner_identification_gln/models/__init__.py index 045a6d0d9..3ca19e1ae 100644 --- a/partner_identification_gln/models/__init__.py +++ b/partner_identification_gln/models/__init__.py @@ -1,2 +1 @@ - from . import res_partner_id_category diff --git a/partner_identification_gln/models/res_partner_id_category.py b/partner_identification_gln/models/res_partner_id_category.py index 63a7d4151..ff42d5922 100644 --- a/partner_identification_gln/models/res_partner_id_category.py +++ b/partner_identification_gln/models/res_partner_id_category.py @@ -11,24 +11,25 @@ try: from stdnum import ean from stdnum.exceptions import InvalidChecksum except ImportError: - _logger.debug('Cannot `import external dependency python stdnum package`.') + _logger.debug("Cannot `import external dependency python stdnum package`.") class ResPartnerIdCategory(models.Model): - _inherit = 'res.partner.id_category' + _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)] + 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) + domain.append(("partner_id.active", "=", True)) + return self.env["res.partner.id_number"].search(domain) - @api.multi def validate_res_partner_gln(self, id_number): self.ensure_one() if not id_number: @@ -39,8 +40,9 @@ class ResPartnerIdCategory(models.Model): except InvalidChecksum: return True - cat = self.env.ref('partner_identification_gln.' - 'partner_identification_gln_number_category').id + 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: @@ -48,7 +50,6 @@ class ResPartnerIdCategory(models.Model): return False - @api.multi def validate_res_partner_gcp(self, id_number): self.ensure_one() if not id_number: @@ -57,8 +58,9 @@ class ResPartnerIdCategory(models.Model): 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 + cat = self.env.ref( + "partner_identification_gln." "partner_identification_gcp_number_category" + ).id duplicate_gln = self._search_duplicate(cat, id_number) if duplicate_gln: diff --git a/partner_identification_gln/readme/CONTRIBUTORS.rst b/partner_identification_gln/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..42b018f96 --- /dev/null +++ b/partner_identification_gln/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Alvaro Estebanez +* Denis Roussel +* Meyomesse Gilles +* Bejaoui Souheil diff --git a/partner_identification_gln/readme/DESCRIPTION.rst b/partner_identification_gln/readme/DESCRIPTION.rst new file mode 100644 index 000000000..b8bcc979e --- /dev/null +++ b/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/ diff --git a/partner_identification_gln/readme/INSTALL.rst b/partner_identification_gln/readme/INSTALL.rst new file mode 100644 index 000000000..ecf4e9c16 --- /dev/null +++ b/partner_identification_gln/readme/INSTALL.rst @@ -0,0 +1 @@ +This module depends on 'stdnum' python module diff --git a/partner_identification_gln/tests/__init__.py b/partner_identification_gln/tests/__init__.py index a7f8eb649..bd636d043 100644 --- a/partner_identification_gln/tests/__init__.py +++ b/partner_identification_gln/tests/__init__.py @@ -1,2 +1 @@ - from . import test_gln diff --git a/partner_identification_gln/tests/test_gln.py b/partner_identification_gln/tests/test_gln.py index 94b631afe..6d3e5b7a7 100644 --- a/partner_identification_gln/tests/test_gln.py +++ b/partner_identification_gln/tests/test_gln.py @@ -6,75 +6,65 @@ from odoo.tests.common import SavepointCase class TestGLN(SavepointCase): - - def setUp(cls): - super(TestGLN, cls).setUp() - 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 setUp(self): + super(TestGLN, self).setUp() + self.partner = self.env["res.partner"].create({"name": "TestGLN"}) + self.partner2 = self.env["res.partner"].create({"name": "TestGLN2"}) + pc = self.env.ref( + "partner_identification_gln." "partner_identification_gln_number_category" + ) + self.partner_id_category = pc + + pc_gcp = self.env.ref( + "partner_identification_gln." "partner_identification_gcp_number_category" + ) + self.partner_id_gcp_category = pc_gcp def test_gln(self): # Good GLN - vals = {'name': '5450534005852', - 'category_id': self.partner_id_category.id - } + vals = {"name": "5450534005852", "category_id": self.partner_id_category.id} - self.partner.write({'id_numbers': [(0, 0, vals)]}) + self.partner.write({"id_numbers": [(0, 0, vals)]}) id_number = self.partner.id_numbers[0] - self.assertEqual(id_number.name, '5450534005852') + self.assertEqual(id_number.name, "5450534005852") # Duplicate GLN - vals = {'name': '5450534005852', - 'category_id': self.partner_id_category.id - } + vals = {"name": "5450534005852", "category_id": self.partner_id_category.id} with self.assertRaises(ValidationError): - self.partner2.write({'id_numbers': [(0, 0, vals)]}) + self.partner2.write({"id_numbers": [(0, 0, vals)]}) # Bad GLN - vals = {'name': '5450534001716', - 'category_id': self.partner_id_category.id - } + vals = {"name": "5450534001716", "category_id": self.partner_id_category.id} with self.assertRaises(ValidationError): - self.partner.write({'id_numbers': [(0, 0, vals)]}) + 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)) + 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)]}) + 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') + self.assertEqual(id_number.name, "545053") # Duplicate GLN - vals = {'name': '545053', - 'category_id': self.partner_id_gcp_category.id - } + vals = {"name": "545053", "category_id": self.partner_id_gcp_category.id} with self.assertRaises(ValidationError): - self.partner2.write({'id_numbers': [(0, 0, vals)]}) + self.partner2.write({"id_numbers": [(0, 0, vals)]}) # Bad GLN - vals = {'name': '5450534001716', - 'category_id': self.partner_id_gcp_category.id - } + vals = {"name": "5450534001716", "category_id": self.partner_id_gcp_category.id} with self.assertRaises(ValidationError): - self.partner.write({'id_numbers': [(0, 0, vals)]}) + 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)) + self.partner_id_gcp_category.validate_res_partner_gln(id_number=None) + )