Browse Source

[ADD] Module to manage GLN partner identification number

pull/297/head
Denis Roussel 9 years ago
parent
commit
c894f7556c
  1. 61
      partner_identification_gln/README.rst
  2. 2
      partner_identification_gln/__init__.py
  3. 22
      partner_identification_gln/__openerp__.py
  4. 10
      partner_identification_gln/data/partner_identification_gln.xml
  5. 5
      partner_identification_gln/models/__init__.py
  6. 33
      partner_identification_gln/models/partner.py
  7. 79
      partner_identification_gln/static/description/icon.svg
  8. 5
      partner_identification_gln/tests/__init__.py
  9. 42
      partner_identification_gln/tests/test_gln.py

61
partner_identification_gln/README.rst

@ -0,0 +1,61 @@
.. 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/partner-contact/8.0
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
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
------------
* Denis Roussel <denis.roussel@acsone.eu>
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.

2
partner_identification_gln/__init__.py

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

22
partner_identification_gln/__openerp__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Partner Identification Gln',
'summary': """
This addon extends "Partner Identification Numbers"
to provide a number category for GLN registration""",
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'author': 'Acsone S.A.,Odoo Community Association (OCA)',
'website': 'https://www.acsone.eu',
'python': ['stdnum'
],
'depends': ['partner_identification'
],
'data': ['data/partner_identification_gln.xml'
],
'demo': [
],
}

10
partner_identification_gln/data/partner_identification_gln.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="res.partner.id_category" id="partner_identification_gln_number_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>
</data>
</openerp>

5
partner_identification_gln/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import partner

33
partner_identification_gln/models/partner.py

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from stdnum import ean
from stdnum.exceptions import InvalidChecksum
from openerp import api, models
class ResPartnerIdCategory(models.Model):
_inherit = 'res.partner.id_category'
@api.multi
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
num_obj = self.env['res.partner.id_number']
duplicate_gln = num_obj.search([('category_id', '=',
id_number.category_id.id),
('name', '=', id_number.name),
('name', '!=', False),
('id', '!=', id_number.id)])
if duplicate_gln:
return True
return False

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

5
partner_identification_gln/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_gln

42
partner_identification_gln/tests/test_gln.py

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.exceptions import ValidationError
from openerp.tests.common import TransactionCase
class TestGLN(TransactionCase):
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
def test_gln(self):
# Good GLN
vals = {'name': '5450534001717',
'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, '5450534001717')
# Duplicate GLN
vals = {'name': '5450534001717',
'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)]})
Loading…
Cancel
Save