mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
Fix immutable default variable in get_start_of_semester
(#656)
Le serveur ne percevait pas le changement de semestre, parce que la valeur par défaut passée à la fonction `get_start_of_semester()` était une fonction appelée une seule fois, lors du lancement du serveur. Bref, c'était ça : https://beta.ruff.rs/docs/rules/function-call-in-default-argument/ --------- Co-authored-by: imperosol <thgirod@hotmail.com>
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
#
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Tuple
|
||||
from typing import Tuple, Optional
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import F, Value, Sum, QuerySet, OuterRef, Exists
|
||||
@ -536,7 +536,7 @@ class Counter(models.Model):
|
||||
.order_by("-perm_sum")
|
||||
)
|
||||
|
||||
def get_top_customers(self, since=get_start_of_semester()) -> QuerySet:
|
||||
def get_top_customers(self, since: Optional[date] = None) -> QuerySet:
|
||||
"""
|
||||
Return a QuerySet querying the money spent by customers of this counter
|
||||
since the specified date, ordered by descending amount of money spent.
|
||||
@ -546,6 +546,8 @@ class Counter(models.Model):
|
||||
- the nickname of the customer
|
||||
- the amount of money spent by the customer
|
||||
"""
|
||||
if since is None:
|
||||
since = get_start_of_semester()
|
||||
return (
|
||||
self.sellings.filter(date__gte=since)
|
||||
.annotate(
|
||||
@ -557,7 +559,8 @@ class Counter(models.Model):
|
||||
)
|
||||
.annotate(nickname=F("customer__user__nick_name"))
|
||||
.annotate(promo=F("customer__user__promo"))
|
||||
.values("customer__user", "name", "nickname")
|
||||
.annotate(user=F("customer__user"))
|
||||
.values("user", "promo", "name", "nickname")
|
||||
.annotate(
|
||||
selling_sum=Sum(
|
||||
F("unit_price") * F("quantity"), output_field=CurrencyField()
|
||||
@ -567,15 +570,17 @@ class Counter(models.Model):
|
||||
.order_by("-selling_sum")
|
||||
)
|
||||
|
||||
def get_total_sales(self, since=get_start_of_semester()) -> CurrencyField:
|
||||
def get_total_sales(self, since=None) -> CurrencyField:
|
||||
"""
|
||||
Compute and return the total turnover of this counter
|
||||
since the date specified in parameter (by default, since the start of the current
|
||||
semester)
|
||||
:param since: timestamp from which to perform the calculation
|
||||
:type since: datetime | date
|
||||
:type since: datetime | date | None
|
||||
:return: Total revenue earned at this counter
|
||||
"""
|
||||
if since is None:
|
||||
since = get_start_of_semester()
|
||||
if isinstance(since, date):
|
||||
since = datetime.combine(since, datetime.min.time())
|
||||
total = self.sellings.filter(date__gte=since).aggregate(
|
||||
|
Reference in New Issue
Block a user