From 3fa84176099c758ca3b4dba1a948609b6006fa8a Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Mon, 16 Feb 2026 23:13:40 +0200 Subject: [PATCH 1/3] Count the redirection forms only for current year --- backend/donations/models/ngos.py | 3 ++- backend/donations/views/ngo_account/redirections.py | 5 +++-- backend/editions/calendar.py | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/donations/models/ngos.py b/backend/donations/models/ngos.py index 02e2a5d0..a5149c2b 100644 --- a/backend/donations/models/ngos.py +++ b/backend/donations/models/ngos.py @@ -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, @@ -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(january_first()).count() @property def can_receive_redirections(self): diff --git a/backend/donations/views/ngo_account/redirections.py b/backend/donations/views/ngo_account/redirections.py index bcf4a6d9..55751f4b 100644 --- a/backend/donations/views/ngo_account/redirections.py +++ b/backend/donations/views/ngo_account/redirections.py @@ -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, QuerySet, Subquery, Q from django.db.models.functions import JSONObject from django.http import Http404, HttpRequest, HttpResponseNotAllowed, QueryDict from django.shortcuts import redirect @@ -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 @@ -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( diff --git a/backend/editions/calendar.py b/backend/editions/calendar.py index 4ba55ecb..3859cb2a 100644 --- a/backend/editions/calendar.py +++ b/backend/editions/calendar.py @@ -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) From 41bf07948d3db0bd478b270b8496847c839bf0cb Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Mon, 16 Feb 2026 23:20:06 +0200 Subject: [PATCH 2/3] Fix typo --- backend/donations/models/ngos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/donations/models/ngos.py b/backend/donations/models/ngos.py index a5149c2b..5d871b24 100644 --- a/backend/donations/models/ngos.py +++ b/backend/donations/models/ngos.py @@ -580,7 +580,7 @@ def mandatory_fields_values(self) -> list[Any]: @property def redirections_count(self): - return self.donor_set.filter(january_first()).count() + return self.donor_set.filter(date_created__gte=january_first()).count() @property def can_receive_redirections(self): From 847197eeedf440991e0d7272c52c9415f212d8b5 Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Mon, 16 Feb 2026 23:22:54 +0200 Subject: [PATCH 3/3] Sort imports --- backend/donations/views/ngo_account/redirections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/donations/views/ngo_account/redirections.py b/backend/donations/views/ngo_account/redirections.py index 55751f4b..1f40e153 100644 --- a/backend/donations/views/ngo_account/redirections.py +++ b/backend/donations/views/ngo_account/redirections.py @@ -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, Q +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