fix code for accounting confirm

This commit is contained in:
2017-04-27 13:23:18 +02:00
parent cae1ee197e
commit 7ad3a3e22d
4 changed files with 26 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
import ast
from billard.serializers import LocationDataSerializer
from billard.models import LocationData, Location, Client, Accounting
from billard.tasks import process_location_data
@@ -39,7 +41,7 @@ class AccountingView(generic.ListView):
context_object_name = 'accounting'
def get_queryset(self):
return Accounting.objects.filter(billed=False).exclude(time_to__isnull=True)
return Accounting.objects.filter(billed=False).exclude(time_to__isnull=True).order_by('time_from')
def dispatch(self, request, *args, **kwargs):
result = super(AccountingView, self).dispatch(request, *args, **kwargs)
@@ -52,6 +54,19 @@ class AccountingView(generic.ListView):
return result
@login_required
@permission_required('billard.change_accounting')
def accounting_confirm(request, pk):
if request.method == 'POST':
if 'accountings' in request.POST:
acc_ids = ast.literal_eval(request.POST['accountings'])
if len(acc_ids) > 0:
Accounting.objects.filter(id__in=acc_ids).update(billed=True)
Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username)
resp = redirect('billard:accounting_detail', pk=pk)
return resp
# TODO OLD CODE, CLEAN UP
@@ -97,7 +112,7 @@ def accountmodalconfirmview(request, pk):
account = Accounting.objects.get(pk=pk)
account.reporter_uuid = None
account.save()
return redirect('carom_index')
return redirect('billard:location_detail', pk=pk)
@login_required