Petit refactor

This commit is contained in:
Ludovic Stephan 2019-12-25 12:39:41 +01:00
parent 8d11044610
commit b450cb09e6

View file

@ -1407,16 +1407,13 @@ def history_json(request):
transfers_only = request.POST.get("transfersonly", None)
opes_only = request.POST.get("opesonly", None)
# Construction de la requête (sur les opérations) pour le prefetch
ope_queryset_prefetch = Operation.objects.select_related(
"article", "canceled_by", "addcost_for"
)
ope_prefetch = Prefetch("opes", queryset=ope_queryset_prefetch)
# Construction de la requête (sur les transferts) pour le prefetch
transfer_queryset_prefetch = Transfer.objects.select_related(
"from_acc", "to_acc", "canceled_by"
)
# Le check sur les comptes est dans le prefetch pour les transferts
if accounts:
transfer_queryset_prefetch = transfer_queryset_prefetch.filter(
Q(from_acc__trigramme__in=accounts) | Q(to_acc__trigramme__in=accounts)
@ -1435,6 +1432,12 @@ def history_json(request):
"transfers", queryset=transfer_queryset_prefetch, to_attr="filtered_transfers"
)
# Construction de la requête (sur les opérations) pour le prefetch
ope_queryset_prefetch = Operation.objects.select_related(
"article", "canceled_by", "addcost_for"
)
ope_prefetch = Prefetch("opes", queryset=ope_queryset_prefetch)
# Construction de la requête principale
opegroups = (
OperationGroup.objects.prefetch_related(ope_prefetch)