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()