Skip to content

Commit

Permalink
fix: second instalments would not appear in listing when archived
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast committed Dec 19, 2024
1 parent 667017a commit b9ca1bc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
generate_application_summary_file,
get_context_for_summary_context,
)
from calculator.enums import InstalmentStatus
from common.permissions import BFIsApplicant, BFIsHandler, TermsOfServiceAccepted
from messages.automatic_messages import send_application_reopened_message
from messages.models import MessageType
Expand Down Expand Up @@ -300,6 +301,18 @@ def post_attachment(self, request, *args, **kwargs):

return Response(serializer.data, status=status.HTTP_201_CREATED)

def _get_application_pks_with_instalments(self) -> List[int]:
return Application.objects.filter(
status=ApplicationStatus.ACCEPTED,
calculation__instalments__due_date__gte=timezone.now().date(),
calculation__instalments__instalment_number=2,
calculation__instalments__status__in=[
InstalmentStatus.ACCEPTED,
InstalmentStatus.ERROR_IN_TALPA,
InstalmentStatus.WAITING,
],
)

def _get_simplified_queryset(self, request, context) -> QuerySet:
qs = self.filter_queryset(self.get_queryset())
fields = set(context.get("fields", []))
Expand All @@ -324,7 +337,14 @@ def _get_simplified_queryset(self, request, context) -> QuerySet:
user = self.request.user
if hasattr(user, "is_handler") and user.is_handler():
should_filter_archived = request.query_params.get("filter_archived") == "1"
qs = qs.filter(archived=should_filter_archived)
if should_filter_archived:
qs = qs.filter(archived=should_filter_archived)
else:
# Applications with second instalment are considered archived but should be included in main views
qs = qs.filter(
Q(archived=should_filter_archived)
| Q(pk__in=self._get_application_pks_with_instalments())
)

ahjo_cases = request.query_params.get("ahjo_case") == "1"
if ahjo_cases:
Expand Down

0 comments on commit b9ca1bc

Please sign in to comment.