merge: confirmare valori needs_review bulk+rapid (PR3 / Issue B)
This commit is contained in:
@@ -3648,6 +3648,63 @@ async def web_confirma_review(
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.post("/_import/{import_id}/confirma-toate-review", response_class=HTMLResponse)
|
||||
async def web_confirma_toate_review(
|
||||
request: Request,
|
||||
import_id: int,
|
||||
) -> HTMLResponse:
|
||||
"""Confirma in bloc TOATE randurile needs_review din batch → reviewed=1 (B1).
|
||||
|
||||
Un singur click marcheaza reviewed=1 pe toate randurile cu resolved_status='needs_review'
|
||||
din batch-ul curent (om in bucla: operatorul confirma explicit intreg lotul, fara
|
||||
auto-accept). Refoloseste EXACT logica din /confirma-review (reviewed=1 = marcaj separat,
|
||||
NU camp de continut), aplicata in masa. La recalcul (_web_compute_preview) randurile cu
|
||||
reviewed=1 si fara erori reale devin ok.
|
||||
|
||||
CSRF + scoped sesiune (404 cross-account) + guard committed (409). O singura recompute
|
||||
+ re-randare #import-section la final (identic cu web_mapare_operatii).
|
||||
"""
|
||||
account_id = require_login(request)
|
||||
conn = get_connection()
|
||||
try:
|
||||
form = await request.form()
|
||||
verify_csrf(request, str(form.get("csrf_token") or ""))
|
||||
|
||||
# Guard batch: 404 cross-account (nu confirmam existenta), 409 committed.
|
||||
acct = account_or_default(account_id)
|
||||
batch = conn.execute(
|
||||
"SELECT id, status FROM import_batches WHERE id=? AND account_id=?",
|
||||
(import_id, acct),
|
||||
).fetchone()
|
||||
if not batch:
|
||||
raise HTTPException(status_code=404, detail="batch de import inexistent sau inaccesibil")
|
||||
if batch["status"] == "committed":
|
||||
raise HTTPException(status_code=409, detail="batch deja comis; confirmarea nu mai are efect")
|
||||
|
||||
# Marcheaza reviewed=1 pe toate randurile needs_review ale batch-ului (scoped pe batch,
|
||||
# deja verificat ca apartine contului). Acelasi marcaj ca /confirma-review, in masa.
|
||||
cur = conn.execute(
|
||||
"UPDATE import_rows SET reviewed=1 "
|
||||
"WHERE batch_id=? AND resolved_status='needs_review'",
|
||||
(import_id,),
|
||||
)
|
||||
n_confirmate = cur.rowcount if cur.rowcount is not None and cur.rowcount >= 0 else 0
|
||||
|
||||
message = (
|
||||
f"Confirmate {n_confirmate} randuri cu valori de verificat."
|
||||
if n_confirmate
|
||||
else "Niciun rand de confirmat."
|
||||
)
|
||||
result = _web_compute_preview(conn, import_id, account_id)
|
||||
if isinstance(result, str):
|
||||
return templates.TemplateResponse("_upload.html", _ctx(request, error=result))
|
||||
return templates.TemplateResponse("_preview_import.html", _ctx(
|
||||
request, import_id=import_id, message=message, **result
|
||||
))
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.post("/_import/{import_id}/mapare-operatie", response_class=HTMLResponse)
|
||||
async def web_mapare_operatie(
|
||||
request: Request,
|
||||
|
||||
Reference in New Issue
Block a user