- PL/SQL: handle duplicate CODMAT in nom_articole with MAX(id_articol) - import_service: add explicit conn.rollback() on Oracle errors - sync_service: auto-fix stale ERROR orders that exist in Oracle - invoice_service: add data_act (invoice date) from vanzari table - sync router: new POST /api/dashboard/refresh-invoices endpoint - order detail: enrich with invoice data (serie, numar, data factura) - dashboard: refresh invoices button (desktop + mobile icon) - quick map modal: compact single-row layout, pre-populate existing mappings - quick map: link on SKU column instead of CODMAT Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import logging
|
|
from .. import database
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def check_invoices_for_orders(id_comanda_list: list) -> dict:
|
|
"""Check which orders have been invoiced in Oracle (vanzari table).
|
|
Returns {id_comanda: {facturat, numar_act, serie_act, total_fara_tva, total_tva, total_cu_tva}}
|
|
"""
|
|
if not id_comanda_list or database.pool is None:
|
|
return {}
|
|
|
|
result = {}
|
|
conn = database.get_oracle_connection()
|
|
try:
|
|
with conn.cursor() as cur:
|
|
for i in range(0, len(id_comanda_list), 500):
|
|
batch = id_comanda_list[i:i+500]
|
|
placeholders = ",".join([f":c{j}" for j in range(len(batch))])
|
|
params = {f"c{j}": cid for j, cid in enumerate(batch)}
|
|
|
|
cur.execute(f"""
|
|
SELECT id_comanda, numar_act, serie_act,
|
|
total_fara_tva, total_tva, total_cu_tva,
|
|
TO_CHAR(data_act, 'YYYY-MM-DD') AS data_act
|
|
FROM vanzari
|
|
WHERE id_comanda IN ({placeholders}) AND sters = 0
|
|
""", params)
|
|
for row in cur:
|
|
result[row[0]] = {
|
|
"facturat": True,
|
|
"numar_act": row[1],
|
|
"serie_act": row[2],
|
|
"total_fara_tva": float(row[3]) if row[3] else 0,
|
|
"total_tva": float(row[4]) if row[4] else 0,
|
|
"total_cu_tva": float(row[5]) if row[5] else 0,
|
|
"data_act": row[6],
|
|
}
|
|
except Exception as e:
|
|
logger.warning(f"Invoice check failed (table may not exist): {e}")
|
|
finally:
|
|
database.pool.release(conn)
|
|
|
|
return result
|