Improve PostalCode subdivision data import

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, and the postal code data comes from geonames.org .

The problem that I found is that pycountry

whereas the export file from geonames.org

  • in some files uses ISO codes to identify subdivisions (for example in DE.txt)
  • but in other files uses FIPS 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): NL-16

Example: Austria, subdivision “Kärnten”
ISO 3166-2 code (from pycountry): AT-2
FIPS code (from 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?

Why is it false?

Since September 2 2008, FIPS is deprecated.

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.

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).


(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. The row “GN” is taken as identifier (here: 27), which is mapped to “FR-27”, which is the ISO code for département “Eure”.

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

1 Like