fix(anaf-dedup): fix ANAF parsing, facturare addr, compact modal layout
- Fix ANAF API: extract CUI from date_generale (not top-level), fix notFound casing (capital F) - Fix missing facturare address when same ID as livrare (copy instead of skip) - Replace ANAF cache pre-population stub with real logic (3-month CUIs) - Restructure order detail modal: inline 2-col GOMAG|ROA layout with compact address lines replacing collapsed sections - Fix addrMatch() to use field-level comparison with Romanian abbreviation stripping (STR, NR, BL, SC, AP, ET, ETAJ, APART) - Add dashboard "Diferente" filter pill for ANAF-adjusted orders - Update e2e test for new modal structure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -696,6 +696,8 @@ async def get_orders(page: int = 1, per_page: int = 50,
|
||||
if status_filter and status_filter not in ("all", "UNINVOICED"):
|
||||
if status_filter.upper() == "IMPORTED":
|
||||
data_clauses.append("UPPER(status) IN ('IMPORTED', 'ALREADY_IMPORTED')")
|
||||
elif status_filter.upper() == "DIFFS":
|
||||
data_clauses.append("(anaf_cod_fiscal_adjusted = 1 OR anaf_denumire_mismatch = 1)")
|
||||
else:
|
||||
data_clauses.append("UPPER(status) = ?")
|
||||
data_params.append(status_filter.upper())
|
||||
@@ -749,6 +751,14 @@ async def get_orders(page: int = 1, per_page: int = 50,
|
||||
cursor = await db.execute(f"SELECT COUNT(*) FROM orders {uninv_old_where}", base_params)
|
||||
uninvoiced_old = (await cursor.fetchone())[0]
|
||||
|
||||
# Diffs count: orders with ANAF adjustments
|
||||
diffs_clauses = list(base_clauses) + [
|
||||
"(anaf_cod_fiscal_adjusted = 1 OR anaf_denumire_mismatch = 1)"
|
||||
]
|
||||
diffs_where = "WHERE " + " AND ".join(diffs_clauses)
|
||||
cursor = await db.execute(f"SELECT COUNT(*) FROM orders {diffs_where}", base_params)
|
||||
diffs_count = (await cursor.fetchone())[0]
|
||||
|
||||
return {
|
||||
"orders": [dict(r) for r in rows],
|
||||
"total": total,
|
||||
@@ -765,6 +775,7 @@ async def get_orders(page: int = 1, per_page: int = 50,
|
||||
"total": sum(status_counts.values()),
|
||||
"uninvoiced_sqlite": uninvoiced_sqlite,
|
||||
"uninvoiced_old": uninvoiced_old,
|
||||
"diffs": diffs_count,
|
||||
}
|
||||
}
|
||||
finally:
|
||||
@@ -1072,6 +1083,35 @@ async def bulk_populate_anaf_cache(results: dict[str, dict]):
|
||||
await db.close()
|
||||
|
||||
|
||||
async def get_expired_cuis_for_prepopulate() -> list[str]:
|
||||
"""Get CUIs from recent orders that need ANAF cache refresh."""
|
||||
from ..services import anaf_service
|
||||
db = await get_sqlite()
|
||||
try:
|
||||
cursor = await db.execute("""
|
||||
SELECT DISTINCT cod_fiscal_gomag FROM orders
|
||||
WHERE cod_fiscal_gomag IS NOT NULL
|
||||
AND cod_fiscal_gomag != ''
|
||||
AND order_date >= date('now', '-3 months')
|
||||
""")
|
||||
rows = await cursor.fetchall()
|
||||
|
||||
cuis_to_check = []
|
||||
for row in rows:
|
||||
raw = row["cod_fiscal_gomag"]
|
||||
bare = anaf_service.strip_ro_prefix(raw)
|
||||
if not anaf_service.validate_cui(bare):
|
||||
continue
|
||||
# Check if cache is valid
|
||||
cached = await get_anaf_cache(bare)
|
||||
if cached is None:
|
||||
cuis_to_check.append(bare)
|
||||
|
||||
return cuis_to_check
|
||||
finally:
|
||||
await db.close()
|
||||
|
||||
|
||||
# ── Partner/Address Data on Orders ─────────────────
|
||||
|
||||
async def update_order_partner_data(order_number: str, partner_data: dict):
|
||||
|
||||
Reference in New Issue
Block a user