Skip to content

Commit

Permalink
fix(import): Correction sur l'import des numéros de téléphone (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller authored May 24, 2024
1 parent fb50bc1 commit b352489
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
9 changes: 4 additions & 5 deletions lemarche/siaes/management/commands/import_esat_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def handle(self, *args, **options): # noqa C901
already_exists += 1

contact_email_before = siae.contact_email
if email and email != contact_email_before:
if siae.user_count == 0: # update only if siae has no user
if siae.user_count == 0: # update only if siae has no user
if email and email != contact_email_before:
email_updated += 1
if options["dry_run"]:
self.stdout_info(f"Email need update :{contact_email_before} <- {email}")
Expand All @@ -57,9 +57,8 @@ def handle(self, *args, **options): # noqa C901
siae.save()
self.stdout_success(f"Email updated :{contact_email_before} <- {email}")

contact_phone_before = siae.contact_phone.replace(" ", "")
if phone and phone != contact_phone_before:
if siae.user_count == 0: # update only if siae has no user
contact_phone_before = siae.contact_phone
if phone:
phone_updated += 1
if options["dry_run"]:
self.stdout_info(f"Phone need update :{contact_phone_before} <- {phone}")
Expand Down
28 changes: 11 additions & 17 deletions lemarche/siaes/management/commands/import_new_sep.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def handle(self, *args, **options): # noqa C901
siae_same_city, data["Email 1"], options["dry_run"]
)

phone_updated += self.update_phone_if_different(
siae_same_city, data["Téléphone"], options["dry_run"]
)
phone_updated += self.update_phone(siae_same_city, data["Téléphone"], options["dry_run"])

# add other
for data in datas:
Expand Down Expand Up @@ -127,9 +125,7 @@ def handle(self, *args, **options): # noqa C901
email_updated += self.update_email_if_different(
siae_same_siret, data["Email 1"], options["dry_run"]
)
phone_updated += self.update_phone_if_different(
siae_same_siret, data["Téléphone"], options["dry_run"]
)
phone_updated += self.update_phone(siae_same_siret, data["Téléphone"], options["dry_run"])
except Siae.DoesNotExist:
added += 1
if options["dry_run"]:
Expand Down Expand Up @@ -176,15 +172,13 @@ def update_email_if_different(self, siae, email, dry_run):
return 1
return 0

def update_phone_if_different(self, siae, phone, dry_run):
phone_before = siae.contact_phone.replace(" ", "")
def update_phone(self, siae, phone, dry_run):
phone_before = siae.contact_phone
phone = phone.replace(" ", "")
if phone_before != phone:
if dry_run:
self.stdout_info(f"Contact phone need update : {phone_before} <- {phone}")
else:
siae.contact_phone = phone
siae.save()
self.stdout_success(f"Phone updated :{phone_before} <- {phone}")
return 1
return 0
if dry_run:
self.stdout_info(f"Contact phone need update : {phone_before} <- {phone}")
else:
siae.contact_phone = phone
siae.save()
self.stdout_success(f"Phone updated :{phone_before} <- {phone}")
return 1

0 comments on commit b352489

Please sign in to comment.