Why Django Group by id Field? Here is queryset:
MyModel.objects\
.filter(
status=1,
created__gte=datestart,
created__lte=dateend)\
.values('terminal_id')\
.annotate(
total_pa=Sum('amount'),
total_ar=Sum('amount_result')).query
But it order and group by pk field.
... GROUP BY payment
.id
ORDER BY payment
.id
...
Instead of
... GROUP BY payment
.terminal_id
ORDER BY payment
.terminal_id
...
See the "Warning" here:
Perhaps the default ordering is getting in the way. Try adding .order_by()
to the end of your query to see if that clears the ordering.