Projet

Général

Profil

« Précédent | Suivant » 

Révision afd1e6d5

Ajouté par Serghei Mihai (congés, retour 15/05) il y a plus de 7 ans

command to cancel all created events after 10 minutes (#12850)

Voir les différences:

facturier/management/commands/cleanup_transactionevents.py
1
from django.core.management.base import BaseCommand
2
from django.utils import timezone
3

  
4
from facturier.models import TransactionEvent
5

  
6

  
7
class Command(BaseCommand):
8

  
9
    def handle(self, *args, **options):
10
        delta = timezone.now() - timezone.timedelta(minutes=10)
11
        for event in TransactionEvent.objects.filter(status='CREATED', date__lte=delta):
12
            if not TransactionEvent.objects.filter(invoice_id=event.invoice_id,
13
                                               status__in=['CANCELED', 'ERROR', 'PAID', 'DENIED']).exists():
14
                TransactionEvent.objects.create(transaction_id=event.transaction_id,
15
                                                status='CANCELED',
16
                                                invoice_id=event.invoice_id, regie=event.regie,
17
                                                details='%s canceled because expired' % event.transaction_id)

Formats disponibles : Unified diff