diff --git a/partner_vat_unique/README.rst b/partner_vat_unique/README.rst new file mode 100644 index 000000000..f8d701e03 --- /dev/null +++ b/partner_vat_unique/README.rst @@ -0,0 +1,43 @@ +.. 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 VAT Unique +================== + +Module to make the VAT number unique for customers and suppliers. Will not +consider empty VATs as duplicated. + + +Installation +============ + +Will not check previous VAT duplicates, so it is recomended make sure there +isn't any duplicated VAT before installation. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + + +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. diff --git a/partner_vat_unique/__init__.py b/partner_vat_unique/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/partner_vat_unique/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_vat_unique/__manifest__.py b/partner_vat_unique/__manifest__.py new file mode 100644 index 000000000..812b7f781 --- /dev/null +++ b/partner_vat_unique/__manifest__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Grant Thornton Spain - Ismael Calvo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Partner VAT Unique", + "version": "10.0.1.0.0", + "category": "Customer Relationship Management", + "website": "https://github.com/OCA/partner-contact", + "author": "Grant Thornton S.L.P, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": True, + "installable": True, + "depends": ["base"], +} diff --git a/partner_vat_unique/i18n/es.po b/partner_vat_unique/i18n/es.po new file mode 100644 index 000000000..3d42b965f --- /dev/null +++ b/partner_vat_unique/i18n/es.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_vat_unique +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-11-29 11:43+0000\n" +"PO-Revision-Date: 2017-11-29 11:43+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_vat_unique +#: code:addons/partner_vat_unique/models/res_partner.py:22 +#, python-format +msgid "The VAT must be unique per partner!" +msgstr "¡El NIF debe de ser único por empresa!" + diff --git a/partner_vat_unique/models/__init__.py b/partner_vat_unique/models/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/partner_vat_unique/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/partner_vat_unique/models/res_partner.py b/partner_vat_unique/models/res_partner.py new file mode 100644 index 000000000..c70b1a3d9 --- /dev/null +++ b/partner_vat_unique/models/res_partner.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Grant Thornton Spain - Ismael Calvo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.constrains('vat') + def _check_vat_unique(self): + for record in self: + if record.parent_id: + continue + results = self.env['res.partner'].search([ + ('parent_id', '=', False), + ('vat', '=', record.vat), + ('id', '!=', record.id) + ]) + if results: + raise ValidationError(_( + "The VAT %s already exists in another " + "partner.") % record.vat) diff --git a/partner_vat_unique/static/description/icon.png b/partner_vat_unique/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_vat_unique/static/description/icon.png differ diff --git a/partner_vat_unique/tests/__init__.py b/partner_vat_unique/tests/__init__.py new file mode 100644 index 000000000..0742f6bf1 --- /dev/null +++ b/partner_vat_unique/tests/__init__.py @@ -0,0 +1 @@ +from . import test_vat_unique diff --git a/partner_vat_unique/tests/test_vat_unique.py b/partner_vat_unique/tests/test_vat_unique.py new file mode 100644 index 000000000..7d1cf1d96 --- /dev/null +++ b/partner_vat_unique/tests/test_vat_unique.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Grant Thornton Spain - Ismael Calvo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import SavepointCase +from odoo.exceptions import ValidationError + + +class TestVatUnique(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestVatUnique, cls).setUpClass() + cls.partner = cls.env['res.partner'].create({ + 'name': 'Test partner', + 'vat': 'ESA12345674' + }) + + def test_duplicated_vat_creation(self): + with self.assertRaises(ValidationError): + self.env['res.partner'].create({ + 'name': 'Second partner', + 'vat': 'ESA12345674' + })