From 96e92670ec0c3abcc41489efcd291f656240a049 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 10 Jan 2024 16:32:42 -0500 Subject: [PATCH] [IMP] partner_data_vies_populator: populate Zip code and City --- partner_data_vies_populator/README.rst | 21 +++++++++++++++---- .../models/res_partner.py | 9 +++++--- .../readme/CONTRIBUTORS.rst | 4 ++++ .../readme/DESCRIPTION.rst | 9 ++++++-- .../readme/INSTALL.rst | 3 ++- partner_data_vies_populator/readme/USAGE.rst | 5 ++++- .../static/description/index.html | 19 +++++++++++++---- .../tests/test_partner_data_vies_populator.py | 6 ++++-- 8 files changed, 59 insertions(+), 17 deletions(-) diff --git a/partner_data_vies_populator/README.rst b/partner_data_vies_populator/README.rst index 0913986b624..9f2d5cf46f0 100644 --- a/partner_data_vies_populator/README.rst +++ b/partner_data_vies_populator/README.rst @@ -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** @@ -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 `_ librairy. As Odoo itself depend on this librairy, it should already be installed on your system. +This module require the `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 =========== @@ -87,6 +96,10 @@ Contributors * Jeremy Didderen +* `Open Source Integrators `_ + + * Daniel Reis + Maintainers ~~~~~~~~~~~ diff --git a/partner_data_vies_populator/models/res_partner.py b/partner_data_vies_populator/models/res_partner.py index 9be4e1de4ab..fd2030e42f9 100644 --- a/partner_data_vies_populator/models/res_partner.py +++ b/partner_data_vies_populator/models/res_partner.py @@ -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)] diff --git a/partner_data_vies_populator/readme/CONTRIBUTORS.rst b/partner_data_vies_populator/readme/CONTRIBUTORS.rst index e86b53f357e..c75443d7dfa 100644 --- a/partner_data_vies_populator/readme/CONTRIBUTORS.rst +++ b/partner_data_vies_populator/readme/CONTRIBUTORS.rst @@ -11,3 +11,7 @@ * `Noviat `_ : * Jeremy Didderen + +* `Open Source Integrators `_ + + * Daniel Reis diff --git a/partner_data_vies_populator/readme/DESCRIPTION.rst b/partner_data_vies_populator/readme/DESCRIPTION.rst index 30490fd0602..f0ec2257f46 100644 --- a/partner_data_vies_populator/readme/DESCRIPTION.rst +++ b/partner_data_vies_populator/readme/DESCRIPTION.rst @@ -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. diff --git a/partner_data_vies_populator/readme/INSTALL.rst b/partner_data_vies_populator/readme/INSTALL.rst index 0f872545f98..0791699a5b2 100644 --- a/partner_data_vies_populator/readme/INSTALL.rst +++ b/partner_data_vies_populator/readme/INSTALL.rst @@ -1 +1,2 @@ -This module require the `python-stdnum `_ librairy. As Odoo itself depend on this librairy, it should already be installed on your system. +This module require the `python-stdnum `_ library. +As Odoo itself depends on this librairy, it should already be installed on your system. diff --git a/partner_data_vies_populator/readme/USAGE.rst b/partner_data_vies_populator/readme/USAGE.rst index 4e84b2b1384..652286be304 100644 --- a/partner_data_vies_populator/readme/USAGE.rst +++ b/partner_data_vies_populator/readme/USAGE.rst @@ -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. diff --git a/partner_data_vies_populator/static/description/index.html b/partner_data_vies_populator/static/description/index.html index b181259405d..527eb0fd9e5 100644 --- a/partner_data_vies_populator/static/description/index.html +++ b/partner_data_vies_populator/static/description/index.html @@ -372,8 +372,12 @@

Partner Data VIES Populator

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

-

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.

+http://ec.europa.eu/taxation_customs/vies

+

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

    @@ -390,11 +394,14 @@

    Partner Data VIES Populator

Installation

-

This module require the python-stdnum librairy. As Odoo itself depend on this librairy, it should already be installed on your system.

+

This module require the 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.

diff --git a/partner_data_vies_populator/tests/test_partner_data_vies_populator.py b/partner_data_vies_populator/tests/test_partner_data_vies_populator.py index dd6c66013c2..f5665caa05c 100644 --- a/partner_data_vies_populator/tests/test_partner_data_vies_populator.py +++ b/partner_data_vies_populator/tests/test_partner_data_vies_populator.py @@ -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.