feat: enforce conditional payment validation in schema
This commit is contained in:
parent
8f1e12bac9
commit
bb61418c79
15
schema.py
15
schema.py
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, model_validator
|
||||||
|
|
||||||
|
|
||||||
class DocumentInput(BaseModel):
|
class DocumentInput(BaseModel):
|
||||||
|
|
@ -13,4 +13,15 @@ class DocumentInput(BaseModel):
|
||||||
fixed_fee_gbp: Optional[float] = Field(None, gt=0)
|
fixed_fee_gbp: Optional[float] = Field(None, gt=0)
|
||||||
|
|
||||||
include_confidentiality: bool = False
|
include_confidentiality: bool = False
|
||||||
governing_law: str
|
governing_law: str
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
def check_payment_fields(self):
|
||||||
|
# enforce conditional reqs cleanly
|
||||||
|
if self.payment_type == "hourly" and self.hourly_rate_gbp is None:
|
||||||
|
raise ValueError("hourly_rate_gbp is required when payment_type is 'hourly'")
|
||||||
|
|
||||||
|
if self.payment_type == "fixed" and self.fixed_fee_gbp is None:
|
||||||
|
raise ValueError("fixed_fee_gbp is required when payment_type is 'fixed'")
|
||||||
|
|
||||||
|
return self
|
||||||
Loading…
Reference in a new issue