This question has been flagged
2 Replies
3499 Views

Fairly new to python but learning and could use some experience here. I want to  use python-phonenumbers class 'AsYouTypeFormatter' found here: https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/phonenumbers/asyoutypeformatter.py to format phone numbers into (xxx) xxx-xxxx US format as the user enters them. Can somebody please tell me if this is possible and maybe where to begin.

Formatting phone numbers in Odoo seems to be a nightmare. I found a few modules but they make the numbers clickable for telephony, I just want properly formatted numbers in the DB.

Thanks in advance for any help.

 

Avatar
Discard
Best Answer

Yes, its possible. I think the requirement is to be done in odoo 8 right? Then you can create a compute field, which calls the function to format value in required format. For that compute function, the link you have given can be used. I can help you doing that or to create a custom module for you. Please contact for any queries: baijuks@hotmail.com, akhil.p.sivan007@gmail.com.

Avatar
Discard
Best Answer

The only struggle I think you will find is the "asyoutype" part. Odoo basically only serves state-based web-pages, so for these things you will likely resort to javascript.

Make sure that the code is accessable using import like any standard library (look up python path). Next up, make sure the formatted number is stored as something Odoo will still accept. If you want formatting and/or symbols other than number, you should likely create a char or text field on the partner. If I recall correctly, in Odoo the phone number field already is such a field.

I think your best bet would be to check out other javascript code in the modules to see how Odoo handles input character by character, as that essentially is what you need.

Alternatively (and much easier) you could create an on_change method for the field. Then, if someone is finished typing in all the digits and skips to the next field, the number will be validated, formatted and returned to the field. Like an auto_correct functionality. On_change is default in Odoo.

Avatar
Discard