# Improve PostalCode subdivision data import

**URL:** https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226
**Category:** Ideas
**Created:** [June 3, 2023, 7:49am UTC](https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226 "2023-06-03T07:49:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lars\_wuerfel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lars_wuerfel/32/2794_2.png) [@lars\_wuerfel](https://discuss.tryton.org/u/lars_wuerfel)
#### Post date: [June 3, 2023, 7:49am UTC](https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226/1 "2023-06-03T07:49:40Z")

</div>

When writing a Proteus script to revise the subdivisions of a huge Party address pool,  
I saw that there are countries that do not have a subdivision for all postal codes in the PostalCode module (for example Netherlands and Austria), and I found that France has two subdivisions per postal code, one of which is false for every postal code.

As far as I understand - please correct me if I’m wrong - the Country data is from [Python pycountry](https://pypi.org/project/pycountry/), and the postal code data comes from [geonames.org](http://geonames.org) .

The problem that I found is that pycountry

- uses [ISO 3166-2](https://www.iso.org/obp/ui/#iso:pub:PUB500001:en) code to identify a subdivision

whereas the export file from [geonames.org](http://geonames.org)

- in some files uses ISO codes to identify subdivisions (for example in DE.txt)
- but in other files uses [FIPS](https://en.wikipedia.org/wiki/List_of_FIPS_region_codes) region codes to identify subdivisions (for example in NL.txt and AT.txt)

Example: The Netherlands, subdivision “Flevoland”  
ISO 3166-2 code (from pycountry): NL-FL  
FIPS code (from [geonames.org](http://geonames.org)): NL-16

Example: Austria, subdivision “Kärnten”  
ISO 3166-2 code (from pycountry): AT-2  
FIPS code (from [geonames.org](http://geonames.org)): AT-02

As a result, no subdivision is available in Tryton for all postal codes in NL and AT.

To improve the situation I would  
(1) analyze for which of the 96 available postal code files this problem exists  
(2) give the trytond\_import\_postal\_codes script a “translation table” from FIPS to ISO codes for the affected postal code files.

I would like to contribute and work on this topic, but I may not see the big picture at the moment.  
If I am on the wrong track, or the effort will forseeable fail, please tell me.

Other thoughts on how to get the subdivisions right in Tryton?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 3, 2023, 8:11am UTC](https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226/2 "2023-06-03T08:11:15Z")

</div>

> [@lars\_wuerfel](#):
>
> I found that France has two subdivisions per postal code, one of which is false for every postal code

Why is it false?

> [@lars\_wuerfel](#):
>
> but in other files uses [FIPS](https://en.wikipedia.org/wiki/List_of_FIPS_region_codes) region codes to identify subdivisions (for example in NL.txt and AT.txt)

Since September 2 2008, FIPS is deprecated.

> [@lars\_wuerfel](#):
>
> Other thoughts on how to get the subdivisions right in Tryton?

I think we should try to convince GeoNames to use ISO 3166-2 for all the files. Because we will not be able to maintain a compatibility table between FIPS and ISO.

---

<div class="post-metadata">

### Author: ![lars\_wuerfel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lars_wuerfel/32/2794_2.png) [@lars\_wuerfel](https://discuss.tryton.org/u/lars_wuerfel)
#### Post date: [June 3, 2023, 9:27am UTC](https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226/3 "2023-06-03T09:27:52Z")

</div>

> [@ced](#):
>
> > [@lars\_wuerfel](#):
> >
> > I found that France has two subdivisions per postal code, one of which is false for every postal code
> 
> Why is it false?

For example I pick the french town “Dôle”. It is situated in the département “Jura” (ISO: FR-39) which lies in the region “Bourgogne-Franche-Comté” (ISO: FR-BFC).

 ![dole](https://discuss-cdn.tryton.org/uploads/default/original/2X/1/1c41ed9290b096b894041814158539564c33b6b9.png)  
(Screenshot taken from Tryton 6.9, same in 6.8)

According to Tryton, Dôle is at the same time in both départements “Jura” (Bourgogne-Franche-Comté) and “Eure” (Normandie). This is false.

I think we can see the cause for this error [here](https://www.geonames.org/FR/administrative-division-france.html). The row “GN” is taken as identifier (here: 27), which is mapped to “FR-27”, which is the ISO code for département “Eure”.

---

<div class="post-metadata">

### Author: ![lars\_wuerfel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lars_wuerfel/32/2794_2.png) [@lars\_wuerfel](https://discuss.tryton.org/u/lars_wuerfel)
#### Post date: [June 3, 2023, 9:29am UTC](https://discuss.tryton.org/t/improve-postalcode-subdivision-data-import/6226/4 "2023-06-03T09:29:25Z")

</div>

> [@ced](#):
>
> I think we should try to convince GeoNames to use ISO 3166-2 for all the files. Because we will not be able to maintain a compatibility table between FIPS and ISO.

Ok, I will contact them and aks if it is possible. I will report here.
