Allow to use local format when entering phone numbers

Rational

Since the addition of phone numbers validation the phone number requires the international prefix in order to be validated. It is quite common for the users to omit the international prefix when using their own local format.

Currently this causes an astonish behavior as they get an error about an invalid from number which is right for them (using their region format)

Proposal

Add a configuration value on the party configuration which will be only visible when the phonenumbers library is installed in order to specify the region to be used on validation.

If this configuration is set it will be used as region when parsing the number. Note that the region is ignored when using an international prefix:

>>> from phonenumbers import parse
>>> parse('666666666', 'ES')
PhoneNumber(country_code=34, national_number=666666666, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> parse('+33666666666', 'ES')
PhoneNumber(country_code=33, national_number=666666666, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> parse('0033666666666', 'ES')
PhoneNumber(country_code=33, national_number=666666666, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> parse('033666666666', 'ES')
PhoneNumber(country_code=34, national_number=33666666666, extension=None, italian_leading_zero=True, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> parse('0034666666666', 'ES')
PhoneNumber(country_code=34, national_number=666666666, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)

A list of available regions can be obtained with:

phonenumbers.phonenumberutil.SUPPORTED_REGIONS

So I propose to add a selection field with only the available options so we prevent selecting wrong values

Implementation

https://bugs.tryton.org/issue7831

I do not find that it solves completely the problem. If I enter a local number but for another country, as a user I will still have the astonishing behavior.
Maybe the error should be improved to be less astonishing. Or we could try to format against the countries of the party and/or company.

Formating against the countries of the party will be a good solution.
We can use the company (from context) country if the party does not have any country.

This topic was automatically closed after 7 days. New replies are no longer allowed.