diff --git a/base_vat_sanitized/README.rst b/base_vat_sanitized/README.rst new file mode 100644 index 000000000..765ba8de6 --- /dev/null +++ b/base_vat_sanitized/README.rst @@ -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 + +================== +Base VAT Sanitized +================== + +This module adds a technical field *sanitized_vat* on partners that stores the VAT number without spaces and with letters in uppercase. It is useful for other modules that need to match partners on VAT number, such as the *account_invoice_import* module for example. + +Configuration +============= + +No configuration is needed. + +Usage +===== + +This module doesn't bring any visible feature for the users. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/8.0 + + +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 smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +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/base_vat_sanitized/__init__.py b/base_vat_sanitized/__init__.py new file mode 100644 index 000000000..cde864bae --- /dev/null +++ b/base_vat_sanitized/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/base_vat_sanitized/__openerp__.py b/base_vat_sanitized/__openerp__.py new file mode 100644 index 000000000..61963525c --- /dev/null +++ b/base_vat_sanitized/__openerp__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + +{ + 'name': 'Base VAT Sanitized', + 'version': '8.0.1.0.0', + 'category': 'Hidden/Dependency', + 'license': 'AGPL-3', + 'summary': 'Adds field sanitized_vat on partners', + 'author': 'Akretion,Odoo Community Association (OCA)', + 'website': 'http://www.akretion.com', + 'depends': ['base_vat'], + 'installable': True, +} diff --git a/base_vat_sanitized/models/__init__.py b/base_vat_sanitized/models/__init__.py new file mode 100644 index 000000000..f261da797 --- /dev/null +++ b/base_vat_sanitized/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import res_partner diff --git a/base_vat_sanitized/models/res_partner.py b/base_vat_sanitized/models/res_partner.py new file mode 100644 index 000000000..d32d7a4bb --- /dev/null +++ b/base_vat_sanitized/models/res_partner.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + +from openerp import models, fields, api +import re + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + sanitized_vat = fields.Char( + compute='compute_sanitized_vat', string='Sanitized TIN', + store=True, readonly=True, + help='TIN in uppercase without spaces nor special caracters.') + + def _sanitize_vat(self, vat): + return vat and re.sub(r'\W+', '', vat).upper() or False + + @api.multi + @api.depends('vat') + def compute_sanitized_vat(self): + for partner in self: + partner.sanitized_vat = self._sanitize_vat(partner.vat) diff --git a/base_vat_sanitized/tests/__init__.py b/base_vat_sanitized/tests/__init__.py new file mode 100644 index 000000000..ee615d406 --- /dev/null +++ b/base_vat_sanitized/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_vat diff --git a/base_vat_sanitized/tests/test_vat.py b/base_vat_sanitized/tests/test_vat.py new file mode 100644 index 000000000..0fa239a1b --- /dev/null +++ b/base_vat_sanitized/tests/test_vat.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + +from openerp.tests.common import TransactionCase + + +class TestVatSanitized(TransactionCase): + + def test_vat_sanitized(self): + ldlc = self.env['res.partner'].create({ + 'name': 'LDLC', + 'is_company': True, + 'vat': 'fr 26 403 554 181' + }) + self.assertEqual(ldlc.sanitized_vat, 'FR26403554181') + # Also test invalidation + ldlc.vat = False + self.assertEqual(ldlc.sanitized_vat, False)