Browse Source

[8.0] Add a GLN field to manage GS1 Global Location Number on partners

pull/293/head
Denis Roussel 9 years ago
parent
commit
bf9809d7b1
  1. 66
      base_partner_gln/README.rst
  2. 5
      base_partner_gln/__init__.py
  3. 24
      base_partner_gln/__openerp__.py
  4. 1
      base_partner_gln/models/__init__.py
  5. 44
      base_partner_gln/models/partner.py
  6. 79
      base_partner_gln/static/description/icon.svg
  7. 5
      base_partner_gln/tests/__init__.py
  8. 35
      base_partner_gln/tests/test_gln.py
  9. 15
      base_partner_gln/views/partner_view.xml

66
base_partner_gln/README.rst

@ -0,0 +1,66 @@
.. 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
================
Base Partner Gln
================
Adds a field GLN on partners (which are companies) to manage GLN (EAN) code.
see: http://www.gs1.org/1/glnrules/en/
Installation
============
This module depends on 'stdnum' python module
Usage
=====
.. 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_id}/{branch}
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
Known issues / Roadmap
======================
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.

5
base_partner_gln/__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 models

24
base_partner_gln/__openerp__.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Base Partner Gln',
'summary': """
Adds a field GLN on partners to manage GLN (EAN) code.""",
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'author': 'Acsone S.A.,Odoo Community Association (OCA)',
'contributors': [
'Denis Roussel <denis.roussel@acsone.eu>',
],
'website': 'https://www.acsone.eu',
'depends': ['base'
],
'python': ['stdnum'
],
'data': ['views/partner_view.xml'
],
'demo': [
],
}

1
base_partner_gln/models/__init__.py

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

44
base_partner_gln/models/partner.py

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Acsone S.A.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from stdnum import ean
from stdnum.exceptions import InvalidChecksum
from openerp import api, fields, models, _
from openerp.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = 'res.partner'
gln = fields.Char(size=13, string='GLN',
help='This is the company GLN identification number.')
@api.multi
@api.constrains('gln')
def _check_gln(self):
for partner in self:
if partner.gln:
try:
ean.validate(partner.gln)
except InvalidChecksum, e:
raise ValidationError(_('The GLN field for the partner'
' %s is not valid! %s')
% (partner.name, e.message))
@api.multi
@api.constrains('gln')
def _check_unique_gln(self):
for partner in self:
if partner.gln:
duplicate_partners = self.search([('gln', '!=', False),
('gln', '=', partner.gln),
('id', '!=', partner.id)])
if duplicate_partners:
raise ValidationError(_('GLN code is already used by '
'existing partners : %s')
% ','.join([p.name for p in
duplicate_partners]))

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

5
base_partner_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

35
base_partner_gln/tests/test_gln.py

@ -0,0 +1,35 @@
# -*- 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'})
def test_gln(self):
# Good GLN
self.partner.write({'gln': '5450534001717'})
self.assertEqual(self.partner.gln, '5450534001717')
# Duplicate GLN
try:
self.partner2.write({'gln': '5450534001717'})
except ValidationError, e:
self.assertEqual(
e.value,
"GLN code is already used by existing partners : TestGLN")
# Bad GLN
try:
self.partner.gln = '5450534001716'
except ValidationError, e:
self.assertEqual(
e.value,
"The GLN field for the partner TestGLN is not valid! "
"The number's checksum or check digit is invalid.")

15
base_partner_gln/views/partner_view.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_gln_form" model="ir.ui.view">
<field name="name">res.partner.gln.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="website" position="after">
<field name="gln"/>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save