- Remove ID_GESTIUNE from config (unused) - Add GoMag API settings (key, shop, days_back, limit) to SQLite — editable without restart - sync_service reads GoMag settings from SQLite before download - gomag_client.download_orders accepts api_key/api_shop/limit overrides - New GET /api/settings/sectii and /api/settings/politici endpoints for Oracle dropdowns (nom_sectii.sectie, crm_politici_preturi.nume_lista_preturi) - id_pol, id_sectie, transport_id_pol, discount_id_pol now use select dropdowns - order_reader extracts discount_vat from GoMag JSON discounts[].vat - import_service uses GoMag discount_vat as primary, settings as fallback - settings.html redesigned to compact 2x2 grid (GoMag API | Import ROA / Transport | Discount) - settings.js v2: loadDropdowns() sequential before loadSettings() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
from pydantic_settings import BaseSettings
|
|
from pydantic import model_validator
|
|
from pathlib import Path
|
|
import os
|
|
|
|
# Anchored paths - independent of CWD
|
|
_api_root = Path(__file__).resolve().parent.parent # .../gomag/api/
|
|
_project_root = _api_root.parent # .../gomag/
|
|
_env_path = _api_root / ".env"
|
|
|
|
class Settings(BaseSettings):
|
|
# Oracle
|
|
ORACLE_USER: str = "MARIUSM_AUTO"
|
|
ORACLE_PASSWORD: str = "ROMFASTSOFT"
|
|
ORACLE_DSN: str = "ROA_CENTRAL"
|
|
INSTANTCLIENTPATH: str = ""
|
|
FORCE_THIN_MODE: bool = False
|
|
TNS_ADMIN: str = ""
|
|
|
|
# SQLite
|
|
SQLITE_DB_PATH: str = "data/import.db"
|
|
|
|
# App
|
|
APP_PORT: int = 5003
|
|
LOG_LEVEL: str = "INFO"
|
|
JSON_OUTPUT_DIR: str = "output"
|
|
|
|
# SMTP (optional)
|
|
SMTP_HOST: str = ""
|
|
SMTP_PORT: int = 587
|
|
SMTP_USER: str = ""
|
|
SMTP_PASSWORD: str = ""
|
|
SMTP_TO: str = ""
|
|
|
|
# Auth (optional)
|
|
API_USERNAME: str = ""
|
|
API_PASSWORD: str = ""
|
|
|
|
# ROA Import Settings
|
|
ID_POL: int = 0
|
|
ID_SECTIE: int = 0
|
|
|
|
# GoMag API
|
|
GOMAG_API_KEY: str = ""
|
|
GOMAG_API_SHOP: str = ""
|
|
GOMAG_ORDER_DAYS_BACK: int = 7
|
|
GOMAG_LIMIT: int = 100
|
|
GOMAG_API_URL: str = "https://api.gomag.ro/api/v1/order/read/json"
|
|
|
|
@model_validator(mode="after")
|
|
def resolve_paths(self):
|
|
"""Resolve relative paths against known roots, independent of CWD."""
|
|
# SQLITE_DB_PATH: relative to api/ root
|
|
if self.SQLITE_DB_PATH and not os.path.isabs(self.SQLITE_DB_PATH):
|
|
self.SQLITE_DB_PATH = str(_api_root / self.SQLITE_DB_PATH)
|
|
# JSON_OUTPUT_DIR: relative to project root
|
|
if self.JSON_OUTPUT_DIR and not os.path.isabs(self.JSON_OUTPUT_DIR):
|
|
self.JSON_OUTPUT_DIR = str(_project_root / self.JSON_OUTPUT_DIR)
|
|
return self
|
|
|
|
model_config = {"env_file": str(_env_path), "env_file_encoding": "utf-8", "extra": "ignore"}
|
|
|
|
settings = Settings()
|