From 276f60825a20ffcc9fd8cd78a380142bd51b4574 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 23 Nov 2015 10:27:21 +0100 Subject: [PATCH] Fix Nonetype error The countrycode may be None so we shouldn't call .upper() on it. Fixes #73 --- base_phone/base_phone.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base_phone/base_phone.py b/base_phone/base_phone.py index c178de3..2580168 100644 --- a/base_phone/base_phone.py +++ b/base_phone/base_phone.py @@ -82,6 +82,8 @@ class PhoneCommon(models.AbstractModel): "to allow the reformat of phone numbers", user.company_id.name) countrycode = None + if countrycode: + countrycode = countrycode.upper() # with country code = None, phonenumbers.parse() will work # with phonenumbers formatted in E164, but will fail with # phone numbers in national format @@ -90,7 +92,7 @@ class PhoneCommon(models.AbstractModel): init_value = vals.get(field) try: res_parse = phonenumbers.parse( - vals.get(field), countrycode.upper()) + vals.get(field), countrycode) vals[field] = phonenumbers.format_number( res_parse, phonenumbers.PhoneNumberFormat.E164) if init_value != vals[field]: