From 742c71d356f28f47b23f61b5277bf95d83240ed9 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Thu, 1 Feb 2024 22:43:58 -0300 Subject: [PATCH] feat: fill name in sync subscription --- bd_api/apps/account/models.py | 6 +++++- bd_api/apps/account/tasks.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bd_api/apps/account/models.py b/bd_api/apps/account/models.py index 286e1516..d5b06fe6 100644 --- a/bd_api/apps/account/models.py +++ b/bd_api/apps/account/models.py @@ -346,7 +346,11 @@ def get_short_name(self): get_short_name.short_description = "nome" def get_full_name(self): - return f"{self.first_name} {self.last_name}" + if self.first_name and self.last_name: + return f"{self.first_name} {self.last_name}" + if self.first_name: + return self.first_name + return self.username get_full_name.short_description = "nome completo" diff --git a/bd_api/apps/account/tasks.py b/bd_api/apps/account/tasks.py index 00f1df25..2cff97d7 100644 --- a/bd_api/apps/account/tasks.py +++ b/bd_api/apps/account/tasks.py @@ -33,8 +33,12 @@ def sync_subscription_task( admin = admin or Account.objects.filter( email=subscription.customer.email, ).first() # fmt: skip + full_name = subscription.customer.name.title() + first_name, last_name = full_name.split(" ") admin = admin or Account.objects.create( is_active=True, + last_name=last_name, + first_name=first_name, email=subscription.customer.email, username=subscription.customer.email.split("@")[0], )