feat(editor): editor prestatii unificat in modal - un select, un rand de chips (PRD 5.23)
Inlocuieste cele 3 controale de asociere cod RAR cu un singur rand de chips + un singur select care adauga instant la change. Stare = un hidden chips_state JSON versionat; post_form_chips redus la 2 actiuni (add/remove). Optgroup Sugestii (fuzzy/k-NN) + optiune "Nu se declara la RAR" in select, cu tinta implicita evidentiata si placeholder care o numeste. exclus persistat prin payload_json (treapta noua de precedenta in resolve_prestatii, round-trip complet). Siguranta: itemii exclusi sunt scosi din payload la momentul trimiterii (worker split_prestatii_excluse inainte de build_rar_payload + filtru defensiv), ca sa nu ajunga NICIODATA la RAR ca codPrestatie:null. Suita: 1680 passed, 1 skipped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,8 +8,10 @@ Un cod ales explicit pe rand bate regula de excludere.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
@@ -191,8 +193,72 @@ def test_rand_mixt_exclude_doar_operatia_exclusa(client):
|
||||
finally:
|
||||
conn.close()
|
||||
payload = json.loads(sub["payload_json"])
|
||||
coduri = [p.get("cod_prestatie") for p in payload["prestatii"]]
|
||||
assert coduri == ["OE-2"], f"Operatia exclusa nu trebuie sa plece la RAR: {coduri}"
|
||||
# Round-trip: itemul exclus RAMANE in payload_json (persistat), adnotat exclus,
|
||||
# dar fara cod_prestatie — nu pleaca niciodata la RAR (vezi build_rar_payload).
|
||||
by_op = {p.get("cod_op_service"): p for p in payload["prestatii"] if p.get("cod_op_service")}
|
||||
assert by_op["OP-ITP"]["exclus"] is True
|
||||
assert not by_op["OP-ITP"].get("cod_prestatie")
|
||||
coduri_declarabile = [p.get("cod_prestatie") for p in payload["prestatii"] if not p.get("exclus")]
|
||||
assert coduri_declarabile == ["OE-2"], f"Operatia exclusa nu trebuie sa plece la RAR: {coduri_declarabile}"
|
||||
|
||||
|
||||
def test_reupload_rand_cu_exclus_deja_comis_e_already_sent(client):
|
||||
"""Cheia de idempotenta la commit (doar declarabile) e IDENTICA cu preview.
|
||||
|
||||
Re-incarcarea aceluiasi rand (dupa ce a fost deja comis cu un item exclus
|
||||
adnotat in payload) trebuie recunoscuta drept duplicat — nu un rand nou.
|
||||
"""
|
||||
_seed()
|
||||
rows = [{
|
||||
"VIN": "WVWZZZ1KZAW000789",
|
||||
"Nr": "B003TST",
|
||||
"Data": "2026-06-12",
|
||||
"KM": "90000",
|
||||
"Operatie": "OP-ITP",
|
||||
}]
|
||||
iid = _upload_and_preview(client, rows=rows)
|
||||
csrf = _get_csrf(client)
|
||||
client.post(f"/_import/{iid}/mapare-operatii", data={
|
||||
"cod_op_service": "OP-ITP", "cod_prestatie": "__NEDECLARAT__", "csrf_token": csrf,
|
||||
})
|
||||
client.post(f"/_import/{iid}/rand/0/editeaza", data={
|
||||
"cod_prestatie": ["", "OE-2"],
|
||||
"chip_op_service": ["OP-ITP", ""],
|
||||
"chip_denumire": ["", ""],
|
||||
})
|
||||
csrf = _get_csrf(client)
|
||||
rc = client.post(f"/_import/{iid}/confirma", data={"n_confirmat": "1", "csrf_token": csrf})
|
||||
assert rc.status_code == 200, rc.text
|
||||
|
||||
# Re-incarca acelasi rand + acelasi cod ales pe editorul de rand. Maparea de
|
||||
# coloane e deja memorata din primul upload -> raspunsul sare direct la preview
|
||||
# (fara link mapare-coloane); extragem import_id din hx-get pe #import-section.
|
||||
csv_data = _csv_bytes(rows)
|
||||
csrf = _get_csrf(client)
|
||||
r2 = client.post(
|
||||
"/_import/upload",
|
||||
files={"file": ("test.csv", io.BytesIO(csv_data), "text/csv")},
|
||||
data={"csrf_token": csrf},
|
||||
)
|
||||
assert r2.status_code == 200, r2.text
|
||||
m2 = re.search(r"/_import/(\d+)/preview", r2.text)
|
||||
assert m2, f"import_id negasit in raspunsul de reupload: {r2.text[:300]}"
|
||||
iid2 = int(m2.group(1))
|
||||
csrf = _get_csrf(client)
|
||||
client.post(f"/_import/{iid2}/mapare-operatii", data={
|
||||
"cod_op_service": "OP-ITP", "cod_prestatie": "__NEDECLARAT__", "csrf_token": csrf,
|
||||
})
|
||||
client.post(f"/_import/{iid2}/rand/0/editeaza", data={
|
||||
"cod_prestatie": ["", "OE-2"],
|
||||
"chip_op_service": ["OP-ITP", ""],
|
||||
"chip_denumire": ["", ""],
|
||||
})
|
||||
# already_sent se calculeaza doar la refresh-ul complet de preview (lookup pe
|
||||
# tot batch-ul), nu la editarea unui singur rand — reincarcam preview-ul.
|
||||
rp = client.get(f"/_import/{iid2}/preview")
|
||||
assert rp.status_code == 200
|
||||
assert "Deja trimis" in rp.text, \
|
||||
"Randul re-incarcat trebuie recunoscut deja trimis (cheia de idempotenta neschimbata)"
|
||||
|
||||
|
||||
def test_cod_explicit_pe_operatie_bate_regula_de_excludere(client):
|
||||
|
||||
Reference in New Issue
Block a user