From 02040bfae925d81ab21016be08167ae54ed4c2e0 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 13:43:04 +0200 Subject: [PATCH] Delete disabled users who never created an invoice --- users/management/commands/clean_notyetactive.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/users/management/commands/clean_notyetactive.py b/users/management/commands/clean_notyetactive.py index 994abfc2..d6c9a701 100644 --- a/users/management/commands/clean_notyetactive.py +++ b/users/management/commands/clean_notyetactive.py @@ -17,6 +17,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # from django.core.management.base import BaseCommand, CommandError +from django.db.models import Q from users.models import User from cotisations.models import Facture @@ -27,13 +28,13 @@ from django.utils import timezone class Command(BaseCommand): - help = "Delete non members users (not yet active)." + help = "Delete non members users (not yet active or disabled too long ago without an invoice)." def handle(self, *args, **options): """First deleting invalid invoices, and then deleting the users""" days = OptionalUser.get_cached_value("delete_notyetactive") users_to_delete = ( - User.objects.filter(state=User.STATE_NOT_YET_ACTIVE) + User.objects.filter(Q(state=User.STATE_NOT_YET_ACTIVE) | Q(state=User.STATE_DISABLED)) .filter(registered__lte=timezone.now() - timedelta(days=days)) .exclude(facture__valid=True) .distinct()