feat(settings): add GoMag API config, Oracle dropdowns, compact 2x2 layout

- 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>
This commit is contained in:
Claude Agent
2026-03-16 16:39:59 +00:00
parent a0649279cf
commit 227dabd6d4
8 changed files with 268 additions and 97 deletions

View File

@@ -16,19 +16,27 @@ logger = logging.getLogger(__name__)
async def download_orders(
json_dir: str,
days_back: int = None,
api_key: str = None,
api_shop: str = None,
limit: int = None,
log_fn: Callable[[str], None] = None,
) -> dict:
"""Download orders from GoMag API and save as JSON files.
Returns dict with keys: pages, total, files (list of saved file paths).
If API keys are not configured, returns immediately with empty result.
Optional api_key, api_shop, limit override config.settings values.
"""
def _log(msg: str):
logger.info(msg)
if log_fn:
log_fn(msg)
if not settings.GOMAG_API_KEY or not settings.GOMAG_API_SHOP:
effective_key = api_key or settings.GOMAG_API_KEY
effective_shop = api_shop or settings.GOMAG_API_SHOP
effective_limit = limit or settings.GOMAG_LIMIT
if not effective_key or not effective_shop:
_log("GoMag API keys neconfigurați, skip download")
return {"pages": 0, "total": 0, "files": []}
@@ -40,8 +48,8 @@ async def download_orders(
out_dir.mkdir(parents=True, exist_ok=True)
headers = {
"Apikey": settings.GOMAG_API_KEY,
"ApiShop": settings.GOMAG_API_SHOP,
"Apikey": effective_key,
"ApiShop": effective_shop,
"User-Agent": "Mozilla/5.0",
"Content-Type": "application/json",
}
@@ -57,7 +65,7 @@ async def download_orders(
params = {
"startDate": start_date,
"page": page,
"limit": settings.GOMAG_LIMIT,
"limit": effective_limit,
}
try:
response = await client.get(settings.GOMAG_API_URL, headers=headers, params=params)