9 changed files with 274 additions and 0 deletions
-
66base_partner_gln/README.rst
-
5base_partner_gln/__init__.py
-
24base_partner_gln/__openerp__.py
-
1base_partner_gln/models/__init__.py
-
44base_partner_gln/models/partner.py
-
79base_partner_gln/static/description/icon.svg
-
5base_partner_gln/tests/__init__.py
-
35base_partner_gln/tests/test_gln.py
-
15base_partner_gln/views/partner_view.xml
@ -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. |
@ -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 |
@ -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': [ |
|||
], |
|||
} |
@ -0,0 +1 @@ |
|||
from . import partner |
@ -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
File diff suppressed because it is too large
View File
@ -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 |
@ -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.") |
@ -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> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue