3030from business_common .utils .datetime import date
3131from business_common .utils .datetime import datetime as dt
3232from business_common .utils .legislation_datetime import LegislationDatetime
33- from business_model .models import Address , Business , Filing , PartyRole
33+ from business_model .models import Address , Business , DocumentType , Filing , PartyRole
3434from legal_api .core .filing import Filing as CoreFiling
3535from legal_api .errors import Error
3636from legal_api .services import STAFF_ROLE , colin , doc_service , flags , namex
@@ -559,14 +559,7 @@ def validate_court_order(
559559 msg .append ({"error" : "Court order date cannot be in the future." , "path" : f"{ court_order_path } /orderDate" })
560560
561561 if is_file_or_details_required :
562- file_key_path = f"{ court_order_path } /fileKey"
563- file_key = court_order .get ("fileKey" )
564-
565- if not court_order .get ("orderDetails" ) and not file_key :
566- msg .append ({"error" : _ ("Court Order is required (in orderDetails/fileKey)." ), "path" : court_order_path })
567-
568- if file_key :
569- msg .extend (validate_pdf (file_key , file_key_path ))
562+ msg .extend (_validate_court_order_documents (court_order_path , court_order ))
570563
571564 if flags .is_on ("enabled-deeper-permission-action" ):
572565 required_permission = ListActionsPermissionsAllowed .COURT_ORDER_POA .value
@@ -578,6 +571,32 @@ def validate_court_order(
578571 return msg
579572
580573
574+ def _validate_court_order_documents (court_order_path , court_order ):
575+ msg = []
576+ file_key = court_order .get ("fileKey" )
577+ files = court_order .get ("files" , [])
578+
579+ if not court_order .get ("orderDetails" ) and not file_key and not files :
580+ msg .append ({"error" : _ ("Court Order is required (in orderDetails/fileKey/files)." ), "path" : court_order_path })
581+
582+ if file_key :
583+ msg .extend (validate_pdf (file_key , f"{ court_order_path } /fileKey" ))
584+ elif files :
585+ court_order_document_count = 0
586+ files_path = f"{ court_order_path } /files"
587+ for file_index , file in enumerate (files ):
588+ if file .get ("documentType" ) == DocumentType .COURT_ORDER .value :
589+ court_order_document_count += 1
590+ msg .extend (validate_pdf (file .get ("fileKey" ), f"{ files_path } /{ file_index } /fileKey" ))
591+
592+ if court_order_document_count == 0 : # if only supporting documents and no court order documents were found
593+ msg .append ({"error" : _ ("At least one Court Order document is required." ), "path" : files_path })
594+ elif court_order_document_count > 1 :
595+ msg .append ({"error" : _ ("Only one Court Order document is allowed." ), "path" : files_path })
596+
597+ return msg
598+
599+
581600def check_good_standing_permission (business : Business ) -> Error | None :
582601 """Check if user has permission to file for a business not in good standing."""
583602 if business .good_standing :
0 commit comments