Better feedback on draft publication
This commit is contained in:
@@ -19,7 +19,7 @@ class ContractStatus(str, Enum):
|
||||
class ContractDraftStatus(str, Enum):
|
||||
in_progress = 'in_progress'
|
||||
ready = 'ready'
|
||||
created = 'created'
|
||||
published = 'published'
|
||||
|
||||
|
||||
class DraftParty(BaseModel):
|
||||
@@ -29,7 +29,8 @@ class DraftParty(BaseModel):
|
||||
"resource": "entity",
|
||||
"schema": "Entity",
|
||||
}
|
||||
}
|
||||
},
|
||||
default=""
|
||||
)
|
||||
part: str
|
||||
representative_id: str = Field(
|
||||
@@ -59,8 +60,8 @@ class Party(BaseModel):
|
||||
|
||||
class ProvisionGenuine(BaseModel):
|
||||
type: Literal['genuine'] = 'genuine'
|
||||
title: str = RichtextSingleline(props={"parametrized": True})
|
||||
body: str = RichtextMultiline(props={"parametrized": True})
|
||||
title: str = RichtextSingleline(props={"parametrized": True}, default="")
|
||||
body: str = RichtextMultiline(props={"parametrized": True}, default="")
|
||||
|
||||
|
||||
class ContractProvisionTemplateReference(BaseModel):
|
||||
@@ -73,7 +74,8 @@ class ContractProvisionTemplateReference(BaseModel):
|
||||
"displayedFields": ['title', 'body']
|
||||
},
|
||||
},
|
||||
props={"parametrized": True}
|
||||
props={"parametrized": True},
|
||||
default=""
|
||||
)
|
||||
|
||||
|
||||
@@ -98,6 +100,7 @@ class ContractDraft(CrudDocument):
|
||||
format="dictionary",
|
||||
)
|
||||
status: ContractDraftStatus = ContractDraftStatus.in_progress
|
||||
todo: List[str] = []
|
||||
|
||||
class Settings(CrudDocument.Settings):
|
||||
bson_encoders = {
|
||||
@@ -106,6 +109,40 @@ class ContractDraft(CrudDocument):
|
||||
hour=0, minute=0, second=0)
|
||||
}
|
||||
|
||||
async def check_is_ready(self):
|
||||
if self.status == ContractDraftStatus.published:
|
||||
return
|
||||
|
||||
self.todo = []
|
||||
if len(self.parties) < 2:
|
||||
self.todo.append('Contract must have at least two parties')
|
||||
if len(self.provisions) < 1:
|
||||
self.todo.append('Contract must have at least one provision')
|
||||
|
||||
for p in self.parties:
|
||||
if not p.entity_id:
|
||||
self.todo.append('All parties must have an associated entity`')
|
||||
|
||||
for p in self.provisions:
|
||||
if p.provision.type == "genuine" and not (p.provision.title and p.provision.body):
|
||||
self.todo.append('Empty genuine provision')
|
||||
elif p.provision.type == "template" and not p.provision.provision_template_id:
|
||||
self.todo.append('Empty template provision')
|
||||
|
||||
for v in self.variables:
|
||||
if not (v.key and v.value):
|
||||
self.todo.append('Empty variable')
|
||||
|
||||
if self.todo:
|
||||
self.status = ContractDraftStatus.in_progress
|
||||
else:
|
||||
self.status = ContractDraftStatus.ready
|
||||
|
||||
await self.update({"$set": {
|
||||
"status": self.status,
|
||||
"todo": self.todo
|
||||
}})
|
||||
|
||||
|
||||
class Contract(CrudDocument):
|
||||
name: str
|
||||
|
||||
Reference in New Issue
Block a user