1616from marshmallow_enum import EnumField
1717
1818from compliance_api .models import (
19- InspectionReqDetailDocument , InspectionReqSourceDetail , InspectionRequirement , InspectionRequirementTypeEnum )
19+ EnforcementActionOptionEnum , InspectionReqDetailDocument , InspectionReqSourceDetail , InspectionRequirement ,
20+ InspectionRequirementTypeEnum )
2021from compliance_api .models .requirement_source import RequirementSourceEnum
2122
2223from .base_schema import AutoSchemaBase , BaseSchema
@@ -182,7 +183,7 @@ class InspectionRequirementCreateSchema(BaseSchema):
182183 )
183184 compliance_finding_id = fields .Int (
184185 metadata = {"description" : "The unique identifier of the compliance findings." },
185- allow_none = True
186+ allow_none = True ,
186187 )
187188 findings = fields .Str (
188189 metadata = {"description" : "The requirement findings in html format." },
@@ -204,6 +205,16 @@ def validate_agency_id(
204205 "Agency is required if the requirement type is Regulatory Consideration" ,
205206 field_name = "agency_id" ,
206207 )
208+ enforcement_action_ids = data .get ("enforcement_action_ids" )
209+ if (
210+ EnforcementActionOptionEnum .REFERRAL_TO_ANOTHER_AGENCY
211+ in enforcement_action_ids
212+ and not agency_id
213+ ):
214+ raise ValidationError (
215+ "Agency is required if the enforcement actions include REFERRAL_TO_ANOTHER_AGENCY" ,
216+ field_name = "agency_id" ,
217+ )
207218
208219
209220class InspectionRequirementUpdateSchema (InspectionRequirementCreateSchema ):
0 commit comments