OCA-git-bot
5 years ago
10 changed files with 362 additions and 0 deletions
-
59partner_identification_gln/README.rst
-
2partner_identification_gln/__init__.py
-
25partner_identification_gln/__manifest__.py
-
15partner_identification_gln/data/partner_identification_gln.xml
-
31partner_identification_gln/i18n/sl.po
-
2partner_identification_gln/models/__init__.py
-
67partner_identification_gln/models/res_partner_id_category.py
-
79partner_identification_gln/static/description/icon.svg
-
2partner_identification_gln/tests/__init__.py
-
80partner_identification_gln/tests/test_gln.py
@ -0,0 +1,59 @@ |
|||||
|
.. 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/repo/github-com-oca-partner-contact-134 |
||||
|
|
||||
|
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 |
||||
|
------------ |
||||
|
|
||||
|
* Alvaro Estebanez <alvaro.estebanez@braintec-group.com> |
||||
|
* Denis Roussel <denis.roussel@acsone.eu> |
||||
|
* Meyomesse Gilles <meyomesse.gilles@gmail.com> |
||||
|
|
||||
|
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,2 @@ |
|||||
|
|
||||
|
from . import models |
@ -0,0 +1,25 @@ |
|||||
|
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
{ |
||||
|
'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, |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
<?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"> |
||||
|
<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> |
||||
|
<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> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,31 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * partner_identification_gln |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 12.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2019-09-11 11:05+0000\n" |
||||
|
"PO-Revision-Date: 2019-09-11 11:05+0000\n" |
||||
|
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>, 2017\n" |
||||
|
"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" |
||||
|
|
||||
|
#. module: partner_identification_gln |
||||
|
#: model:res.partner.id_category,name:partner_identification_gln.partner_identification_gcp_number_category |
||||
|
msgid "GCP Identification Number" |
||||
|
msgstr "GCP identifikacijska številka" |
||||
|
|
||||
|
#. module: partner_identification_gln |
||||
|
#: model:res.partner.id_category,name:partner_identification_gln.partner_identification_gln_number_category |
||||
|
msgid "GLN Identification Number" |
||||
|
msgstr "GLN identifikacijska številka" |
||||
|
|
||||
|
#. module: partner_identification_gln |
||||
|
#: model:ir.model,name:partner_identification_gln.model_res_partner_id_category |
||||
|
msgid "Partner ID Category" |
||||
|
msgstr "Partnerjeve ID kategorije" |
@ -0,0 +1,2 @@ |
|||||
|
|
||||
|
from . import res_partner_id_category |
@ -0,0 +1,67 @@ |
|||||
|
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import logging |
||||
|
|
||||
|
from odoo import api, models |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
try: |
||||
|
from stdnum import ean |
||||
|
from stdnum.exceptions import InvalidChecksum |
||||
|
except ImportError: |
||||
|
_logger.debug('Cannot `import external dependency python stdnum package`.') |
||||
|
|
||||
|
|
||||
|
class ResPartnerIdCategory(models.Model): |
||||
|
_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)] |
||||
|
|
||||
|
if force_active: |
||||
|
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: |
||||
|
return False |
||||
|
|
||||
|
try: |
||||
|
ean.validate(id_number.name) |
||||
|
except InvalidChecksum: |
||||
|
return True |
||||
|
|
||||
|
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: |
||||
|
return True |
||||
|
|
||||
|
return False |
||||
|
|
||||
|
@api.multi |
||||
|
def validate_res_partner_gcp(self, id_number): |
||||
|
self.ensure_one() |
||||
|
if not id_number: |
||||
|
return False |
||||
|
|
||||
|
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 |
||||
|
duplicate_gln = self._search_duplicate(cat, id_number) |
||||
|
|
||||
|
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
File diff suppressed because it is too large
View File
@ -0,0 +1,2 @@ |
|||||
|
|
||||
|
from . import test_gln |
@ -0,0 +1,80 @@ |
|||||
|
# Copyright 2016 Acsone S.A. |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo.exceptions import ValidationError |
||||
|
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 test_gln(self): |
||||
|
# Good GLN |
||||
|
vals = {'name': '5450534005852', |
||||
|
'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, '5450534005852') |
||||
|
|
||||
|
# Duplicate GLN |
||||
|
vals = {'name': '5450534005852', |
||||
|
'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)]}) |
||||
|
|
||||
|
def test_gln_with_no_number(self): |
||||
|
self.assertFalse( |
||||
|
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)]}) |
||||
|
id_number = self.partner.id_numbers[0] |
||||
|
|
||||
|
self.assertEqual(id_number.name, '545053') |
||||
|
|
||||
|
# Duplicate GLN |
||||
|
vals = {'name': '545053', |
||||
|
'category_id': self.partner_id_gcp_category.id |
||||
|
} |
||||
|
|
||||
|
with self.assertRaises(ValidationError): |
||||
|
self.partner2.write({'id_numbers': [(0, 0, vals)]}) |
||||
|
|
||||
|
# Bad GLN |
||||
|
vals = {'name': '5450534001716', |
||||
|
'category_id': self.partner_id_gcp_category.id |
||||
|
} |
||||
|
with self.assertRaises(ValidationError): |
||||
|
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)) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue