Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/donations/models/ngos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from donations.models.common import CommonFilenameCacheModel
from donations.models.donors import Donor
from editions.calendar import january_first
from utils.models_hashing import hash_id_secret
from utils.text.registration_number import (
REGISTRATION_NUMBER_REGEX_WITH_VAT,
Expand Down Expand Up @@ -579,7 +580,7 @@ def mandatory_fields_values(self) -> list[Any]:

@property
def redirections_count(self):
return self.donor_set.count()
return self.donor_set.filter(date_created__gte=january_first()).count()

@property
def can_receive_redirections(self):
Expand Down
5 changes: 3 additions & 2 deletions backend/donations/views/ngo_account/redirections.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.db.models import Count, F, OuterRef, QuerySet, Subquery
from django.db.models import Count, F, OuterRef, Q, QuerySet, Subquery
from django.db.models.functions import JSONObject
from django.http import Http404, HttpRequest, HttpResponseNotAllowed, QueryDict
from django.shortcuts import redirect
Expand All @@ -26,6 +26,7 @@
get_queryset_filters,
get_redirections_filters,
)
from editions.calendar import january_first
from redirectioneaza.common.app_url import build_uri
from redirectioneaza.common.cache import cache_decorator
from redirectioneaza.common.messaging import extend_email_context, send_email
Expand Down Expand Up @@ -104,7 +105,7 @@ def _get_ngo_causes(self, *, ngo: Ngo) -> QuerySet:

return (
ngo.causes.annotate(
redirections_count=Count("donor"),
redirections_count=Count("donor", filter=Q(date_created__gte=january_first())),
last_archive_job=Subquery(ngo_archive_jobs[:1]),
)
.values(
Expand Down
7 changes: 7 additions & 0 deletions backend/editions/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def get_current_year_range() -> list[int]:
"""
current_year: int = timezone.now().year
return list(range(settings.START_YEAR, current_year + 1))


def january_first():
"""
Returns a timezone aware datetime for January 1st of the current year
"""
return timezone.localtime(timezone.now()).replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)