feat(pricing): kit/pachet pricing with price list lookup, replace procent_pret
- Oracle PL/SQL: kit pricing logic with Mode A (distributed discount) and
Mode B (separate discount line), dual policy support, PRETURI_CU_TVA flag
- Eliminate procent_pret from entire stack (Oracle, Python, JS, HTML)
- New settings: kit_pricing_mode, kit_discount_codmat, price_sync_enabled
- Settings UI: cards for Kit Pricing and Price Sync configuration
- Mappings UI: kit badges with lazy-loaded component prices from price list
- Price sync from orders: auto-update ROA prices when web prices differ
- Catalog price sync: new service to sync all GoMag product prices to ROA
- Kit component price validation: pre-check prices before import
- New endpoint GET /api/mappings/{sku}/prices for component price display
- New endpoints POST /api/price-sync/start, GET status, GET history
- DDL script 07_drop_procent_pret.sql (run after deploy confirmation)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,13 @@ class AppSettingsUpdate(BaseModel):
|
||||
gomag_order_days_back: str = "7"
|
||||
gomag_limit: str = "100"
|
||||
dashboard_poll_seconds: str = "5"
|
||||
kit_pricing_mode: str = ""
|
||||
kit_discount_codmat: str = ""
|
||||
kit_discount_id_pol: str = ""
|
||||
price_sync_enabled: str = "1"
|
||||
catalog_sync_enabled: str = "0"
|
||||
price_sync_schedule: str = ""
|
||||
gomag_products_url: str = ""
|
||||
|
||||
|
||||
# API endpoints
|
||||
@@ -139,6 +146,31 @@ async def sync_history(page: int = 1, per_page: int = 20):
|
||||
return await sqlite_service.get_sync_runs(page, per_page)
|
||||
|
||||
|
||||
@router.post("/api/price-sync/start")
|
||||
async def start_price_sync(background_tasks: BackgroundTasks):
|
||||
"""Trigger manual catalog price sync."""
|
||||
from ..services import price_sync_service
|
||||
result = await price_sync_service.prepare_price_sync()
|
||||
if result.get("error"):
|
||||
return {"error": result["error"]}
|
||||
run_id = result["run_id"]
|
||||
background_tasks.add_task(price_sync_service.run_catalog_price_sync, run_id=run_id)
|
||||
return {"message": "Price sync started", "run_id": run_id}
|
||||
|
||||
|
||||
@router.get("/api/price-sync/status")
|
||||
async def price_sync_status():
|
||||
"""Get current price sync status."""
|
||||
from ..services import price_sync_service
|
||||
return await price_sync_service.get_price_sync_status()
|
||||
|
||||
|
||||
@router.get("/api/price-sync/history")
|
||||
async def price_sync_history(page: int = 1, per_page: int = 20):
|
||||
"""Get price sync run history."""
|
||||
return await sqlite_service.get_price_sync_runs(page, per_page)
|
||||
|
||||
|
||||
@router.get("/logs", response_class=HTMLResponse)
|
||||
async def logs_page(request: Request, run: str = None):
|
||||
return templates.TemplateResponse("logs.html", {"request": request, "selected_run": run or ""})
|
||||
@@ -285,7 +317,7 @@ async def sync_run_orders(run_id: str, status: str = "all", page: int = 1, per_p
|
||||
|
||||
|
||||
def _get_articole_terti_for_skus(skus: set) -> dict:
|
||||
"""Query ARTICOLE_TERTI for all active codmat/cantitate/procent per SKU."""
|
||||
"""Query ARTICOLE_TERTI for all active codmat/cantitate per SKU."""
|
||||
from .. import database
|
||||
result = {}
|
||||
sku_list = list(skus)
|
||||
@@ -297,7 +329,7 @@ def _get_articole_terti_for_skus(skus: set) -> dict:
|
||||
placeholders = ",".join([f":s{j}" for j in range(len(batch))])
|
||||
params = {f"s{j}": sku for j, sku in enumerate(batch)}
|
||||
cur.execute(f"""
|
||||
SELECT at.sku, at.codmat, at.cantitate_roa, at.procent_pret,
|
||||
SELECT at.sku, at.codmat, at.cantitate_roa,
|
||||
na.denumire
|
||||
FROM ARTICOLE_TERTI at
|
||||
LEFT JOIN NOM_ARTICOLE na ON na.codmat = at.codmat AND na.sters = 0 AND na.inactiv = 0
|
||||
@@ -311,8 +343,7 @@ def _get_articole_terti_for_skus(skus: set) -> dict:
|
||||
result[sku].append({
|
||||
"codmat": row[1],
|
||||
"cantitate_roa": float(row[2]) if row[2] else 1,
|
||||
"procent_pret": float(row[3]) if row[3] else 100,
|
||||
"denumire": row[4] or ""
|
||||
"denumire": row[3] or ""
|
||||
})
|
||||
finally:
|
||||
database.pool.release(conn)
|
||||
@@ -371,7 +402,6 @@ async def order_detail(order_number: str):
|
||||
item["codmat_details"] = [{
|
||||
"codmat": sku,
|
||||
"cantitate_roa": 1,
|
||||
"procent_pret": 100,
|
||||
"denumire": nom_map[sku],
|
||||
"direct": True
|
||||
}]
|
||||
@@ -663,6 +693,13 @@ async def get_app_settings():
|
||||
"gomag_order_days_back": s.get("gomag_order_days_back", "") or str(config_settings.GOMAG_ORDER_DAYS_BACK),
|
||||
"gomag_limit": s.get("gomag_limit", "") or str(config_settings.GOMAG_LIMIT),
|
||||
"dashboard_poll_seconds": s.get("dashboard_poll_seconds", "5"),
|
||||
"kit_pricing_mode": s.get("kit_pricing_mode", ""),
|
||||
"kit_discount_codmat": s.get("kit_discount_codmat", ""),
|
||||
"kit_discount_id_pol": s.get("kit_discount_id_pol", ""),
|
||||
"price_sync_enabled": s.get("price_sync_enabled", "1"),
|
||||
"catalog_sync_enabled": s.get("catalog_sync_enabled", "0"),
|
||||
"price_sync_schedule": s.get("price_sync_schedule", ""),
|
||||
"gomag_products_url": s.get("gomag_products_url", ""),
|
||||
}
|
||||
|
||||
|
||||
@@ -685,6 +722,13 @@ async def update_app_settings(config: AppSettingsUpdate):
|
||||
await sqlite_service.set_app_setting("gomag_order_days_back", config.gomag_order_days_back)
|
||||
await sqlite_service.set_app_setting("gomag_limit", config.gomag_limit)
|
||||
await sqlite_service.set_app_setting("dashboard_poll_seconds", config.dashboard_poll_seconds)
|
||||
await sqlite_service.set_app_setting("kit_pricing_mode", config.kit_pricing_mode)
|
||||
await sqlite_service.set_app_setting("kit_discount_codmat", config.kit_discount_codmat)
|
||||
await sqlite_service.set_app_setting("kit_discount_id_pol", config.kit_discount_id_pol)
|
||||
await sqlite_service.set_app_setting("price_sync_enabled", config.price_sync_enabled)
|
||||
await sqlite_service.set_app_setting("catalog_sync_enabled", config.catalog_sync_enabled)
|
||||
await sqlite_service.set_app_setting("price_sync_schedule", config.price_sync_schedule)
|
||||
await sqlite_service.set_app_setting("gomag_products_url", config.gomag_products_url)
|
||||
return {"success": True}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user