64 lines
1.2 KiB
Python
64 lines
1.2 KiB
Python
import datetime
|
|
from typing import List
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from .models import ContractDraft, DraftProvision, Party, Contract
|
|
|
|
from ..entity.models import Entity
|
|
from ..core.schemas import Writer
|
|
from ..core.models import DictionaryEntry
|
|
|
|
|
|
class ContractDraftRead(ContractDraft):
|
|
pass
|
|
|
|
|
|
class ContractDraftCreate(Writer):
|
|
name: str
|
|
title: str
|
|
parties: List[Party]
|
|
provisions: List[DraftProvision]
|
|
variables: List[DictionaryEntry] = Field(
|
|
default=[],
|
|
format="dictionary",
|
|
)
|
|
location: str = ""
|
|
date: datetime.date = datetime.date(1, 1, 1)
|
|
|
|
async def validate_foreign_key(self):
|
|
return
|
|
for p in self.parties:
|
|
p.entity = await Entity.get(p.entity)
|
|
if p.entity is None:
|
|
raise ValueError
|
|
|
|
|
|
class ContractDraftUpdate(ContractDraftCreate):
|
|
pass
|
|
|
|
|
|
class EntityRead(BaseModel):
|
|
label: str
|
|
|
|
|
|
class PartyRead(BaseModel):
|
|
signature_affixed: bool
|
|
signature_uuid: str = Field(format="signature-link")
|
|
part: str
|
|
entity: EntityRead
|
|
|
|
|
|
class ContractRead(Contract):
|
|
parties: List[PartyRead]
|
|
|
|
|
|
class ContractCreate(Writer):
|
|
date: datetime.date
|
|
location: str
|
|
draft_id: str
|
|
|
|
|
|
class ContractUpdate(BaseModel):
|
|
pass
|