From 25099528bf13a79926cc285899d43de05503ba31 Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 24 Aug 2025 00:26:34 +0200 Subject: [PATCH] Improve eboutic readability --- eboutic/views.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/eboutic/views.py b/eboutic/views.py index f4762534..b52e8d83 100644 --- a/eboutic/views.py +++ b/eboutic/views.py @@ -133,28 +133,30 @@ class EbouticMainView(LoginRequiredMixin, FormView): context["products"] = self.products context["customer_amount"] = self.request.user.account_balance + purchases = ( + Customer.objects.filter(pk=self.customer.pk) + .annotate( + last_refill=Subquery( + Refilling.objects.filter( + counter__type="EBOUTIC", customer_id=self.customer.pk + ) + .order_by("-date") + .values("date")[:1] + ), + last_purchase=Subquery( + Selling.objects.filter( + counter__type="EBOUTIC", customer_id=self.customer.pk + ) + .order_by("-date") + .values("date")[:1] + ), + ) + .values_list("last_refill", "last_purchase") + )[0] + purchase_times = [ int(purchase.timestamp() * 1000) - for purchase in ( - Customer.objects.filter(pk=self.customer.pk) - .annotate( - last_refill=Subquery( - Refilling.objects.filter( - counter__type="EBOUTIC", customer_id=self.customer.pk - ) - .order_by("-date") - .values("date")[:1] - ), - last_purchase=Subquery( - Selling.objects.filter( - counter__type="EBOUTIC", customer_id=self.customer.pk - ) - .order_by("-date") - .values("date")[:1] - ), - ) - .values("last_refill", "last_purchase") - )[0].values() + for purchase in purchases if purchase is not None ]