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:
@@ -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"):
|
||||
|
||||
@@ -11,6 +11,8 @@ CREATE OR REPLACE PACKAGE "PACK_FACTURARE" is
|
||||
-- descarca_gestiune - tva adaos
|
||||
|
||||
-- 20.03.2026 - duplicate CODMAT pe comanda: PRET in GROUP BY/JOIN (cursor_comanda, cursor_lucrare, inchide_comanda, adauga_articol_*)
|
||||
-- 20.03.2026 - SIGN() fix for negative quantity (discount) lines in cursor_comanda and inchide_comanda
|
||||
-- 20.03.2026 - Fix NULL SUMA in adauga_articol_factura: use PTVA from COMENZI_ELEMENTE for discount lines (NVL2)
|
||||
|
||||
cnume_program VARCHAR(30) := 'ROAFACTURARE';
|
||||
|
||||
@@ -3007,7 +3009,7 @@ CREATE OR REPLACE PACKAGE BODY "PACK_FACTURARE" is
|
||||
NVL(C.UM, '') AS UM,
|
||||
C.IN_STOC AS GESTIONABIL,
|
||||
A.CANTITATE - NVL(D.CANTITATE, 0) AS CANTITATE,
|
||||
B.PROC_TVAV,
|
||||
NVL2(A.PTVA, 1+A.PTVA/100, B.PROC_TVAV) AS PROC_TVAV,
|
||||
A.PRET_CU_TVA AS PRETURI_CU_TVA,
|
||||
E.CURS,
|
||||
E.MULTIPLICATOR,
|
||||
@@ -3055,7 +3057,7 @@ CREATE OR REPLACE PACKAGE BODY "PACK_FACTURARE" is
|
||||
ON A.ID_VALUTA = F.ID_VALUTA
|
||||
WHERE A.STERS = 0
|
||||
AND A.ID_COMANDA = V_ID_COMANDA
|
||||
AND A.CANTITATE - NVL(D.CANTITATE, 0) > 0
|
||||
AND SIGN(A.CANTITATE) * (A.CANTITATE - NVL(D.CANTITATE, 0)) > 0
|
||||
ORDER BY C.DENUMIRE;
|
||||
ELSE
|
||||
-- aviz
|
||||
@@ -3094,7 +3096,7 @@ CREATE OR REPLACE PACKAGE BODY "PACK_FACTURARE" is
|
||||
NVL(C.UM, '') AS UM,
|
||||
C.IN_STOC AS GESTIONABIL,
|
||||
A.CANTITATE - NVL(D.CANTITATE, 0) AS CANTITATE,
|
||||
B.PROC_TVAV,
|
||||
NVL2(A.PTVA, 1+A.PTVA/100, B.PROC_TVAV) AS PROC_TVAV,
|
||||
A.PRET_CU_TVA AS PRETURI_CU_TVA,
|
||||
E.CURS,
|
||||
E.MULTIPLICATOR,
|
||||
@@ -5032,7 +5034,7 @@ CREATE OR REPLACE PACKAGE BODY "PACK_FACTURARE" is
|
||||
V_ID_COMANDA := to_number(pack_facturare.clistaid);
|
||||
|
||||
SELECT A.PRET,
|
||||
C.PROC_TVAV,
|
||||
NVL2(A.PTVA, ROUND((A.PTVA + 100) / 100, 2), C.PROC_TVAV),
|
||||
C.ID_VALUTA,
|
||||
B.PRETURI_CU_TVA,
|
||||
D.IN_STOC
|
||||
@@ -5792,7 +5794,7 @@ CREATE OR REPLACE PACKAGE BODY "PACK_FACTURARE" is
|
||||
AND A.PRET = C.PRET
|
||||
WHERE A.STERS = 0
|
||||
AND A.ID_COMANDA = to_number(pack_facturare.clistaid)
|
||||
AND A.CANTITATE > NVL(C.CANTITATE, 0) + NVL(B.CANTITATE, 0);
|
||||
AND SIGN(A.CANTITATE) * A.CANTITATE > SIGN(A.CANTITATE) * (NVL(C.CANTITATE, 0) + NVL(B.CANTITATE, 0));
|
||||
|
||||
END inchide_comanda;
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user