Skip to content

Commit

Permalink
Merge pull request #944 from uktrade/LTD-1368-API-fixes
Browse files Browse the repository at this point in the history
LTD-1368: Update Party document validation during application submission
  • Loading branch information
saruniitr authored Mar 11, 2022
2 parents ffa3954 + dbb062f commit d39b4d5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions api/applications/creators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
)
from api.cases.enums import CaseTypeSubTypeEnum
from api.core.helpers import str_to_bool
from api.documents.models import Document
from api.goods.models import GoodDocument
from api.goodstype.models import GoodsType
from api.goodstype.document.models import GoodsTypeDocument
Expand Down Expand Up @@ -70,22 +69,20 @@ def check_party_document(party, is_mandatory):
"""
Checks for existence of and status of document (if it is mandatory) and return any errors
"""

try:
document = PartyDocument.objects.get(party=party)
except Document.DoesNotExist:
document = None
documents_qs = PartyDocument.objects.filter(party=party).values_list("safe", flat=True)
if not documents_qs.exists():
if is_mandatory:
return getattr(strings.Applications.Standard, f"NO_{party.type.upper()}_DOCUMENT_SET")

if document:
if document.safe is None:
return getattr(strings.Applications.Standard, f"{party.type.upper()}_DOCUMENT_PROCESSING")
elif not document.safe:
return getattr(strings.Applications.Standard, f"{party.type.upper()}_DOCUMENT_INFECTED")
else:
return None

if None in documents_qs:
return getattr(strings.Applications.Standard, f"{party.type.upper()}_DOCUMENT_PROCESSING")
elif False in documents_qs:
return getattr(strings.Applications.Standard, f"{party.type.upper()}_DOCUMENT_INFECTED")

return None


def check_parties_documents(parties, is_mandatory=True):
"""Check a given list of parties all have documents if is_mandatory. Also checks all documents are safe"""
Expand Down

0 comments on commit d39b4d5

Please sign in to comment.