Merge branch 'aureplop/1_11/fix_querysets' into 'supportBDS'

Aureplop/1 11/fix querysets

See merge request !183
This commit is contained in:
Martin Pepin 2017-03-19 16:16:05 +01:00
commit 33dedc7474

View file

@ -841,34 +841,40 @@ def account_read_json(request):
'trigramme': account.trigramme }
return JsonResponse(data)
@teamkfet_required
def kpsul_checkout_data(request):
pk = request.POST.get('pk', 0)
if not pk:
pk = 0
data = (Checkout.objects
.annotate(
last_statement_by_first_name=F('statements__by__profile__user__first_name'),
last_statement_by_last_name=F('statements__by__profile__user__last_name'),
last_statement_by_trigramme=F('statements__by__trigramme'),
last_statement_balance=F('statements__balance_new'),
last_statement_at=F('statements__at'))
.values(
'id', 'name', 'balance', 'valid_from', 'valid_to',
'last_statement_balance', 'last_statement_at',
'last_statement_by_trigramme', 'last_statement_by_last_name',
'last_statement_by_first_name')
.select_related(
'statements'
'statements__by',
'statements__by__profile__user')
.filter(pk=pk)
.order_by('statements__at')
.last())
if data is None:
raise Http404
checkout = get_object_or_404(Checkout, pk=pk)
data = {
'id': checkout.id, 'name': checkout.name, 'balance': checkout.balance,
'valid_from': checkout.valid_from, 'valid_to': checkout.valid_to
}
try:
last_statement = (
CheckoutStatement
.objects
.select_related('by', 'by__profile', 'by__profile__user')
.filter(checkout=checkout)
.latest('at')
)
data['last_statement_balance'] = last_statement.balance_new
data['last_statement_at'] = last_statement.at
data['last_statement_by_trigramme'] = last_statement.by.trigramme
data['last_statement_by_last_name'] = \
last_statement.by.profile.user.last_name
data['last_statement_by_first_name'] = \
last_statement.by.profile.user.first_name
except CheckoutStatement.DoesNotExist:
pass
return JsonResponse(data)
@teamkfet_required
def kpsul_update_addcost(request):
addcost_form = AddcostForm(request.POST)
@ -1273,19 +1279,19 @@ def history_json(request):
# Récupération des paramètres
from_date = request.POST.get('from', None)
to_date = request.POST.get('to', None)
limit = request.POST.get('limit', None);
limit = request.POST.get('limit', None)
checkouts = request.POST.getlist('checkouts[]', None)
accounts = request.POST.getlist('accounts[]', None)
# Construction de la requête (sur les opérations) pour le prefetch
queryset_prefetch = Operation.objects.select_related(
'canceled_by__trigramme', 'addcost_for__trigramme',
'article__name')
'canceled_by', 'addcost_for',
'article')
# Construction de la requête principale
opegroups = (OperationGroup.objects
.prefetch_related(Prefetch('opes', queryset = queryset_prefetch))
.select_related('on_acc__trigramme', 'valid_by__trigramme')
.select_related('on_acc', 'valid_by')
.order_by('at')
)
# Application des filtres