8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Delete disabled users who never created an invoice

This commit is contained in:
Jean-Romain Garnier 2020-04-17 13:43:04 +02:00 committed by Gabriel Detraz
parent e574284936
commit 02040bfae9

View file

@ -17,6 +17,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db.models import Q
from users.models import User from users.models import User
from cotisations.models import Facture from cotisations.models import Facture
@ -27,13 +28,13 @@ from django.utils import timezone
class Command(BaseCommand): 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): def handle(self, *args, **options):
"""First deleting invalid invoices, and then deleting the users""" """First deleting invalid invoices, and then deleting the users"""
days = OptionalUser.get_cached_value("delete_notyetactive") days = OptionalUser.get_cached_value("delete_notyetactive")
users_to_delete = ( 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)) .filter(registered__lte=timezone.now() - timedelta(days=days))
.exclude(facture__valid=True) .exclude(facture__valid=True)
.distinct() .distinct()