Browse Source

[[MIG] partner_create_by_vat: Migrated to 10.0. (#325)

* [[MIG] partner_create_by_vat: Migrated to 10.0.

* Remove images, update travis, add requirements.

* Add images, update manifest.

* Update pylint, tabs..

* Update view, vat term.

* Update test, vat number for not listed partner on vies, since from 1st of January all romanian companies that are vat_subjected are listed on VIES.
pull/429/head
Fekete Mihai 8 years ago
committed by Rafael Blasco
parent
commit
4bd4937a7f
  1. 2
      .travis.yml
  2. 70
      partner_create_by_vat/README.rst
  3. 5
      partner_create_by_vat/__init__.py
  4. 26
      partner_create_by_vat/__manifest__.py
  5. 35
      partner_create_by_vat/i18n/es.po
  6. 34
      partner_create_by_vat/i18n/ro.po
  7. 35
      partner_create_by_vat/i18n/sl.po
  8. 5
      partner_create_by_vat/models/__init__.py
  9. 64
      partner_create_by_vat/models/res_partner.py
  10. BIN
      partner_create_by_vat/static/description/customer.png
  11. BIN
      partner_create_by_vat/static/description/customer1.png
  12. BIN
      partner_create_by_vat/static/description/icon.png
  13. 5
      partner_create_by_vat/tests/__init__.py
  14. 73
      partner_create_by_vat/tests/test_partner_create_by_vat.py
  15. 28
      partner_create_by_vat/views/res_partner_view.xml
  16. 4
      requirements.txt

2
.travis.yml

@ -29,8 +29,6 @@ virtualenv:
system_site_packages: true
install:
- pip install requests
- pip install unicodecsv
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly

70
partner_create_by_vat/README.rst

@ -0,0 +1,70 @@
.. 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 10.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/10.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.
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.

5
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

26
partner_create_by_vat/__manifest__.py

@ -0,0 +1,26 @@
# -*- 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': '10.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/icon.png',
'static/description/customer.png',
'static/description/customer1.png'],
'auto_install': False,
}

35
partner_create_by_vat/i18n/es.po

@ -0,0 +1,35 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_create_by_vat
#
# Translators:
# Oihane Crucelaegui <oihanecruce@gmail.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: partner-contact (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-03 07:56+0000\n"
"PO-Revision-Date: 2016-07-04 07:42+0000\n"
"Last-Translator: Oihane Crucelaegui <oihanecruce@gmail.com>\n"
"Language-Team: Spanish (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: partner_create_by_vat
#: view:res.partner:partner_create_by_vat.view_partner_create_by_vat
msgid "Get Vies Data"
msgstr ""
#. module: partner_create_by_vat
#: model:ir.model,name:partner_create_by_vat.model_res_partner
msgid "Partner"
msgstr "Empresa"
#. module: partner_create_by_vat
#: code:addons/partner_create_by_vat/models/res_partner.py:29
#, python-format
msgid "The partner is not listed on Vies Webservice."
msgstr ""

34
partner_create_by_vat/i18n/ro.po

@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_create_by_vat
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: partner-contact (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-05-07 07:18+0000\n"
"PO-Revision-Date: 2016-05-06 15:15+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>\n"
"Language-Team: Romanian (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/ro/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: ro\n"
"Plural-Forms: nplurals=3; plural=(n==1?0:(((n%100>19)||((n%100==0)&&(n!=0)))?2:1));\n"
#. module: partner_create_by_vat
#: view:res.partner:partner_create_by_vat.view_partner_create_by_vat
msgid "Get Vies Data"
msgstr ""
#. 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:29
#, python-format
msgid "The partner is not listed on Vies Webservice."
msgstr "Partenerul nu este listat pe site-ul Vies."

35
partner_create_by_vat/i18n/sl.po

@ -0,0 +1,35 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_create_by_vat
#
# Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2016
msgid ""
msgstr ""
"Project-Id-Version: partner-contact (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-05-07 07:18+0000\n"
"PO-Revision-Date: 2016-05-07 07:16+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\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_create_by_vat
#: view:res.partner:partner_create_by_vat.view_partner_create_by_vat
msgid "Get Vies Data"
msgstr "Pridobi podatke VIES"
#. module: partner_create_by_vat
#: model:ir.model,name:partner_create_by_vat.model_res_partner
msgid "Partner"
msgstr "Partner"
#. module: partner_create_by_vat
#: code:addons/partner_create_by_vat/models/res_partner.py:29
#, python-format
msgid "The partner is not listed on Vies Webservice."
msgstr "Partnerja ni na seznamu spletne storitve VIES."

5
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

64
partner_create_by_vat/models/res_partner.py

@ -0,0 +1,64 @@
# -*- 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 odoo import api, fields, models, _
from odoo.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"
vat_subjected = fields.Boolean('VAT Legal Statement')
@api.model
def _get_vies_data(self):
res = {}
vat = self.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.onchange('vat')
def vat_change(self):
res = {'value': {}}
# Update fields with the values available in the upper method
# Skip required name error
with self.env.do_in_onchange():
if self.vat:
result = self._get_vies_data()
res['value'].update(result)
return res
@api.one
def get_vies_data_from_vat(self):
if self.vat:
res = self._get_vies_data()
self.update(res)

BIN
partner_create_by_vat/static/description/customer.png

After

Width: 1852  |  Height: 966  |  Size: 115 KiB

BIN
partner_create_by_vat/static/description/customer1.png

After

Width: 1834  |  Height: 855  |  Size: 117 KiB

BIN
partner_create_by_vat/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 12 KiB

5
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

73
partner_create_by_vat/tests/test_partner_create_by_vat.py

@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
# © 2015 Forest and Biomass Services Romania
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from openerp.tests.common import TransactionCase
from openerp.exceptions import ValidationError
mock_vies = 'openerp.addons.partner_create_by_vat.' \
'models.res_partner.check_vies'
class TestPartnerCreatebyVAT(TransactionCase):
def setUp(self):
super(TestPartnerCreatebyVAT, self).setUp()
self.partner_model = self.env['res.partner']
self.sample_1 = {
'valid': True,
'name': u'SA ODOO',
'address': u'Chaussée De Namur 40 1367 Ramillies',
}
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})
with mock.patch(mock_vies) as mock_func:
mock_func.return_value = type('obj', (object,), self.sample_1)
# 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(
unicode(self.partner1_id.name), self.sample_1['name'])
self.assertEqual(
unicode(self.partner1_id.street), self.sample_1['address'])
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():
with mock.patch(mock_vies) as mock_func:
mock_func.return_value = type('obj', (object,), self.sample_1)
self.partner11_id.vat = 'be0477472701'
res = self.partner11_id.vat_change()
self.partner11_id.update(res['value'])
# Check if the datas fetch correspond with the datas from VIES.
self.assertEqual(
unicode(self.partner11_id.name), self.sample_1['name'])
self.assertEqual(
unicode(self.partner11_id.street), self.sample_1['address'])
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': 'ro4400972',
'is_company': True})
# Check VAT number not listed on VIES
with self.assertRaises(ValidationError):
self.partner2_id.get_vies_data_from_vat()

28
partner_create_by_vat/views/res_partner_view.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<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.view_partner_form"/>
<field name="arch" type="xml">
<field name="vat" position="after">
<label for="vat_subjected"/>
<div name="vat_subjected_info" class="o_row">
<field name="vat_subjected"
attrs="{'invisible': [
('vat', '=', False),
('is_company', '=', False )]}"/>
<button name="get_vies_data_from_vat"
attrs="{'invisible': [
('vat', '=', False),
('is_company', '=', False )]}"
colspan="2" string="Get Vies Data"
type="object" icon="fa-cogs"/>
</div>
</field>
</field>
</record>
</odoo>

4
requirements.txt

@ -0,0 +1,4 @@
python-stdnum==1.1
suds
requests
unicodecsv
Loading…
Cancel
Save