fix: NULL SUMA in PACK_FACTURARE for discount lines + SKU enrichment fallback

PACK_FACTURARE: use PTVA from COMENZI_ELEMENTE (NVL2) in adauga_articol_factura
instead of fetching PROC_TVAV from price list, fixing NULL SUMA for discount
lines with multiple TVA rates (11%, 21%).

sync.py: broaden direct SKU enrichment to all unmapped SKUs regardless of
mapping_status, fixing stale status edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-03-20 22:32:28 +00:00
parent 3fabe3f4b1
commit 5addeb08bd
2 changed files with 12 additions and 11 deletions

View File

@@ -390,12 +390,11 @@ async def order_detail(order_number: str):
if sku and sku in codmat_map:
item["codmat_details"] = codmat_map[sku]
# Enrich direct SKUs (SKU=CODMAT in NOM_ARTICOLE, no ARTICOLE_TERTI entry)
direct_skus = {item["sku"] for item in items
if item.get("sku") and item.get("mapping_status") == "direct"
and not item.get("codmat_details")}
if direct_skus:
nom_map = await asyncio.to_thread(_get_nom_articole_for_direct_skus, direct_skus)
# Enrich remaining SKUs via NOM_ARTICOLE (fallback for stale mapping_status)
remaining_skus = {item["sku"] for item in items
if item.get("sku") and not item.get("codmat_details")}
if remaining_skus:
nom_map = await asyncio.to_thread(_get_nom_articole_for_direct_skus, remaining_skus)
for item in items:
sku = item.get("sku")
if sku and sku in nom_map and not item.get("codmat_details"):