mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-01 11:58:04 +00:00
fix: invoices month grouping
This commit is contained in:
parent
564d95f701
commit
e4845b580b
@ -21,9 +21,11 @@
|
|||||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
import itertools
|
||||||
|
|
||||||
# This file contains all the views that concern the user model
|
# This file contains all the views that concern the user model
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
from operator import itemgetter
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -665,9 +667,15 @@ class UserAccountView(UserAccountBase):
|
|||||||
kwargs["refilling_month"] = self.expense_by_month(
|
kwargs["refilling_month"] = self.expense_by_month(
|
||||||
Refilling.objects.filter(customer=self.object.customer)
|
Refilling.objects.filter(customer=self.object.customer)
|
||||||
)
|
)
|
||||||
kwargs["invoices_month"] = self.expense_by_month(
|
kwargs["invoices_month"] = [
|
||||||
Invoice.objects.filter(user=self.object)
|
# the django ORM removes the `group by` clause in this query,
|
||||||
|
# so a little of post-processing is needed
|
||||||
|
{"grouped_date": key, "total": sum(i["total"] for i in group)}
|
||||||
|
for key, group in itertools.groupby(
|
||||||
|
self.expense_by_month(Invoice.objects.filter(user=self.object)),
|
||||||
|
key=itemgetter("grouped_date"),
|
||||||
)
|
)
|
||||||
|
]
|
||||||
kwargs["etickets"] = self.object.customer.buyings.exclude(product__eticket=None)
|
kwargs["etickets"] = self.object.customer.buyings.exclude(product__eticket=None)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user