diff --git a/lemarche/siaes/models.py b/lemarche/siaes/models.py index 12c273088..8aef9c694 100644 --- a/lemarche/siaes/models.py +++ b/lemarche/siaes/models.py @@ -24,7 +24,7 @@ from lemarche.stats.models import Tracker from lemarche.users.models import User from lemarche.utils.constants import DEPARTMENTS_PRETTY, RECALCULATED_FIELD_HELP_TEXT, REGIONS_PRETTY -from lemarche.utils.data import round_by_base +from lemarche.utils.data import phone_number_display, round_by_base from lemarche.utils.fields import ChoiceArrayField from lemarche.utils.urls import get_object_admin_url from lemarche.utils.validators import validate_naf, validate_post_code, validate_siret @@ -168,6 +168,10 @@ def save(self, *args, **kwargs): self.set_last_updated_fields() super().save(*args, **kwargs) + @property + def contact_phone_display(self): + return phone_number_display(self.contact_phone) + class SiaeQuerySet(models.QuerySet): def is_live(self): @@ -1080,6 +1084,10 @@ def contact_short_name(self): return f"{self.contact_first_name.upper()[:1]}. {self.contact_last_name.upper()}" return "" + @property + def contact_phone_display(self): + return phone_number_display(self.contact_phone) + @property def geo_range_pretty_display(self): if self.geo_range == siae_constants.GEO_RANGE_COUNTRY: diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index fa6c0b73a..ab966bbaa 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -41,6 +41,7 @@ MARCHE_BENEFIT_CHOICES, RECALCULATED_FIELD_HELP_TEXT, ) +from lemarche.utils.data import phone_number_display from lemarche.utils.fields import ChoiceArrayField from lemarche.utils.urls import get_object_admin_url from lemarche.utils.validators import OptionalSchemeURLValidator @@ -779,6 +780,10 @@ def save(self, *args, **kwargs): def contact_full_name(self) -> str: return f"{self.contact_first_name} {self.contact_last_name}" + @property + def contact_phone_display(self): + return phone_number_display(self.contact_phone) + def contact_company_name_display(self) -> str: if self.contact_company_name: return self.contact_company_name diff --git a/lemarche/users/models.py b/lemarche/users/models.py index b0ddc9960..8571f9433 100644 --- a/lemarche/users/models.py +++ b/lemarche/users/models.py @@ -13,6 +13,7 @@ from lemarche.stats.models import StatsUser from lemarche.users import constants as user_constants +from lemarche.utils.data import phone_number_display from lemarche.utils.emails import anonymize_email @@ -354,6 +355,10 @@ def kind_detail_display(self): kind_detail_display_string += f" : {self.get_partner_kind_display()}" return kind_detail_display_string + @property + def phone_display(self): + return phone_number_display(self.phone) + @property def has_siae(self): return self.siaes.exists() diff --git a/lemarche/utils/apis/api_brevo.py b/lemarche/utils/apis/api_brevo.py index 3ec71be0d..7ecddff01 100644 --- a/lemarche/utils/apis/api_brevo.py +++ b/lemarche/utils/apis/api_brevo.py @@ -92,7 +92,7 @@ def create_or_update_company(siae): "address_post_code": siae.post_code, "address_city": siae.city, "contact_email": siae.contact_email, - "contact_phone": siae.contact_phone, + "contact_phone": siae.contact_phone_display, "domain": siae.website, "logo_url": siae.logo_url, "geo_range": siae.geo_range, diff --git a/lemarche/utils/apis/api_hubspot.py b/lemarche/utils/apis/api_hubspot.py index 33a5d91b6..1dbc9e71e 100644 --- a/lemarche/utils/apis/api_hubspot.py +++ b/lemarche/utils/apis/api_hubspot.py @@ -88,7 +88,7 @@ def add_user_to_crm(user): company=user.company_name, firstname=user.first_name, lastname=user.last_name, - phone=str(user.phone), + phone=user.phone_display, website=user.c4_website, ) if result and result.id: diff --git a/lemarche/utils/data.py b/lemarche/utils/data.py index bf5a3f819..def569bd5 100644 --- a/lemarche/utils/data.py +++ b/lemarche/utils/data.py @@ -64,3 +64,15 @@ def phone_number_is_valid(phone_number): return phonenumbers.is_valid_number(phonenumbers.parse(phone_number)) except phonenumbers.phonenumberutil.NumberParseException: return False + + +def phone_number_display(phone_number_model_field): + """ + https://django-phonenumber-field.readthedocs.io/en/latest/reference.html + phone.as_international --> +33 1 23 45 67 89 + phone.as_national --> 01 23 45 67 89 + phone.as_e164 --> +33123456789 + phone.as_rfc3966 --> tel:+33-1-23-45-67-89 + str(phone) --> +33123456789 + """ + return phone_number_model_field.as_e164 diff --git a/lemarche/utils/export.py b/lemarche/utils/export.py index 48304b824..556eeda07 100644 --- a/lemarche/utils/export.py +++ b/lemarche/utils/export.py @@ -69,6 +69,9 @@ def generate_siae_row(siae: Siae, siae_field_list): # ManyToManyFields elif field_name == "sectors": col_value = siae.sectors_full_list_string() + # Complex fields + elif field_name == "contact_phone": + col_value = siae.contact_phone_display # Custom fields elif field_name == "Inscrite": col_value = "Oui" if siae.user_count else "Non" diff --git a/lemarche/www/tenders/tasks.py b/lemarche/www/tenders/tasks.py index ccee69a08..17635f372 100644 --- a/lemarche/www/tenders/tasks.py +++ b/lemarche/www/tenders/tasks.py @@ -698,7 +698,7 @@ def send_super_siaes_email_to_author(tender: Tender, top_siaes: list[Siae]): "name": siae.name_display, "kind": siae.get_kind_display(), "contact_name": siae.contact_full_name, - "contact_phone": siae.contact_phone, + "contact_phone": siae.contact_phone_display, "contact_email": siae.contact_email, } ) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index f9d0ee8ba..29152d7e0 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -133,7 +133,7 @@ def test_tender_wizard_form_all_good_authenticated(self): self.assertEqual(tender.contact_first_name, self.user_buyer.first_name) self.assertEqual(tender.contact_last_name, self.user_buyer.last_name) self.assertEqual(tender.contact_email, self.user_buyer.email) - self.assertEqual(tender.contact_phone, self.user_buyer.phone) + self.assertEqual(tender.contact_phone_display, self.user_buyer.phone_display) def test_tender_wizard_form_not_created(self): self.client.force_login(self.user_buyer)