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

Merge branch 'fix_cleanaccounts' into 'dev'

Fix suppression machines + factures

See merge request federez/re2o!333
This commit is contained in:
klafyvel 2018-10-14 16:45:31 +02:00
commit fd12561761
3 changed files with 29 additions and 4 deletions

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-10-13 12:17
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('machines', '0095_auto_20180919_2225'),
]
operations = [
migrations.AlterField(
model_name='machine',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View file

@ -55,7 +55,7 @@ from re2o.mixins import AclMixin, RevMixin
class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
""" Class définissant une machine, object parent user, objets fils
interfaces"""
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
user = models.ForeignKey('users.User', on_delete=models.CASCADE)
name = models.CharField(
max_length=255,
help_text=_("Optional"),

View file

@ -19,6 +19,7 @@
from django.core.management.base import BaseCommand, CommandError
from users.models import User
from cotisations.models import Facture
from preferences.models import OptionalUser
from datetime import timedelta
@ -28,7 +29,9 @@ class Command(BaseCommand):
help = "Delete non members users (not yet active)"
def handle(self, *args, **options):
"""First deleting invalid invoices, and then deleting the users"""
days = OptionalUser.get_cached_value('delete_notyetactive')
users = User.objects.filter(state=User.STATE_NOT_YET_ACTIVE).filter(registered__lte=timezone.now() - timedelta(days=days))
print("Deleting " + str(users.count()) + " users")
users.delete()
users_to_delete = User.objects.filter(state=User.STATE_NOT_YET_ACTIVE).filter(registered__lte=timezone.now() - timedelta(days=days)).exclude(facture__valid=True).distinct()
print("Deleting " + str(users_to_delete.count()) + " users")
Facture.objects.filter(user__in=users_to_delete).delete()
users_to_delete.delete()