Files
gomag-vending/api/app/config.py
Marius Mutu 2e65855fe2 feat(sync): already_imported tracking, invoice cache, path fixes, remove vfp
- Track already_imported/new_imported counts separately in sync_runs
  and surface them in status API + dashboard last-run card
- Cache invoice data in SQLite orders table (factura_* columns);
  dashboard falls back to Oracle only for uncached imported orders
- Resolve JSON_OUTPUT_DIR and SQLITE_DB_PATH relative to known
  anchored roots in config.py, independent of CWD (fixes WSL2 start)
- Use single Oracle connection for entire validation phase (perf)
- Batch upsert web_products instead of one-by-one
- Remove stale VFP scripts (replaced by gomag-vending.prg workflow)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 00:15:37 +02:00

58 lines
1.7 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_GESTIUNE: int = 0
ID_SECTIE: int = 0
@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()