diff --git a/partner_create_by_vat/README.rst b/partner_create_by_vat/README.rst new file mode 100644 index 000000000..97e525668 --- /dev/null +++ b/partner_create_by_vat/README.rst @@ -0,0 +1,71 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +============================================== +Automatic partner creation based on VAT number +============================================== + +This module allows you to create the partners (companies) based on their VAT number. +Name and address of the partner will automatically be completed via VIES Webservice. + +VIES Service (based on stdnum python) +http://ec.europa.eu/taxation_customs/vies/vieshome.do + +Installation +============ + +To install this module, you need to: + +#. Clone the branch 8.0 of the repository https://github.com/OCA/partner-contact +#. Add the path to this repository in your configuration (addons-path) +#. Update the module list +#. Search for "Partner Create by VAT" in your addons +#. install the module + +Usage +===== + +On the partner's form view you will have a button in the header, called +"Get Vies Data", available only on companies (is_company field set to True). +Clicking the button will fetch data, when available, from the VIES Webservice, for most of +the EU countries. + +.. 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 +`here `_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Fekete Mihai + +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_create_by_vat/__init__.py b/partner_create_by_vat/__init__.py new file mode 100644 index 000000000..8986aaf4e --- /dev/null +++ b/partner_create_by_vat/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_create_by_vat/__openerp__.py b/partner_create_by_vat/__openerp__.py new file mode 100644 index 000000000..e218f04c2 --- /dev/null +++ b/partner_create_by_vat/__openerp__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Automatic partner creation based on VAT number', + 'summary': 'Using VIES webservice, name and address information will ' + 'be fetched and added to the partner.', + 'version': '8.0.1.0.0', + 'category': 'Customer Relationship Management', + 'author': 'Forest and Biomass Services Romania, ' + 'Odoo Community Association (OCA)', + 'website': 'https://www.forbiom.eu', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'external_dependencies': { + 'python': ['stdnum', 'suds'], + }, + 'depends': ['base_vat'], + 'data': ['views/res_partner_view.xml'], + 'images': ['static/description/customer.png', + 'static/description/customer1.png'], + 'auto_install': False, +} diff --git a/partner_create_by_vat/i18n/ro.po b/partner_create_by_vat/i18n/ro.po new file mode 100644 index 000000000..4943ab5b3 --- /dev/null +++ b/partner_create_by_vat/i18n/ro.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_create_by_vat +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-12-14 06:25+0000\n" +"PO-Revision-Date: 2015-12-14 06:25+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_create_by_vat +#: code:addons/partner_create_by_vat/models/res_partner.py:27 +#: code:addons/partner_create_by_vat/models/res_partner.py:30 +#: code:addons/partner_create_by_vat/models/res_partner.py:57 +#: code:addons/partner_create_by_vat/models/res_partner.py:61 +#, python-format +msgid "Error!" +msgstr "Eroare!" + +#. module: partner_create_by_vat +#: view:res.partner:partner_create_by_vat.view_partner_create_by_vat +msgid "Get Partner Data" +msgstr "Preia Date Partener" + +#. module: partner_create_by_vat +#: code:addons/partner_create_by_vat/models/res_partner.py:31 +#, python-format +msgid "No VAT number inputted." +msgstr "Număr TVA neintrodus" + +#. module: partner_create_by_vat +#: model:ir.model,name:partner_create_by_vat.model_res_partner +msgid "Partner" +msgstr "Partener" + +#. module: partner_create_by_vat +#: code:addons/partner_create_by_vat/models/res_partner.py:58 +#, python-format +msgid "The partner doesn't have the name and address listed on Vies Webservice." +msgstr "Partenerul nu are numele și adresa listată pe site-ul Vies." + +#. module: partner_create_by_vat +#: code:addons/partner_create_by_vat/models/res_partner.py:62 +#, python-format +msgid "The partner is not listed on Vies Webservice." +msgstr "Partenerul nu este listat pe site-ul Vies." + +#. module: partner_create_by_vat +#: code:addons/partner_create_by_vat/models/res_partner.py:28 +#, python-format +msgid "VAT number invalid." +msgstr "Număr TVA invalid" + diff --git a/partner_create_by_vat/models/__init__.py b/partner_create_by_vat/models/__init__.py new file mode 100644 index 000000000..9fd77dd8e --- /dev/null +++ b/partner_create_by_vat/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_partner diff --git a/partner_create_by_vat/models/res_partner.py b/partner_create_by_vat/models/res_partner.py new file mode 100644 index 000000000..9ffe17e5a --- /dev/null +++ b/partner_create_by_vat/models/res_partner.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from openerp import api, models, _ +from openerp.exceptions import ValidationError + +_logger = logging.getLogger(__name__) + +try: + from stdnum.eu.vat import check_vies +except ImportError: + _logger.debug("Cannot import check_vies method from python stdnum.") + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.model + def _get_vies_data(self, vat): + res = {} + vat = vat.strip().upper() + vat_country, vat_number = self._split_vat(vat) + result = check_vies(vat) + # Raise error if partner is not listed on Vies + if result.name is None: + raise ValidationError(_("The partner is not listed on Vies " + "Webservice.")) + res['vat'] = vat + res['vat_subjected'] = result.valid + # Update partner name if listed on VIES + if result.name != '---': + res['name'] = result.name.upper() + # Update partner address if listed on VIES + if result.address != '---': + res['street'] = \ + result.address.replace('\n', ' ').replace('\r', '').title() + # Get country by country code + country = self.env['res.country'].search( + [('code', 'ilike', vat_country)]) + if country: + res['country_id'] = country[0].id + return res + + @api.multi + def vat_change(self, value): + res = super(ResPartner, self).vat_change(value) + # Update fields with the values available in the upper method + # Skip required name error + with self.env.do_in_onchange(): + if value: + result = self._get_vies_data(value) + res['value'].update(result) + return res + + @api.one + def get_vies_data_from_vat(self): + if self.vat: + res = self._get_vies_data(self.vat) + self.update(res) diff --git a/partner_create_by_vat/static/description/customer.png b/partner_create_by_vat/static/description/customer.png new file mode 100644 index 000000000..8894300b2 Binary files /dev/null and b/partner_create_by_vat/static/description/customer.png differ diff --git a/partner_create_by_vat/static/description/customer1.png b/partner_create_by_vat/static/description/customer1.png new file mode 100644 index 000000000..e47c56822 Binary files /dev/null and b/partner_create_by_vat/static/description/customer1.png differ diff --git a/partner_create_by_vat/static/description/icon.png b/partner_create_by_vat/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_create_by_vat/static/description/icon.png differ diff --git a/partner_create_by_vat/tests/__init__.py b/partner_create_by_vat/tests/__init__.py new file mode 100644 index 000000000..a4cb1837c --- /dev/null +++ b/partner_create_by_vat/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_partner_create_by_vat diff --git a/partner_create_by_vat/tests/test_partner_create_by_vat.py b/partner_create_by_vat/tests/test_partner_create_by_vat.py new file mode 100644 index 000000000..aa746c930 --- /dev/null +++ b/partner_create_by_vat/tests/test_partner_create_by_vat.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# © 2015 Forest and Biomass Services Romania +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +from openerp.exceptions import ValidationError + + +class TestPartnerCreatebyVAT(TransactionCase): + + def setUp(self): + super(TestPartnerCreatebyVAT, self).setUp() + self.partner_model = self.env['res.partner'] + + def test_create_from_vat1(self): + # Create an partner from VAT number field + self.partner1_id = self.partner_model.create({'name': '1', + 'vat': 'be0477472701', + 'is_company': True}) + + # Push the button to fetch partner's data + self.partner1_id.get_vies_data_from_vat() + + # Check if the datas fetch correspond with the datas from VIES. + self.assertEqual(self.partner1_id.name, 'SA ODOO') + self.assertEqual( + unicode(self.partner1_id.street), + u'Chaussée De Namur 40 1367 Ramillies' + ) + self.assertEqual(self.partner1_id.country_id.name, 'Belgium') + self.assertEqual(self.partner1_id.vat, 'BE0477472701') + self.assertEqual(self.partner1_id.vat_subjected, True) + + def test_vat_change1(self): + # Create an partner from VAT number field + self.partner11_id = self.partner_model.create({'name': '1', + 'is_company': True}) + + with self.env.do_in_onchange(): + res = self.partner11_id.vat_change('be0477472701') + self.partner11_id.update(res['value']) + + # Check if the datas fetch correspond with the datas from VIES. + self.assertEqual(self.partner11_id.name, 'SA ODOO') + self.assertEqual( + unicode(self.partner11_id.street), + u'Chaussée De Namur 40 1367 Ramillies' + ) + self.assertEqual(self.partner11_id.country_id.name, 'Belgium') + self.assertEqual(self.partner11_id.vat, 'BE0477472701') + self.assertEqual(self.partner11_id.vat_subjected, True) + + def test_create_from_vat2(self): + # Create an partner from VAT number field + self.partner2_id = self.partner_model.create({'name': '1', + 'vat': 'ro16507426', + 'is_company': True}) + + # Check VAT number not listed on VIES + with self.assertRaises(ValidationError): + self.partner2_id.get_vies_data_from_vat() diff --git a/partner_create_by_vat/views/res_partner_view.xml b/partner_create_by_vat/views/res_partner_view.xml new file mode 100644 index 000000000..a3353e03a --- /dev/null +++ b/partner_create_by_vat/views/res_partner_view.xml @@ -0,0 +1,23 @@ + + + + + + res.partner.create.by.vat + res.partner + + + +