fix(sync): prevent kit/bax price sync from overwriting individual CRM prices
Three code paths could overwrite CRM list prices with wrong values when web unit (50 buc) differs from ROA unit (100 buc): - price_sync_service: kit path now skips components that have their own ARTICOLE_TERTI mapping (individual path handles them with correct ÷0.5) - validation_service: sync_prices_from_order now skips bax SKUs (cantitate_roa > 1) in addition to multi-component kits - pack_import_comenzi: skip negative kit discount (markup), ROUND prices to nzecimale_pretv decimals Also adds: - SQL script for 6 ARTICOLE_TERTI mappings (cantitate_roa=0.5) for cup articles where web=50buc, ROA=100buc/set - Oracle schema reference documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,12 @@ async def run_catalog_price_sync(run_id: str):
|
||||
if is_kit:
|
||||
for comp in mapped_data[sku]:
|
||||
comp_codmat = comp["codmat"]
|
||||
|
||||
# Skip components that have their own ARTICOLE_TERTI mapping
|
||||
# (they'll be synced with correct cantitate_roa in individual path)
|
||||
if comp_codmat in mapped_data:
|
||||
continue
|
||||
|
||||
comp_product = products_by_sku.get(comp_codmat)
|
||||
if not comp_product:
|
||||
continue # Component not in GoMag as standalone product
|
||||
|
||||
@@ -542,8 +542,9 @@ def sync_prices_from_order(orders, mapped_codmat_data: dict, direct_id_map: dict
|
||||
kit_discount_codmat = (settings or {}).get("kit_discount_codmat", "")
|
||||
skip_codmats = {transport_codmat, discount_codmat, kit_discount_codmat} - {""}
|
||||
|
||||
# Build set of kit SKUs (>1 component)
|
||||
kit_skus = {sku for sku, comps in mapped_codmat_data.items() if len(comps) > 1}
|
||||
# Build set of kit/bax SKUs (>1 component, or single component with cantitate_roa > 1)
|
||||
kit_skus = {sku for sku, comps in mapped_codmat_data.items()
|
||||
if len(comps) > 1 or (len(comps) == 1 and (comps[0].get("cantitate_roa") or 1) > 1)}
|
||||
|
||||
updated = []
|
||||
own_conn = conn is None
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
-- 20.03.2026 - kit pricing extins pt reambalari single-component (cantitate_roa > 1)
|
||||
-- 21.03.2026 - diagnostic detaliat discount kit (id_pol, id_art, codmat in eroare)
|
||||
-- 21.03.2026 - fix discount amount: v_disc_amt e per-kit, nu se imparte la v_cantitate_web
|
||||
-- 25.03.2026 - skip negative kit discount (markup), ROUND prices to nzecimale_pretv
|
||||
-- ====================================================================
|
||||
CREATE OR REPLACE PACKAGE PACK_IMPORT_COMENZI AS
|
||||
|
||||
@@ -284,6 +285,9 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
v_kit_disc_count PLS_INTEGER := 0;
|
||||
v_kit_disc_found BOOLEAN;
|
||||
|
||||
-- Zecimale pret vanzare (din optiuni firma, default 2)
|
||||
v_nzec_pretv PLS_INTEGER := NVL(TO_NUMBER(pack_sesiune.getoptiunefirma(USER, 'PPRETV')), 2);
|
||||
|
||||
-- pljson
|
||||
l_json_articole CLOB := p_json_articole;
|
||||
v_json_arr pljson_list;
|
||||
@@ -492,8 +496,10 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
END IF;
|
||||
|
||||
-- pret_ajustat = pret_cu_tva - discount_share / cantitate_roa
|
||||
v_pret_ajustat := v_kit_comps(i_comp).pret_cu_tva -
|
||||
(v_discount_share / v_kit_comps(i_comp).cantitate_roa);
|
||||
v_pret_ajustat := ROUND(
|
||||
v_kit_comps(i_comp).pret_cu_tva -
|
||||
(v_discount_share / v_kit_comps(i_comp).cantitate_roa),
|
||||
v_nzec_pretv);
|
||||
|
||||
BEGIN
|
||||
merge_or_insert_articol(
|
||||
@@ -578,8 +584,8 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
v_vat_disc_alloc := v_vat_disc_alloc + v_disc_amt;
|
||||
END IF;
|
||||
|
||||
IF v_disc_amt != 0 THEN
|
||||
v_unit_pret := v_disc_amt;
|
||||
IF v_disc_amt > 0 THEN
|
||||
v_unit_pret := ROUND(v_disc_amt, v_nzec_pretv);
|
||||
|
||||
-- Search for existing entry with same (ptva, pret) to merge qty
|
||||
v_kit_disc_found := FALSE;
|
||||
|
||||
54
api/database-scripts/09_articole_terti_050.sql
Normal file
54
api/database-scripts/09_articole_terti_050.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
-- ====================================================================
|
||||
-- 09_articole_terti_050.sql
|
||||
-- Mapări ARTICOLE_TERTI cu cantitate_roa = 0.5 pentru articole
|
||||
-- unde unitatea web (50 buc/set) ≠ unitatea ROA (100 buc/set).
|
||||
--
|
||||
-- Efect: price sync va calcula pret_crm = pret_web / 0.5,
|
||||
-- iar kit pricing va folosi prețul corect per set ROA.
|
||||
--
|
||||
-- 25.03.2026 - creat pentru fix discount negativ kit pahare
|
||||
-- ====================================================================
|
||||
|
||||
-- Pahar 6oz Coffee Coffee SIBA 50buc (GoMag) → 100buc/set (ROA)
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '1708828', '1708828', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '1708828' AND codmat = '1708828' AND sters = 0
|
||||
);
|
||||
|
||||
-- Pahar 8oz Coffee Coffee SIBA 50buc → 100buc/set
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '528795', '528795', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '528795' AND codmat = '528795' AND sters = 0
|
||||
);
|
||||
|
||||
-- Pahar 8oz Tchibo 50buc → 100buc/set
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '58', '58', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '58' AND codmat = '58' AND sters = 0
|
||||
);
|
||||
|
||||
-- Pahar 7oz Lavazza SIBA 50buc → 100buc/set
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '51', '51', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '51' AND codmat = '51' AND sters = 0
|
||||
);
|
||||
|
||||
-- Pahar 8oz Albastru JND 50buc → 100buc/set
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '105712338826', '105712338826', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '105712338826' AND codmat = '105712338826' AND sters = 0
|
||||
);
|
||||
|
||||
-- Pahar 8oz Paris JND 50buc → 100buc/set
|
||||
INSERT INTO articole_terti (sku, codmat, cantitate_roa, activ, sters, data_creare, id_util_creare)
|
||||
SELECT '10573080', '10573080', 0.5, 1, 0, SYSDATE, -3 FROM dual
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM articole_terti WHERE sku = '10573080' AND codmat = '10573080' AND sters = 0
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user