2014-09-10 16:53:09 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2014-09-08 10:03:42 +00:00
|
|
|
from .methods import PaymentMethod
|
2014-09-10 16:53:09 +00:00
|
|
|
from .models import Transaction
|
|
|
|
|
2014-07-30 12:55:33 +00:00
|
|
|
def process_transactions(modeladmin, request, queryset):
|
2014-09-10 16:53:09 +00:00
|
|
|
processes = []
|
|
|
|
if queryset.exclude(state=Transaction.WAITTING_PROCESSING).exists():
|
|
|
|
msg = _("Selected transactions must be on '{state}' state")
|
|
|
|
messages.error(request, msg.format(state=Transaction.WAITTING_PROCESSING))
|
|
|
|
return
|
2014-09-16 14:35:00 +00:00
|
|
|
for method, transactions in queryset.group_by('source__method').iteritems():
|
2014-09-08 10:03:42 +00:00
|
|
|
if method is not None:
|
2014-09-10 16:53:09 +00:00
|
|
|
method = PaymentMethod.get_plugin(method)
|
|
|
|
procs = method.process(transactions)
|
|
|
|
processes += procs
|
|
|
|
if not processes:
|
|
|
|
return
|
|
|
|
opts = modeladmin.model._meta
|
|
|
|
context = {
|
|
|
|
'title': _("Huston, be advised"),
|
|
|
|
'action_name': _("Process"),
|
|
|
|
'processes': processes,
|
|
|
|
'opts': opts,
|
|
|
|
'app_label': opts.app_label,
|
|
|
|
}
|
|
|
|
return render(request, 'admin/payments/transaction/get_processes.html', context)
|