- Added a new column `subscriptions_locked` to the `customers` table to manage subscription access. - Implemented a script to create new modules from a template, including updates to various files (module.json, README.md, router.py, views.py, and migration SQL). - Developed a script to import BMC Office subscriptions from an Excel file into the database, including error handling and statistics reporting. - Created a script to lookup and update missing CVR numbers using the CVR.dk API. - Implemented a script to relink Hub customers to e-conomic customer numbers based on name matching. - Developed scripts to sync CVR numbers from Simply-CRM and vTiger to the local customers database.
140 lines
5.1 KiB
Python
140 lines
5.1 KiB
Python
"""
|
|
Configuration Module
|
|
Handles environment variables and application settings
|
|
"""
|
|
|
|
import os
|
|
from typing import List
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings loaded from environment variables"""
|
|
|
|
# Database
|
|
DATABASE_URL: str = "postgresql://bmc_hub:bmc_hub@localhost:5432/bmc_hub"
|
|
|
|
# API
|
|
API_HOST: str = "0.0.0.0"
|
|
API_PORT: int = 8000
|
|
|
|
# Security
|
|
SECRET_KEY: str = "dev-secret-key-change-in-production"
|
|
ALLOWED_ORIGINS: List[str] = ["http://localhost:8000", "http://localhost:3000"]
|
|
|
|
# Logging
|
|
LOG_LEVEL: str = "INFO"
|
|
LOG_FILE: str = "logs/app.log"
|
|
|
|
# e-conomic Integration
|
|
ECONOMIC_API_URL: str = "https://restapi.e-conomic.com"
|
|
ECONOMIC_APP_SECRET_TOKEN: str = ""
|
|
ECONOMIC_AGREEMENT_GRANT_TOKEN: str = ""
|
|
ECONOMIC_READ_ONLY: bool = True
|
|
ECONOMIC_DRY_RUN: bool = True
|
|
|
|
# vTiger CRM Integration
|
|
VTIGER_URL: str = ""
|
|
VTIGER_USERNAME: str = ""
|
|
VTIGER_API_KEY: str = ""
|
|
VTIGER_PASSWORD: str = "" # Fallback hvis API key ikke virker
|
|
|
|
# Simply-CRM Integration (Legacy System med CVR data)
|
|
OLD_VTIGER_URL: str = "https://bmcnetworks.simply-crm.dk"
|
|
OLD_VTIGER_USERNAME: str = "ct"
|
|
OLD_VTIGER_ACCESS_KEY: str = ""
|
|
|
|
# Time Tracking Module - vTiger Integration (Isoleret)
|
|
TIMETRACKING_VTIGER_READ_ONLY: bool = True # 🚨 SAFETY: Bloker ALLE skrivninger til vTiger
|
|
TIMETRACKING_VTIGER_DRY_RUN: bool = True # 🚨 SAFETY: Log uden at synkronisere
|
|
|
|
# Time Tracking Module - e-conomic Integration (Isoleret)
|
|
TIMETRACKING_ECONOMIC_READ_ONLY: bool = True # 🚨 SAFETY: Bloker ALLE skrivninger til e-conomic
|
|
TIMETRACKING_ECONOMIC_DRY_RUN: bool = True # 🚨 SAFETY: Log uden at eksportere
|
|
TIMETRACKING_EXPORT_TYPE: str = "draft" # draft|booked (draft er sikrest)
|
|
|
|
# Time Tracking Module - Business Logic
|
|
TIMETRACKING_DEFAULT_HOURLY_RATE: float = 850.00 # DKK pr. time (fallback)
|
|
TIMETRACKING_AUTO_ROUND: bool = True # Auto-afrund til nærmeste 0.5 time
|
|
TIMETRACKING_ROUND_INCREMENT: float = 0.5 # Afrundingsinterval (0.25, 0.5, 1.0)
|
|
TIMETRACKING_ROUND_METHOD: str = "up" # up (op til), nearest (nærmeste), down (ned til)
|
|
TIMETRACKING_REQUIRE_APPROVAL: bool = True # Kræv manuel godkendelse (ikke auto-approve)
|
|
|
|
# Ollama AI Integration
|
|
OLLAMA_ENDPOINT: str = "http://ai_direct.cs.blaahund.dk"
|
|
OLLAMA_MODEL: str = "qwen2.5-coder:7b" # qwen2.5-coder fungerer bedre til JSON udtrækning
|
|
|
|
# Email System Configuration
|
|
EMAIL_TO_TICKET_ENABLED: bool = False # 🚨 SAFETY: Disable auto-processing until configured
|
|
|
|
# Email Fetching (IMAP)
|
|
USE_GRAPH_API: bool = False # Use Microsoft Graph API instead of IMAP (preferred)
|
|
IMAP_SERVER: str = "outlook.office365.com"
|
|
IMAP_PORT: int = 993
|
|
IMAP_USE_SSL: bool = True
|
|
IMAP_USERNAME: str = ""
|
|
IMAP_PASSWORD: str = ""
|
|
IMAP_FOLDER: str = "INBOX"
|
|
IMAP_READ_ONLY: bool = True # 🚨 SAFETY: Never mark emails as read or modify mailbox
|
|
|
|
# Microsoft Graph API (OAuth2)
|
|
GRAPH_TENANT_ID: str = ""
|
|
GRAPH_CLIENT_ID: str = ""
|
|
GRAPH_CLIENT_SECRET: str = ""
|
|
GRAPH_USER_EMAIL: str = "" # Email account to monitor
|
|
|
|
# Email Processing
|
|
EMAIL_PROCESS_INTERVAL_MINUTES: int = 5 # Background job frequency
|
|
EMAIL_MAX_FETCH_PER_RUN: int = 50 # Limit emails per processing cycle
|
|
EMAIL_RETENTION_DAYS: int = 90 # Days to keep emails before soft delete
|
|
|
|
# Email Classification (AI)
|
|
EMAIL_AI_ENABLED: bool = True
|
|
EMAIL_AI_CONFIDENCE_THRESHOLD: float = 0.7 # Minimum confidence for auto-processing
|
|
EMAIL_AUTO_CLASSIFY: bool = True # Run AI classification on new emails
|
|
|
|
# Email Rules Engine
|
|
EMAIL_RULES_ENABLED: bool = True
|
|
EMAIL_RULES_AUTO_PROCESS: bool = False # 🚨 SAFETY: Require manual approval initially
|
|
|
|
# Company Info
|
|
OWN_CVR: str = "29522790" # BMC Denmark ApS - ignore when detecting vendors
|
|
|
|
# File Upload
|
|
UPLOAD_DIR: str = "uploads"
|
|
MAX_FILE_SIZE_MB: int = 50
|
|
ALLOWED_EXTENSIONS: List[str] = [".pdf", ".png", ".jpg", ".jpeg", ".txt", ".csv"]
|
|
|
|
# Module System Configuration
|
|
MODULES_ENABLED: bool = True # Enable/disable entire module system
|
|
MODULES_DIR: str = "app/modules" # Directory for dynamic modules
|
|
MODULES_AUTO_RELOAD: bool = True # Hot-reload modules on changes (dev only)
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
extra = "ignore" # Ignore extra fields from .env
|
|
|
|
|
|
settings = Settings()
|
|
|
|
|
|
def get_module_config(module_name: str, key: str, default=None):
|
|
"""
|
|
Hent modul-specifik konfiguration fra miljøvariabel
|
|
|
|
Pattern: MODULES__{MODULE_NAME}__{KEY}
|
|
Eksempel: MODULES__MY_MODULE__API_KEY
|
|
|
|
Args:
|
|
module_name: Navn på modul (fx "my_module")
|
|
key: Config key (fx "API_KEY")
|
|
default: Default værdi hvis ikke sat
|
|
|
|
Returns:
|
|
Konfigurationsværdi eller default
|
|
"""
|
|
import os
|
|
env_key = f"MODULES__{module_name.upper()}__{key.upper()}"
|
|
return os.getenv(env_key, default)
|