from typing import Any from pydantic import Field from firm.core.models import CrudDocument from firm.core.schemas import Writer, Reader from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate class CurrentFirmModel(CrudDocument): instance: str firm: str name: str = Field(nullable=False) # primary_color: str = Field() # secondary_color: str = Field() def __eq__(self, other: Any) -> bool: if isinstance(other, dict): return self.instance == other["instance"] and self.firm == other["firm"] return super().__eq__(other) def compute_label(self) -> str: return self.name @classmethod async def get(cls, db): document = await cls._get_collection(db).find_one({}) if not document: return None document["id"] = document.pop("_id") return cls.model_validate(document) class CurrentFirmSchemaRead(Reader): pass class CurrentFirmSchemaCreate(Writer): corporation: EntityCorporationCreate = Field(title="Informations sur la firme") owner: EntityIndividualCreate = Field(title="Informations sur le dirigeant") class CurrentFirmSchemaUpdate(Writer): pass