Compare commits
3 Commits
d28092874f
...
90a46ada2d
| Author | SHA1 | Date | |
|---|---|---|---|
| 90a46ada2d | |||
| 4f0d943e04 | |||
| 04ff66f187 |
@@ -27,11 +27,11 @@ class ContractDraftStatus(str, Enum):
|
||||
|
||||
|
||||
class DraftParty(BaseModel):
|
||||
entity_id: PydanticObjectId = ForeignKey("entities", "Entity", default="", title="Partie")
|
||||
entity: SkipJsonSchema[Entity] = Field(default=None, exclude=True, )
|
||||
entity_id: Optional[PydanticObjectId] = ForeignKey("entities", "Entity", default=None, title="Partie")
|
||||
part: str = Field(title="Rôle")
|
||||
representative_id: PydanticObjectId = ForeignKey("entities", "Entity", default="", title="Représentant")
|
||||
representative_id: Optional[PydanticObjectId] = ForeignKey("entities", "Entity", default=None, title="Représentant")
|
||||
|
||||
entity: SkipJsonSchema[Entity] = Field(default=None, exclude=True, )
|
||||
class Config:
|
||||
title = 'Partie'
|
||||
|
||||
@@ -64,7 +64,7 @@ class ContractProvisionTemplateReference(BaseModel):
|
||||
"ProvisionTemplate",
|
||||
displayed_fields=['title', 'body'],
|
||||
props={"parametrized": True},
|
||||
default="",
|
||||
default=None,
|
||||
title="Template de clause"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import List, Literal, Optional
|
||||
from pydantic import Field, BaseModel
|
||||
from beanie import Indexed, PydanticObjectId
|
||||
|
||||
from firm.core.models import CrudDocument
|
||||
from firm.core.models import CrudDocument, ForeignKey
|
||||
from firm.core.filter import Filter, FilterSchema
|
||||
|
||||
|
||||
@@ -39,16 +39,7 @@ class Individual(EntityType):
|
||||
|
||||
class Employee(BaseModel):
|
||||
position: Indexed(str) = Field(title='Poste')
|
||||
entity_id: PydanticObjectId = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "entities",
|
||||
"schema": "Entity",
|
||||
"condition": "entity_data.type=individual"
|
||||
}
|
||||
},
|
||||
title='Employé'
|
||||
)
|
||||
entity_id: PydanticObjectId = ForeignKey("entities", "Entity", title='Employé')
|
||||
|
||||
class Config:
|
||||
title = 'Fiche Employé'
|
||||
|
||||
@@ -1,35 +1,17 @@
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
from html import unescape
|
||||
|
||||
from beanie import PydanticObjectId
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from firm.core.models import CrudDocument, RichtextMultiline, RichtextSingleline, DictionaryEntry
|
||||
from firm.core.models import CrudDocument, RichtextMultiline, RichtextSingleline, DictionaryEntry, ForeignKey
|
||||
from firm.core.filter import Filter, FilterSchema
|
||||
|
||||
|
||||
class PartyTemplate(BaseModel):
|
||||
entity_id: PydanticObjectId = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "entities",
|
||||
"schema": "Entity",
|
||||
}
|
||||
},
|
||||
default="",
|
||||
title="Partie"
|
||||
)
|
||||
entity_id: Optional[PydanticObjectId] = ForeignKey("entities", "Entity", default=None, title="Partie")
|
||||
part: str = Field(title="Rôle")
|
||||
representative_id: PydanticObjectId = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "entities",
|
||||
"schema": "Entity",
|
||||
}
|
||||
},
|
||||
default="",
|
||||
title="Représentant"
|
||||
)
|
||||
representative_id: Optional[PydanticObjectId] = ForeignKey("entities", "Entity", default=None, title="Représentant")
|
||||
|
||||
class Config:
|
||||
title = 'Partie'
|
||||
@@ -62,14 +44,10 @@ class ProvisionTemplate(CrudDocument):
|
||||
|
||||
|
||||
class ProvisionTemplateReference(BaseModel):
|
||||
provision_template_id: PydanticObjectId = Field(
|
||||
foreignKey={
|
||||
"reference": {
|
||||
"resource": "templates/provisions",
|
||||
"schema": "ProvisionTemplate",
|
||||
"displayedFields": ['title', 'body']
|
||||
},
|
||||
},
|
||||
provision_template_id: PydanticObjectId = ForeignKey(
|
||||
"templates/provisions",
|
||||
"TemplateProvision",
|
||||
['title', 'body'],
|
||||
props={"parametrized": True},
|
||||
title="Template de clause"
|
||||
)
|
||||
|
||||
@@ -78,8 +78,8 @@ export default function ArrayFieldTemplate<
|
||||
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>, index) => (
|
||||
<Grid2 key={key} size={gridSize} >
|
||||
<Grid2 container sx={{alignItems: "center"}} >
|
||||
{numbered &&<Grid2 size={1} ><Typography variant="h4">{index + 1}</Typography></Grid2>}
|
||||
<Grid2 size={numbered ? 11 : 12} ><ArrayFieldItemTemplate key={key} {...itemProps} /></Grid2>
|
||||
{numbered &&<Grid2 size={.5} ><Typography variant="h4">{index + 1}</Typography></Grid2>}
|
||||
<Grid2 size={numbered ? 11.5 : 12} ><ArrayFieldItemTemplate key={key} {...itemProps} /></Grid2>
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
))}
|
||||
|
||||
@@ -6,7 +6,7 @@ import ClearIcon from '@mui/icons-material/Clear';
|
||||
import EditIcon from '@mui/icons-material/Edit';
|
||||
import NoteAddIcon from '@mui/icons-material/NoteAdd';
|
||||
import React, { useState, useEffect, useContext, Fragment } from "react";
|
||||
import { useList, useOne } from "@refinedev/core";
|
||||
import { useForm, useList, useOne } from "@refinedev/core";
|
||||
import { ResourceContext } from "../../contexts/ResourceContext";
|
||||
import { CrudForm } from "../crud-form";
|
||||
|
||||
@@ -103,7 +103,7 @@ const RealAutocomplete = <T = any, S extends ForeignKeySchema = ForeignKeySchema
|
||||
aria-describedby="modal-modal-description"
|
||||
>
|
||||
<DialogContent>
|
||||
<FormContainer
|
||||
<FormContainerNew
|
||||
schemaName={schema}
|
||||
resourceBasePath={basePath}
|
||||
resource={resource}
|
||||
@@ -166,7 +166,7 @@ const ChosenValue = <T = any, S extends ForeignKeySchema = ForeignKeySchema, F e
|
||||
aria-describedby="modal-modal-description"
|
||||
>
|
||||
<DialogContent>
|
||||
<FormContainer
|
||||
<FormContainerEdit
|
||||
schemaName={schema}
|
||||
resourceBasePath={basePath}
|
||||
resource={resource}
|
||||
@@ -203,11 +203,49 @@ type FormContainerProps = {
|
||||
onSuccess: (data: any) => void
|
||||
}
|
||||
|
||||
const FormContainer = (props: FormContainerProps) => {
|
||||
const { schemaName, resourceBasePath, resource, uiSchema = {}, id = undefined, onSuccess } = props;
|
||||
const FormContainerEdit = (props: FormContainerProps) => {
|
||||
const { schemaName, resourceBasePath, resource, uiSchema = {}, id, onSuccess } = props;
|
||||
const { onFinish, query, formLoading } = useForm({
|
||||
resource: `${resourceBasePath}/${resource}`,
|
||||
action: "edit",
|
||||
id: id,
|
||||
});
|
||||
|
||||
if (formLoading || query?.data === undefined) {
|
||||
return <CircularProgress />
|
||||
}
|
||||
return (
|
||||
<Box sx={{ ...modalStyle, width: 800 }}>
|
||||
<CrudForm schemaName={schemaName} resourceBasePath={resourceBasePath} resource={resource} uiSchema={uiSchema} id={id} onSuccess={(data) => onSuccess(data)} />
|
||||
<CrudForm
|
||||
schemaName={schemaName}
|
||||
uiSchema={uiSchema}
|
||||
resourceBasePath={resourceBasePath}
|
||||
record={query.data.data}
|
||||
onSubmit={(data:any) => {
|
||||
onFinish(data);
|
||||
onSuccess(data);
|
||||
}} />
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
const FormContainerNew = (props: FormContainerProps) => {
|
||||
const { schemaName, resourceBasePath, resource, uiSchema = {}, onSuccess } = props;
|
||||
const { onFinish } = useForm({
|
||||
resource: `${resourceBasePath}/${resource}`,
|
||||
action: "create"
|
||||
});
|
||||
|
||||
return (
|
||||
<Box sx={{ ...modalStyle, width: 800 }}>
|
||||
<CrudForm
|
||||
schemaName={schemaName}
|
||||
uiSchema={uiSchema}
|
||||
resourceBasePath={resourceBasePath}
|
||||
onSubmit={(data:any) => {
|
||||
onFinish(data);
|
||||
onSuccess(data);
|
||||
}} />
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user