Skip to content

Commit

Permalink
Remove goodstype and goodcountrydecision refs
Browse files Browse the repository at this point in the history
  • Loading branch information
hnryjmes committed Dec 16, 2024
1 parent 9ca0245 commit f54ca26
Show file tree
Hide file tree
Showing 59 changed files with 171 additions and 2,187 deletions.
38 changes: 0 additions & 38 deletions api/applications/libraries/document_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from api.applications.serializers.good import DocumentOnOrganisationSerializer
from api.audit_trail import service as audit_trail_service
from api.audit_trail.enums import AuditType
from api.goodstype.document.models import GoodsTypeDocument
from api.goodstype.document.serializers import GoodsTypeDocumentSerializer
from api.parties.enums import PartyDocumentType, PartyType
from api.parties.models import PartyDocument
from api.parties.serializers import PartyDocumentSerializer
Expand Down Expand Up @@ -142,39 +140,3 @@ def delete_party_document(party, application, user):
)

return HttpResponse(status=status.HTTP_204_NO_CONTENT)


def get_goods_type_document(goods_type):
if not goods_type:
return JsonResponse(data={"error": "No such goods type"}, status=status.HTTP_400_BAD_REQUEST)

documents = GoodsTypeDocument.objects.filter(goods_type=goods_type)
return _get_document(documents)


def upload_goods_type_document(goods_type, data):
if not goods_type:
return JsonResponse(data={"error": "No such goods type"}, status=status.HTTP_400_BAD_REQUEST)

documents = GoodsTypeDocument.objects.filter(goods_type=goods_type)
if documents.exists():
return JsonResponse(data={"error": "Document already exists"}, status=status.HTTP_400_BAD_REQUEST)

data["goods_type"] = goods_type.id
serializer = GoodsTypeDocumentSerializer(data=data)

if not serializer.is_valid():
return JsonResponse({"errors": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

serializer.save()

return JsonResponse({"document": serializer.data}, status=status.HTTP_201_CREATED)


def delete_goods_type_document(goods_type):
documents = GoodsTypeDocument.objects.filter(goods_type=goods_type)
for document in documents:
document.delete_s3()
document.delete()

return HttpResponse(status=status.HTTP_204_NO_CONTENT)
2 changes: 1 addition & 1 deletion api/applications/libraries/goods_on_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def add_goods_flags_to_submitted_application(application: BaseApplication):
"""
When an application is submitted;
The 'not yet verified' system flag must be added to its Goods or GoodsTypes
The 'not yet verified' system flag must be added to its Goods
A Good's status must also be updated to 'SUBMITTED'
"""
if application.case_type.sub_type == CaseTypeSubTypeEnum.STANDARD:
Expand Down
3 changes: 0 additions & 3 deletions api/applications/serializers/advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from api.flags.enums import FlagStatuses
from api.goods.models import Good
from api.applications.models import GoodOnApplication
from api.goodstype.models import GoodsType
from api.gov_users.serializers import (
GovUserListSerializer,
GovUserSimpleSerializer,
Expand Down Expand Up @@ -59,7 +58,6 @@ class AdviceViewSerializer(serializers.Serializer):
team = TeamReadOnlySerializer()

good = GoodField()
goods_type = serializers.UUIDField(source="goods_type_id")
country = serializers.UUIDField(source="country_id")
end_user = serializers.UUIDField(source="end_user_id")
ultimate_end_user = serializers.UUIDField(source="ultimate_end_user_id")
Expand Down Expand Up @@ -111,7 +109,6 @@ class AdviceCreateSerializer(serializers.ModelSerializer):
)

good = GoodField(required=False)
goods_type = serializers.PrimaryKeyRelatedField(queryset=GoodsType.objects.all(), required=False)
country = serializers.PrimaryKeyRelatedField(queryset=Country.objects.all(), required=False)
end_user = serializers.PrimaryKeyRelatedField(
queryset=Party.objects.filter(type=PartyType.END_USER), required=False
Expand Down
1 change: 0 additions & 1 deletion api/applications/tests/test_copy_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def _validate_third_party(self):
def _validate_case_data(self):
self.assertEqual(list(self.copied_application.case_ecju_query.all()), [])
self.assertEqual(list(self.copied_application.case_notes.all()), [])
self.assertEqual(list(self.copied_application.goodcountrydecision_set.all()), [])
self.assertEqual(list(self.copied_application.get_case().advice.all()), [])
self.assertEqual(list(self.copied_application.applicationdocument_set.all()), [])
self.assertEqual(list(self.copied_application.casedocument_set.all()), [])
Expand Down
24 changes: 0 additions & 24 deletions api/applications/tests/test_endpoints_response_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ def test_application_goods(self):
self.url + self.get_standard_application()["id"] + "/goods/",
)

def test_applications_goodstype_list(self):
self.call_endpoint(
self.get_exporter_headers(),
self.url + self.get_open_application()["id"] + "/goodstypes/",
)

def test_applications_goodstype_detail(self):
application = self.get_open_application()
application_id = application["id"]
goods_type = self.get_application_goodstype_id()
url = f"{self.url}{application_id}/goodstype/{goods_type}"
exporter_user = self.get_exporter_headers()
self.call_endpoint(exporter_user, url)

def test_applications_goodstype_documents(self):
self.call_endpoint(
self.get_exporter_headers(),
self.url
+ self.get_open_application()["id"]
+ "/goodstype/"
+ self.get_application_goodstype_id()
+ "/document/",
)

def test_application_parties_list(self):
self.call_endpoint(
self.get_exporter_headers(),
Expand Down
6 changes: 0 additions & 6 deletions api/applications/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@
goods.ApplicationGoodOnApplicationUpdateSerialNumbers.as_view(),
name="good_on_application_update_serial_numbers",
),
# Goods types
path(
"<uuid:pk>/goodstype/<uuid:goods_type_pk>/document/",
documents.GoodsTypeDocumentView.as_view(),
name="goods_type_document",
),
# Parties
path("<uuid:pk>/parties/", parties.ApplicationPartyView.as_view(), name="parties"),
path("<uuid:pk>/parties/<uuid:party_pk>/", parties.ApplicationPartyView.as_view(), name="party"),
Expand Down
24 changes: 0 additions & 24 deletions api/applications/views/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
from api.flags.enums import FlagStatuses, SystemFlags
from api.goods.serializers import GoodCreateSerializer
from api.goods.models import FirearmGoodDetails
from api.goodstype.models import GoodsType
from api.licences.enums import LicenceStatus
from api.licences.helpers import get_licence_reference_code
from api.licences.models import Licence
Expand Down Expand Up @@ -636,14 +635,10 @@ def post(self, request, pk):

# Create new foreign key connection using data from old application (this is for tables pointing to the case)
self.create_foreign_relations_for_new_application()
self.duplicate_goodstypes_for_new_application()

# Get all parties connected to the application and produce a copy (and replace reference for each one)
self.duplicate_parties_on_new_application()

# Remove usage & licenced quantity/ value
self.new_application.goods_type.update(usage=0)

# Save
self.new_application.created_at = now()
self.new_application.save()
Expand Down Expand Up @@ -741,25 +736,6 @@ def create_foreign_relations_for_new_application(self):
result.created_at = now()
result.save()

def duplicate_goodstypes_for_new_application(self):
"""
Creates a duplicate GoodsType and attaches it to the new application if applicable.
"""
# GoodsType has more logic than in "create_foreign_relations_for_new_application",
# such as listing the countries on the goodstype, and flags as such it is seperated.
for good in GoodsType.objects.filter(application_id=self.old_application_id).all():
old_good_countries = list(good.countries.all())
old_good_flags = list(good.flags.all())
old_good_control_list_entries = list(good.control_list_entries.all())
good.pk = None
good.id = None
good.application = self.new_application
good.created_at = now()
good.save()
good.countries.set(old_good_countries)
good.flags.set(old_good_flags)
good.control_list_entries.set(old_good_control_list_entries)


class ApplicationRouteOfGoods(UpdateAPIView):
authentication_classes = (ExporterAuthentication,)
Expand Down
37 changes: 0 additions & 37 deletions api/applications/views/documents.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from django.db import transaction
from django.http import JsonResponse
from rest_framework import status
from rest_framework.views import APIView

from api.applications.libraries import document_helpers
from api.applications.libraries.get_applications import get_application
from api.applications.models import ApplicationDocument
from api.applications.serializers.document import ApplicationDocumentSerializer
from api.cases.enums import CaseTypeSubTypeEnum
from api.core.authentication import ExporterAuthentication
from api.core.decorators import (
authorised_to_view_application,
allowed_application_types,
application_is_editable,
application_is_major_editable,
)
from api.goodstype.helpers import get_goods_type
from api.users.models import ExporterUser


Expand Down Expand Up @@ -70,35 +65,3 @@ def delete(self, request, pk, doc_pk):
"""
application = get_application(pk)
return document_helpers.delete_application_document(doc_pk, application, request.user)


class GoodsTypeDocumentView(APIView):
"""
Retrieve, add or delete a third party document from an application
"""

authentication_classes = (ExporterAuthentication,)

@allowed_application_types([CaseTypeSubTypeEnum.HMRC])
@authorised_to_view_application(ExporterUser)
def get(self, request, pk, goods_type_pk):
goods_type = get_goods_type(goods_type_pk)
return document_helpers.get_goods_type_document(goods_type)

@transaction.atomic
@allowed_application_types([CaseTypeSubTypeEnum.HMRC])
@application_is_major_editable
@authorised_to_view_application(ExporterUser)
def post(self, request, pk, goods_type_pk):
goods_type = get_goods_type(goods_type_pk)
return document_helpers.upload_goods_type_document(goods_type, request.data)

@transaction.atomic
@allowed_application_types([CaseTypeSubTypeEnum.HMRC])
@authorised_to_view_application(ExporterUser)
def delete(self, request, pk, goods_type_pk):
goods_type = get_goods_type(goods_type_pk)
if not goods_type:
return JsonResponse(data={"error": "No such goods type"}, status=status.HTTP_400_BAD_REQUEST)

return document_helpers.delete_goods_type_document(goods_type)
5 changes: 0 additions & 5 deletions api/cases/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class EcjuQueryAdmin(admin.ModelAdmin):
list_display = ("id",)


@admin.register(models.GoodCountryDecision)
class GoodCountryDecisionAdmin(admin.ModelAdmin):
list_display = ("id",)


@admin.register(models.EnforcementCheckID)
class EnforcementCheckIDAdmin(admin.ModelAdmin):
list_display = (
Expand Down
Loading

0 comments on commit f54ca26

Please sign in to comment.