Handling mongo indexes in firm

This commit is contained in:
ewandor committed 2025-05-04 02:26:06 +02:00
1 parent b542fd40a6
commit ea5093f2c2
9 files changed
+67 -56

No files matched your search

+10 -19
View File
@@ -1,8 +1,8 @@
from datetime import date, datetime
from datetime import date
from typing import List, Literal, Optional
from pydantic import Field, BaseModel, ConfigDict
from beanie import Indexed, PydanticObjectId
from beanie import PydanticObjectId
from firm.core.models import CrudDocument, ForeignKey
from firm.core.filter import Filter, FilterSchema
@@ -18,10 +18,10 @@ class Individual(EntityType):
model_config = ConfigDict(title='Particulier')
type: Literal['individual'] = 'individual'
firstname: Indexed(str) = Field(title='Prénom')
middlename: Indexed(str) = Field(default="", title='Autres prénoms')
lastname: Indexed(str) = Field(title='Nom de famille')
surnames: List[Indexed(str)] = Field(
firstname: str = Field(title='Prénom')
middlename: str = Field(default="", title='Autres prénoms')
lastname: str = Field(title='Nom de famille')
surnames: List[str] = Field(
default=[],
props={"items_per_row": "4", "numbered": True},
title="Surnoms"
@@ -32,14 +32,14 @@ class Individual(EntityType):
@property
def label(self) -> str:
# if len(self.surnames) > 0:
# return '{} "{}" {}'.format(self.firstname, self.surnames[0], self.lastname)
# return f"{self.firstname} \"{self.surnames[0]}\" {self.lastname}"
return f"{self.firstname} {self.lastname}"
class Employee(BaseModel):
model_config = ConfigDict(title='Fiche Employé')
position: Indexed(str) = Field(title='Poste')
position: str = Field(title='Poste')
entity_id: PydanticObjectId = ForeignKey("entities", "Entity", title='Employé')
@@ -47,8 +47,8 @@ class Corporation(EntityType):
model_config = ConfigDict(title='Entreprise')
type: Literal['corporation'] = 'corporation'
title: Indexed(str) = Field(title='Dénomination sociale')
activity: Indexed(str) = Field(title='Activité')
title: str = Field(title='Dénomination sociale')
activity: str = Field(title='Activité')
employees: List[Employee] = Field(default=[], title='Employés')
@@ -72,15 +72,6 @@ class Entity(CrudDocument):
return ""
return self.entity_data.label
class Settings(CrudDocument.Settings):
fulltext_search = ['label']
bson_encoders = {
date: lambda dt: dt if hasattr(dt, 'hour')
else datetime(year=dt.year, month=dt.month, day=dt.day,
hour=0, minute=0, second=0)
}
class EntityFilters(FilterSchema):
class Constants(Filter.Constants):