Contract Drafts modules
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from typing import List, Literal
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from beanie import Document
|
||||
|
||||
from ..entity.models import Entity
|
||||
|
||||
|
||||
class ContractType(str, Enum):
|
||||
employment = 'employment'
|
||||
location = 'location'
|
||||
from ..core.models import CrudDocument, RichtextSingleline, RichtextMultiline, DictionaryEntry
|
||||
|
||||
|
||||
class ContractStatus(str, Enum):
|
||||
@@ -20,21 +13,54 @@ class ContractStatus(str, Enum):
|
||||
executed = 'executed'
|
||||
|
||||
|
||||
class ContractDraftStatus(str, Enum):
|
||||
draft = 'draft'
|
||||
created = 'created'
|
||||
|
||||
|
||||
class Party(BaseModel):
|
||||
entity: Entity
|
||||
entity_id: str = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "entity",
|
||||
"schema": "Entity",
|
||||
}
|
||||
}
|
||||
)
|
||||
part: str
|
||||
|
||||
|
||||
class Clause(BaseModel):
|
||||
class ProvisionGenuine(BaseModel):
|
||||
type: Literal['genuine'] = 'genuine'
|
||||
title: str = RichtextSingleline(props={"parametrized": True})
|
||||
body: str = RichtextMultiline(props={"parametrized": True})
|
||||
|
||||
|
||||
class ContractProvisionTemplateReference(BaseModel):
|
||||
type: Literal['template'] = 'template'
|
||||
provision_template_id: str = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "template/provision",
|
||||
"schema": "ProvisionTemplate",
|
||||
"displayedFields": ['title', 'body']
|
||||
},
|
||||
},
|
||||
props={"parametrized": True}
|
||||
)
|
||||
|
||||
|
||||
class DraftProvision(BaseModel):
|
||||
provision: ContractProvisionTemplateReference | ProvisionGenuine = Field(..., discriminator='type')
|
||||
|
||||
|
||||
class ContractDraft(CrudDocument):
|
||||
name: str
|
||||
body: str
|
||||
|
||||
|
||||
class Contract(Document):
|
||||
_id: str
|
||||
type: ContractType
|
||||
title: str
|
||||
parties: List[Party]
|
||||
clauses: List[Clause]
|
||||
status: ContractStatus = Field(default=ContractStatus.new)
|
||||
created_at: datetime = Field(default=datetime.utcnow(), nullable=False)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
|
||||
provisions: List[DraftProvision]
|
||||
variables: List[DictionaryEntry] = Field(
|
||||
default=[],
|
||||
format="dictionary",
|
||||
)
|
||||
status: ContractDraftStatus = Field(default=ContractDraftStatus.draft)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from ..core.routes import get_crud_router
|
||||
from .models import Contract
|
||||
from .schemas import ContractCreate, ContractRead, ContractUpdate
|
||||
from .models import ContractDraft
|
||||
from .schemas import ContractDraftCreate, ContractDraftRead, ContractDraftUpdate
|
||||
|
||||
router = get_crud_router(Contract, ContractCreate, ContractRead, ContractUpdate)
|
||||
router = get_crud_router(ContractDraft, ContractDraftCreate, ContractDraftRead, ContractDraftUpdate)
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, validator
|
||||
from pydantic import Field
|
||||
|
||||
from beanie import PydanticObjectId
|
||||
from .models import ContractDraft, DraftProvision, Party
|
||||
|
||||
from .models import Contract, ContractType, Clause
|
||||
from ..entity.models import Entity
|
||||
from ..core.schemas import Writer
|
||||
from ..core.models import DictionaryEntry
|
||||
|
||||
|
||||
class ContractRead(Contract):
|
||||
class ContractDraftRead(ContractDraft):
|
||||
pass
|
||||
|
||||
|
||||
class PartyCreate(BaseModel):
|
||||
entity: PydanticObjectId
|
||||
part: str
|
||||
|
||||
|
||||
class ContractCreate(Writer):
|
||||
type: ContractType
|
||||
parties: List[PartyCreate]
|
||||
clauses: List[Clause]
|
||||
class ContractDraftCreate(Writer):
|
||||
name: str
|
||||
title: str
|
||||
parties: List[Party]
|
||||
provisions: List[DraftProvision]
|
||||
variables: List[DictionaryEntry] = Field(
|
||||
default=[],
|
||||
format="dictionary",
|
||||
)
|
||||
|
||||
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 ContractUpdate(BaseModel):
|
||||
status: str
|
||||
class ContractDraftUpdate(ContractDraftCreate):
|
||||
pass
|
||||
|
||||
@@ -6,7 +6,7 @@ from .user import User, AccessToken
|
||||
from .entity.models import Entity
|
||||
from .template.models import ContractTemplate, ProvisionTemplate
|
||||
from .order.models import Order
|
||||
from .contract.models import Contract
|
||||
from .contract.models import ContractDraft
|
||||
|
||||
DATABASE_URL = "mongodb://root:example@mongo:27017/"
|
||||
|
||||
@@ -17,5 +17,5 @@ async def init_db():
|
||||
)
|
||||
|
||||
await init_beanie(database=client.db_name,
|
||||
document_models=[User, AccessToken, Entity, ContractTemplate, ProvisionTemplate, Order, Contract, ],
|
||||
document_models=[User, AccessToken, Entity, ContractTemplate, ProvisionTemplate, ContractDraft, ],
|
||||
allow_index_dropping=True)
|
||||
|
||||
@@ -25,7 +25,7 @@ app.include_router(user_router, prefix="/users", tags=["users"], )
|
||||
app.include_router(entity_router, prefix="/entity", tags=["entity"], )
|
||||
app.include_router(order_router, prefix="/order", tags=["order"], )
|
||||
app.include_router(template_router, prefix="/template", tags=["template"], )
|
||||
app.include_router(contract_router, prefix="/contract", tags=["contract"], )
|
||||
app.include_router(contract_router, prefix="/contract-draft", tags=["contract-draft"], )
|
||||
|
||||
if __name__ == '__main__':
|
||||
import uvicorn
|
||||
|
||||
Reference in New Issue
Block a user