Phone number validation

I have a strange behavior in proteus.
i am trying to validate a party from CA with a phone number that tryton do not like.
i tried :

    x = phonenumbers.parse( '819-944-2765', 'CA')
    if phonenumbers.is_valid_number(x):
        print ("phone is VALID"); # <== the phone is valid

but tryton says :

 Le numéro de téléphone « +33 8199442765 » du tiers « Tartempion» n'est pas valide.

ok i could save it under others but i do not know how to do it. i tried to validate before with phonenumbers with no avails.

Tryton spits error when you save, not when you affect. how can i manage this ? Maybe there is a internal way of validation for tryton ?

Your party should have a country set on the addresses. Based on those countries Tryton will check if the phone number is valid.

I’ve tested it on the demo server and it just works. The phone number also got rewritten to ‘+1 819-944-2765’

the party has a country on the adress and the number is rewrite

Country = Model.get('country.country')
the_country, = Country.find([('code', '=', 'CA')])
party.addresses.append(Address(street=args.adresse,postal_code=args.cp, city=args.ville, country=the_country,invoice=True,delivery=True)) 
party.save() 
# Party should be saved with an adresse in Canada
party.contact_mechanisms.append(ContactMechanism(type='phone',value='819-944-2588'))
 
==> Le numéro de téléphone « +33 8199442588 » du tiers « tartempion » n'est pas valide. 

proteus-tryton tries to validate it as a french (???) number. i tried

with my_config.set_context(country='CA'):

but it did not work.

The party must be added to ContactMechanism creation in order to resolve the country from the address:

party.contact_mechanisms.append(ContactMechanism(party=party, type='phone',value='819-944-2588'))