mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Merge branch 'fix_cleanaccounts' into 'dev'
Fix suppression machines + factures See merge request federez/re2o!333
This commit is contained in:
commit
fd12561761
3 changed files with 29 additions and 4 deletions
22
machines/migrations/0096_auto_20181013_1417.py
Normal file
22
machines/migrations/0096_auto_20181013_1417.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -55,7 +55,7 @@ from re2o.mixins import AclMixin, RevMixin
|
||||||
class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
""" Class définissant une machine, object parent user, objets fils
|
""" Class définissant une machine, object parent user, objets fils
|
||||||
interfaces"""
|
interfaces"""
|
||||||
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
|
user = models.ForeignKey('users.User', on_delete=models.CASCADE)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
help_text=_("Optional"),
|
help_text=_("Optional"),
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
from cotisations.models import Facture
|
||||||
from preferences.models import OptionalUser
|
from preferences.models import OptionalUser
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
@ -28,7 +29,9 @@ class Command(BaseCommand):
|
||||||
help = "Delete non members users (not yet active)"
|
help = "Delete non members users (not yet active)"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
"""First deleting invalid invoices, and then deleting the users"""
|
||||||
days = OptionalUser.get_cached_value('delete_notyetactive')
|
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))
|
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.count()) + " users")
|
print("Deleting " + str(users_to_delete.count()) + " users")
|
||||||
users.delete()
|
Facture.objects.filter(user__in=users_to_delete).delete()
|
||||||
|
users_to_delete.delete()
|
||||||
|
|
Loading…
Reference in a new issue