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 Jan 10, 2024
1 parent a782116 commit a837f35
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 16 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
12 changes: 9 additions & 3 deletions partner_data_vies_populator/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ def _get_vies_data(self, vat, raise_if_fail=False):
) from None
return res
if result.valid and result.name:
import pudb; pu.db
res["vat"] = vat
# Update partner name if listed on VIES
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)]
)
if country:
res["country_id"] = country[0].id
print(result)
print(res)
return res

@api.onchange("vat")
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 @@ -373,8 +373,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 @@ -391,11 +395,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 @@ -430,6 +437,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,7 +13,9 @@ 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",
}

Expand Down

0 comments on commit a837f35

Please sign in to comment.