Skip to content

Commit

Permalink
Re-use existing klanten sync methods on user post_save signal
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Jan 13, 2025
1 parent e37ef66 commit 3d38a48
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions src/open_inwoner/accounts/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def update_user_on_login(sender, user, request, *args, **kwargs):


def _update_user_from_openklant2(
user: User, service: OpenKlant2Service, request
user: User, service: OpenKlant2Service, request: None = None
) -> None:
if fetch_params := service.get_fetch_parameters(request=request):
partij, created = service.get_or_create_partij_for_user(
Expand All @@ -69,7 +69,7 @@ def _update_user_from_openklant2(


def _update_user_from_esuite(
user: User, service: eSuiteKlantenService, request
user: User, service: eSuiteKlantenService, request: None = None
) -> None:
if not (fetch_params := service.get_fetch_parameters(request=request)):
return
Expand Down Expand Up @@ -107,49 +107,18 @@ def get_or_create_klant_for_new_user(
except Exception:
logger.error("OpenKlant2 service failed to build")
else:
if not (
fetch_params := service.get_fetch_parameters(
user=user, use_vestigingsnummer=True
)
):
return

partij, partij_created = service.get_or_create_partij_for_user(
fetch_params=fetch_params, user=user
_update_user_from_openklant2(
user,
service,
)
if not partij:
logger.error("Failed to create partij for new user %s", user)
return

if not partij_created:
service.update_user_from_partij(partij_uuid=partij["uuid"], user=user)

logger.info("Created partij %s for new user %s", partij, user)

# eSuite
try:
service = eSuiteKlantenService()
except Exception:
logger.error("eSuiteKlantenService failed to build")
else:
if not (
fetch_params := service.get_fetch_parameters(
user=user, use_vestigingsnummer=True
)
):
return

klant, klant_created = service.get_or_create_klant(
fetch_params=fetch_params, user=user
)
if not klant:
logger.error("Failed to create klant for new user %s", user)
return

if not klant_created:
service.update_user_from_klant(klant, user)

logger.info("Created klant %s for new user %s", klant, user)
_update_user_from_esuite(user, service)


@receiver(user_logged_in)
Expand Down

0 comments on commit 3d38a48

Please sign in to comment.