feat(sync): handle cancelled GoMag orders (status Anulata / statusId 7)
- Add web_status column to orders table (generic name for platform status) - Filter cancelled orders during sync, record as CANCELLED in SQLite - Soft-delete previously-imported cancelled orders in Oracle (if not invoiced) - Add CANCELLED filter pill + badge in dashboard UI - New soft_delete_order_in_roa() and mark_order_cancelled() functions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -294,3 +294,51 @@ def import_single_order(order, id_pol: int = None, id_sectie: int = None, app_se
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def soft_delete_order_in_roa(id_comanda: int) -> dict:
|
||||
"""Soft-delete an order in Oracle ROA (set sters=1 on comenzi + comenzi_detalii).
|
||||
Returns {"success": bool, "error": str|None, "details_deleted": int}
|
||||
"""
|
||||
result = {"success": False, "error": None, "details_deleted": 0}
|
||||
|
||||
if database.pool is None:
|
||||
result["error"] = "Oracle pool not initialized"
|
||||
return result
|
||||
|
||||
conn = None
|
||||
try:
|
||||
conn = database.pool.acquire()
|
||||
with conn.cursor() as cur:
|
||||
# Soft-delete order details
|
||||
cur.execute(
|
||||
"UPDATE comenzi_detalii SET sters = 1 WHERE id_comanda = :1 AND sters = 0",
|
||||
[id_comanda]
|
||||
)
|
||||
result["details_deleted"] = cur.rowcount
|
||||
|
||||
# Soft-delete the order itself
|
||||
cur.execute(
|
||||
"UPDATE comenzi SET sters = 1 WHERE id_comanda = :1 AND sters = 0",
|
||||
[id_comanda]
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
result["success"] = True
|
||||
logger.info(f"Soft-deleted order ID={id_comanda} in Oracle ROA ({result['details_deleted']} details)")
|
||||
except Exception as e:
|
||||
result["error"] = str(e)
|
||||
logger.error(f"Error soft-deleting order ID={id_comanda}: {e}")
|
||||
if conn:
|
||||
try:
|
||||
conn.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
if conn:
|
||||
try:
|
||||
database.pool.release(conn)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user