Merge pull request #940 from ae-utbm/fix-dump

Fix the account dump command.
This commit is contained in:
thomas girod 2024-12-05 19:52:07 +01:00 committed by GitHub
commit 9591162cc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -55,7 +55,9 @@ class Command(BaseCommand):
customer__user__in=reactivated_users customer__user__in=reactivated_users
).delete() ).delete()
self._dump_accounts({u.customer for u in users_to_dump}) self._dump_accounts({u.customer for u in users_to_dump})
self._send_mails(users_to_dump) self.stdout.write("Accounts dumped")
nb_successful_mails = self._send_mails(users_to_dump)
self.stdout.write(f"{nb_successful_mails} were successfuly sent.")
self.stdout.write("Finished !") self.stdout.write("Finished !")
@staticmethod @staticmethod
@ -103,13 +105,14 @@ class Command(BaseCommand):
if len(pending_dumps) != len(customer_ids): if len(pending_dumps) != len(customer_ids):
raise ValueError("One or more accounts were not engaged in a dump process") raise ValueError("One or more accounts were not engaged in a dump process")
counter = Counter.objects.get(pk=settings.SITH_COUNTER_ACCOUNT_DUMP_ID) counter = Counter.objects.get(pk=settings.SITH_COUNTER_ACCOUNT_DUMP_ID)
seller = User.objects.get(pk=settings.SITH_ROOT_USER_ID)
sales = Selling.objects.bulk_create( sales = Selling.objects.bulk_create(
[ [
Selling( Selling(
label="Vidange compte inactif", label="Vidange compte inactif",
club=counter.club, club=counter.club,
counter=counter, counter=counter,
seller=None, seller=seller,
product=None, product=None,
customer=account, customer=account,
quantity=1, quantity=1,
@ -134,8 +137,12 @@ class Command(BaseCommand):
Customer.objects.filter(pk__in=customer_ids).update(amount=0) Customer.objects.filter(pk__in=customer_ids).update(amount=0)
@staticmethod @staticmethod
def _send_mails(users: Iterable[User]): def _send_mails(users: Iterable[User]) -> int:
"""Send the mails informing users that their account has been dumped.""" """Send the mails informing users that their account has been dumped.
Returns:
The number of emails successfully sent.
"""
mails = [ mails = [
( (
_("Your AE account has been emptied"), _("Your AE account has been emptied"),
@ -145,4 +152,4 @@ class Command(BaseCommand):
) )
for user in users for user in users
] ]
send_mass_mail(mails) return send_mass_mail(mails, fail_silently=True)

View File

@ -351,6 +351,9 @@ SITH_SEMESTER_START_SPRING = (2, 15) # 15 February
# Used to determine the valid promos # Used to determine the valid promos
SITH_SCHOOL_START_YEAR = 1999 SITH_SCHOOL_START_YEAR = 1999
# id of the Root account
SITH_ROOT_USER_ID = 0
SITH_GROUP_ROOT_ID = 1 SITH_GROUP_ROOT_ID = 1
SITH_GROUP_PUBLIC_ID = 2 SITH_GROUP_PUBLIC_ID = 2
SITH_GROUP_SUBSCRIBERS_ID = 3 SITH_GROUP_SUBSCRIBERS_ID = 3