73 lines
3.1 KiB
Python
73 lines
3.1 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
"""Feature models: Feature, FeatureInstance."""
|
|
|
|
import uuid
|
|
from typing import Optional, Dict, Any
|
|
from pydantic import BaseModel, Field
|
|
from modules.datamodels.datamodelBase import PowerOnModel
|
|
from modules.shared.i18nRegistry import i18nModel
|
|
from modules.datamodels.datamodelUtils import TextMultilingual
|
|
|
|
|
|
@i18nModel("Feature")
|
|
class Feature(PowerOnModel):
|
|
"""Feature-Definition (global, z.B. 'trustee', 'chatbot'). Verfuegbare Funktionalitaeten der Plattform."""
|
|
code: str = Field(
|
|
description="Unique feature code (Primary Key), z.B. 'trustee', 'chatbot'",
|
|
json_schema_extra={"label": "Code", "frontend_type": "text", "frontend_readonly": False, "frontend_required": True}
|
|
)
|
|
label: TextMultilingual = Field(
|
|
description="Feature label in multiple languages (I18n)",
|
|
json_schema_extra={"label": "Bezeichnung", "frontend_type": "multilingual", "frontend_readonly": False, "frontend_required": True}
|
|
)
|
|
icon: str = Field(
|
|
default="",
|
|
description="Icon identifier for the feature",
|
|
json_schema_extra={"label": "Symbol", "frontend_type": "text", "frontend_readonly": False, "frontend_required": False}
|
|
)
|
|
|
|
|
|
@i18nModel("Feature-Instanz")
|
|
class FeatureInstance(PowerOnModel):
|
|
"""Instanz eines Features in einem Mandanten. Ein Mandant kann mehrere Instanzen desselben Features haben."""
|
|
id: str = Field(
|
|
default_factory=lambda: str(uuid.uuid4()),
|
|
description="Unique ID of the feature instance",
|
|
json_schema_extra={"label": "ID", "frontend_type": "text", "frontend_readonly": True, "frontend_required": False}
|
|
)
|
|
featureCode: str = Field(
|
|
description="FK -> Feature.code",
|
|
json_schema_extra={
|
|
"label": "Feature",
|
|
"frontend_type": "select",
|
|
"frontend_readonly": True,
|
|
"frontend_required": True,
|
|
"fk_target": {"db": "poweron_app", "table": "Feature", "column": "code"},
|
|
},
|
|
)
|
|
mandateId: str = Field(
|
|
description="FK -> Mandate.id (CASCADE DELETE)",
|
|
json_schema_extra={
|
|
"label": "Mandant",
|
|
"frontend_type": "text",
|
|
"frontend_readonly": True,
|
|
"frontend_required": True,
|
|
"fk_target": {"db": "poweron_app", "table": "Mandate"},
|
|
},
|
|
)
|
|
label: str = Field(
|
|
default="",
|
|
description="Instance label, z.B. 'Buchhaltung 2025'",
|
|
json_schema_extra={"label": "Bezeichnung", "frontend_type": "text", "frontend_readonly": False, "frontend_required": True}
|
|
)
|
|
enabled: bool = Field(
|
|
default=True,
|
|
description="Whether this feature instance is enabled",
|
|
json_schema_extra={"label": "Aktiviert", "frontend_type": "checkbox", "frontend_readonly": False, "frontend_required": False}
|
|
)
|
|
config: Optional[Dict[str, Any]] = Field(
|
|
default=None,
|
|
description="Instance-specific configuration (JSONB). Structure depends on featureCode.",
|
|
json_schema_extra={"label": "Konfiguration", "frontend_type": "json", "frontend_readonly": False, "frontend_required": False}
|
|
)
|