Skip to content

Commit

Permalink
Merge pull request #946 from uktrade/LTD-1279-Destinations
Browse files Browse the repository at this point in the history
LTD-1279-Adds-Destinations-to-payload
  • Loading branch information
seijihg authored Mar 21, 2022
2 parents e190a8a + 367821f commit 7353ca7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion api/cases/views/search/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db.models.functions import Concat
from django.utils import timezone

from api.applications.models import HmrcQuery
from api.applications.models import HmrcQuery, PartyOnApplication
from api.audit_trail.models import Audit
from api.cases.enums import CaseTypeEnum, CaseTypeSubTypeEnum, AdviceType
from api.cases.models import Case
Expand All @@ -18,6 +18,8 @@
from api.staticdata.statuses.enums import CaseStatusEnum
from api.users.enums import UserStatuses
from api.users.models import GovUser
from api.cases.enums import CaseTypeTypeEnum
from api.parties.serializers import PartySerializer


def get_case_status_list() -> List[Dict]:
Expand Down Expand Up @@ -189,3 +191,19 @@ def get_hmrc_sla_hours(cases: List[Dict]):
for case in cases:
if case["id"] in hmrc_cases_goods_not_left_country:
case["sla_hours_since_raised"] = working_hours_in_range(case["submitted_at"], timezone.now())


def populate_destinations(cases: List[Dict]):
for case in cases:
id = case["id"]
destinations = []

if case["case_type"]["type"]["key"] == CaseTypeTypeEnum.APPLICATION:
for poa in PartyOnApplication.objects.filter(application=id, deleted_at=None):
serializer = PartySerializer(poa.party)
data = serializer.data
destinations.append(data)

case["destinations"] = destinations

return cases
3 changes: 3 additions & 0 deletions api/cases/views/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CasesSearchView(generics.ListAPIView):
authentication_classes = (GovAuthentication,)

def get(self, request, *args, **kwargs):

user = request.user.govuser
queue_id = request.GET.get("queue_id", ALL_CASES_QUEUE_ID)
is_work_queue = queue_id not in NON_WORK_QUEUES.keys()
Expand Down Expand Up @@ -94,6 +95,8 @@ def get(self, request, *args, **kwargs):
case_types = service.get_case_type_type_list()
gov_users = service.get_gov_users_list()
advice_types = service.get_advice_types_list()
# Add destinations.
service.populate_destinations(cases)

return self.get_paginated_response(
{
Expand Down

0 comments on commit 7353ca7

Please sign in to comment.