Fekete Mihai
9 years ago
committed by
Alexis de Lattre
12 changed files with 317 additions and 0 deletions
-
71partner_create_by_vat/README.rst
-
5partner_create_by_vat/__init__.py
-
25partner_create_by_vat/__openerp__.py
-
60partner_create_by_vat/i18n/ro.po
-
5partner_create_by_vat/models/__init__.py
-
62partner_create_by_vat/models/res_partner.py
-
BINpartner_create_by_vat/static/description/customer.png
-
BINpartner_create_by_vat/static/description/customer1.png
-
BINpartner_create_by_vat/static/description/icon.png
-
5partner_create_by_vat/tests/__init__.py
-
61partner_create_by_vat/tests/test_partner_create_by_vat.py
-
23partner_create_by_vat/views/res_partner_view.xml
@ -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 <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 |
||||
|
`here <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_create_by_vat%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Images |
||||
|
------ |
||||
|
|
||||
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Fekete Mihai <feketemihai@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,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 |
@ -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, |
||||
|
} |
@ -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" |
||||
|
|
@ -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 |
@ -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) |
After Width: 1611 | Height: 955 | Size: 118 KiB |
After Width: 1614 | Height: 955 | Size: 123 KiB |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -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 |
@ -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() |
@ -0,0 +1,23 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="view_partner_create_by_vat" model="ir.ui.view"> |
||||
|
<field name="name">res.partner.create.by.vat</field> |
||||
|
<field name="model">res.partner</field> |
||||
|
<field name="inherit_id" ref="base_vat.view_partner_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="vat" position="after"> |
||||
|
<button name="get_vies_data_from_vat" |
||||
|
attrs="{'invisible': [ |
||||
|
('vat', '=', False), |
||||
|
('is_company', '=', False )]}" |
||||
|
colspan="2" string="Get Vies Data" |
||||
|
type="object" icon="gtk-execute"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue