mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Fix suppression machines + factures
This commit is contained in:
parent
d93dccb9f8
commit
355e5d5a5e
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 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"),
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue