Browse Source

[13.0][MIG] - migration partner_identification_gln

14.0
sbejaoui 5 years ago
committed by Simone Orsi
parent
commit
5e8a457688
  1. 1
      partner_identification_gln/__init__.py
  2. 28
      partner_identification_gln/__manifest__.py
  3. 20
      partner_identification_gln/data/partner_identification_gln.xml
  4. 1
      partner_identification_gln/models/__init__.py
  5. 30
      partner_identification_gln/models/res_partner_id_category.py
  6. 4
      partner_identification_gln/readme/CONTRIBUTORS.rst
  7. 3
      partner_identification_gln/readme/DESCRIPTION.rst
  8. 1
      partner_identification_gln/readme/INSTALL.rst
  9. 1
      partner_identification_gln/tests/__init__.py
  10. 72
      partner_identification_gln/tests/test_gln.py

1
partner_identification_gln/__init__.py

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

28
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,
}

20
partner_identification_gln/data/partner_identification_gln.xml

@ -1,15 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<?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">
<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>
<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">
<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>
<field
name="validation_code"
><![CDATA[failed = self.validate_res_partner_gcp(id_number)]]></field>
</record>
</odoo>

1
partner_identification_gln/models/__init__.py

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

30
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:

4
partner_identification_gln/readme/CONTRIBUTORS.rst

@ -0,0 +1,4 @@
* 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>

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

1
partner_identification_gln/tests/__init__.py

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

72
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)
)
Loading…
Cancel
Save