Skip to content

Commit

Permalink
[IMP] partner_data_vies_populator: populate Zip code and City
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Sep 23, 2024
1 parent 1c05db5 commit 96e9267
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
21 changes: 17 additions & 4 deletions partner_data_vies_populator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ This module allows you to create the partners (companies) based on their VAT num
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
http://ec.europa.eu/taxation_customs/vies

Unfortunately, VIES doesn't return a structured address but just a one-line address that aggregate street, zip and city. So, when you use this module to create a partner, the *City* and *Zip* fields will be left empty ; the *Street* field will contain the one-line address.
Unfortunately, VIES doesn't return a structured address but just a multi-line string
with aggregate street, zip and city.

So, when the data is retrieved, it will try to populate the *City* and *Zip* fields
from the last line of the address.
T he *Street* field will contain the remaining information.

**Table of contents**

Expand All @@ -44,12 +49,16 @@ Unfortunately, VIES doesn't return a structured address but just a one-line addr
Installation
============

This module require the `python-stdnum <https://pypi.org/project/python-stdnum/>`_ librairy. As Odoo itself depend on this librairy, it should already be installed on your system.
This module require the `python-stdnum <https://pypi.org/project/python-stdnum/>`_ library.
As Odoo itself depends on this librairy, it should already be installed on your system.

Usage
=====

When changing a company partner VAT number, this module will try to fetch the partner data from VIES webservice, if available on VIES will update the name, address and country.
When changing a company partner VAT number, this module will try
to fetch the partner data from VIES webservice.

If found on VIES, it will update the name, address, zip, city and country.

Bug Tracker
===========
Expand Down Expand Up @@ -87,6 +96,10 @@ Contributors

* Jeremy Didderen <[email protected]>

* `Open Source Integrators <https://opensourceintegrators.com>`_

* Daniel Reis <[email protected]>

Maintainers
~~~~~~~~~~~

Expand Down
9 changes: 6 additions & 3 deletions partner_data_vies_populator/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ def _get_vies_data(self, vat, raise_if_fail=False):
if result.name != "---":
res["name"] = result.name.upper()
# Update partner address if listed on VIES
# Last line can be "ZipCode City"
if result.address != "---":
res["street"] = (
result.address.replace("\n", " ").replace("\r", "").title()
)
address_parts = result.address.split("\n")
if len(address_parts) > 1 and " " in address_parts[-1]:
zip_city = address_parts.pop()
res["zip"], res["city"] = zip_city.split(" ", 1)
res["street"] = " ".join(address_parts)
# Get country by country code
country = self.env["res.country"].search(
[("code", "ilike", result.countryCode)]
Expand Down
4 changes: 4 additions & 0 deletions partner_data_vies_populator/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
* `Noviat <https://www.noviat.com/>`_ :

* Jeremy Didderen <[email protected]>

* `Open Source Integrators <https://opensourceintegrators.com>`_

* Daniel Reis <[email protected]>
9 changes: 7 additions & 2 deletions partner_data_vies_populator/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ This module allows you to create the partners (companies) based on their VAT num
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
http://ec.europa.eu/taxation_customs/vies

Unfortunately, VIES doesn't return a structured address but just a one-line address that aggregate street, zip and city. So, when you use this module to create a partner, the *City* and *Zip* fields will be left empty ; the *Street* field will contain the one-line address.
Unfortunately, VIES doesn't return a structured address but just a multi-line string
with aggregate street, zip and city.

So, when the data is retrieved, it will try to populate the *City* and *Zip* fields
from the last line of the address.
T he *Street* field will contain the remaining information.
3 changes: 2 additions & 1 deletion partner_data_vies_populator/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module require the `python-stdnum <https://pypi.org/project/python-stdnum/>`_ librairy. As Odoo itself depend on this librairy, it should already be installed on your system.
This module require the `python-stdnum <https://pypi.org/project/python-stdnum/>`_ library.
As Odoo itself depends on this librairy, it should already be installed on your system.
5 changes: 4 additions & 1 deletion partner_data_vies_populator/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
When changing a company partner VAT number, this module will try to fetch the partner data from VIES webservice, if available on VIES will update the name, address and country.
When changing a company partner VAT number, this module will try
to fetch the partner data from VIES webservice.

If found on VIES, it will update the name, address, zip, city and country.
19 changes: 15 additions & 4 deletions partner_data_vies_populator/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,12 @@ <h1 class="title">Partner Data VIES Populator</h1>
<p>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.</p>
<p>VIES Service (based on stdnum python)
<a class="reference external" href="http://ec.europa.eu/taxation_customs/vies/vieshome.do">http://ec.europa.eu/taxation_customs/vies/vieshome.do</a></p>
<p>Unfortunately, VIES doesn’t return a structured address but just a one-line address that aggregate street, zip and city. So, when you use this module to create a partner, the <em>City</em> and <em>Zip</em> fields will be left empty ; the <em>Street</em> field will contain the one-line address.</p>
<a class="reference external" href="http://ec.europa.eu/taxation_customs/vies">http://ec.europa.eu/taxation_customs/vies</a></p>
<p>Unfortunately, VIES doesn’t return a structured address but just a multi-line string
with aggregate street, zip and city.</p>
<p>So, when the data is retrieved, it will try to populate the <em>City</em> and <em>Zip</em> fields
from the last line of the address.
T he <em>Street</em> field will contain the remaining information.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -390,11 +394,14 @@ <h1 class="title">Partner Data VIES Populator</h1>
</div>
<div class="section" id="installation">
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>This module require the <a class="reference external" href="https://pypi.org/project/python-stdnum/">python-stdnum</a> librairy. As Odoo itself depend on this librairy, it should already be installed on your system.</p>
<p>This module require the <a class="reference external" href="https://pypi.org/project/python-stdnum/">python-stdnum</a> library.
As Odoo itself depends on this librairy, it should already be installed on your system.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>When changing a company partner VAT number, this module will try to fetch the partner data from VIES webservice, if available on VIES will update the name, address and country.</p>
<p>When changing a company partner VAT number, this module will try
to fetch the partner data from VIES webservice.</p>
<p>If found on VIES, it will update the name, address, zip, city and country.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
Expand Down Expand Up @@ -429,6 +436,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Jeremy Didderen &lt;<a class="reference external" href="mailto:jeremy.didderen&#64;noviat.com">jeremy.didderen&#64;noviat.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://opensourceintegrators.com">Open Source Integrators</a><ul>
<li>Daniel Reis &lt;<a class="reference external" href="mailto:dreis&#64;opensourceintegrators.com">dreis&#64;opensourceintegrators.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ def setUpClass(cls):
cls.be_country_id = cls.env.ref("base.be").id
cls.sample_1 = {
"name": "SA ODOO",
"address": "Chaussée De Namur 40 1367 Ramillies",
"address": "Chaussée de Namur 40",
"zip": "1367",
"city": "Ramillies",
"country_code": "BE",
}

def test_create_from_vat1(self):
# Create an partner from VAT number field
with Form(self.partner_model) as partner_form:
partner_form.is_company = True
partner_form.company_type = "company"
partner_form.vat = "be0477472701"

# Check if the datas fetch correspond with the datas from VIES.
Expand Down

0 comments on commit 96e9267

Please sign in to comment.