2015-06-02 12:59:49 +00:00
|
|
|
from django.contrib import messages
|
2023-10-24 16:59:02 +00:00
|
|
|
from django.utils.translation import ngettext, gettext_lazy as _
|
2015-06-02 12:59:49 +00:00
|
|
|
|
|
|
|
from .models import Transaction
|
|
|
|
|
|
|
|
|
|
|
|
def pre_delete_processes(modeladmin, request, queryset):
|
|
|
|
if not queryset:
|
|
|
|
messages.warning(request,
|
|
|
|
_("No transaction process selected."))
|
|
|
|
return
|
|
|
|
if queryset.exclude(transactions__state=Transaction.WAITTING_EXECUTION).exists():
|
|
|
|
messages.error(request,
|
|
|
|
_("Done nothing. Not all related transactions in waitting execution."))
|
|
|
|
return
|
|
|
|
# Store before deleting
|
|
|
|
related_transactions = []
|
|
|
|
for process in queryset:
|
|
|
|
waitting_execution = process.transactions.filter(state=Transaction.WAITTING_EXECUTION)
|
|
|
|
related_transactions.extend(waitting_execution)
|
|
|
|
return related_transactions
|
|
|
|
|
|
|
|
|
|
|
|
def post_delete_processes(modeladmin, request, related_transactions):
|
|
|
|
# Confirmation
|
|
|
|
num = 0
|
|
|
|
for transaction in related_transactions:
|
|
|
|
transaction.state = Transaction.WAITTING_PROCESSING
|
2016-04-07 11:14:44 +00:00
|
|
|
transaction.save(update_fields=('state', 'modified_at'))
|
2015-06-02 12:59:49 +00:00
|
|
|
num += 1
|
|
|
|
modeladmin.log_change(request, transaction, _("Unprocessed"))
|
2023-10-24 16:59:02 +00:00
|
|
|
messages.success(request, ngettext(
|
2015-06-02 12:59:49 +00:00
|
|
|
"One related transaction has been marked as <i>waitting for processing</i>",
|
|
|
|
"%i related transactions have been marked as <i>waitting for processing</i>." % num,
|
|
|
|
num
|
|
|
|
))
|