refactor(price): remove price comparison UI and catalog sync
GoMag vs ROA price comparison generated too many false positives (kits, volume discounts, special prices). Removes comparison columns, dots, badges, catalog sync endpoints, and ~950 lines of dead code. Keeps WRITE path (sync_prices_from_order) for kit pricing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -280,7 +280,7 @@ class TestSyncPricesKitSkip:
|
||||
# ===========================================================================
|
||||
|
||||
class TestKitComponentOwnMapping:
|
||||
"""Regression: price_sync_service skips kit components that have their own ARTICOLE_TERTI mapping."""
|
||||
"""Regression: kit components that have their own ARTICOLE_TERTI mapping should be skipped."""
|
||||
|
||||
def test_component_with_own_mapping_skipped(self):
|
||||
"""If comp_codmat is itself a key in mapped_data, it's skipped."""
|
||||
@@ -306,7 +306,7 @@ class TestKitComponentOwnMapping:
|
||||
# ===========================================================================
|
||||
|
||||
class TestVatIncludedNormalization:
|
||||
"""Regression: GoMag returns vat_included as int 1 or string '1' (price_sync_service.py:144)."""
|
||||
"""Regression: GoMag returns vat_included as int 1 or string '1'."""
|
||||
|
||||
def _compute_price_cu_tva(self, product):
|
||||
price = float(product.get("price", "0"))
|
||||
@@ -494,183 +494,6 @@ class TestResolveCodmatIds:
|
||||
assert "COD2" in codmats
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Group 6: get_prices_for_order() — cantitate_roa price normalization
|
||||
# ===========================================================================
|
||||
|
||||
from app.services.validation_service import get_prices_for_order
|
||||
|
||||
|
||||
def _mock_oracle_conn(pol_cu_tva=False, price_map=None):
|
||||
"""Build a mock Oracle connection for get_prices_for_order.
|
||||
|
||||
price_map: {id_articol: (pret, proc_tvav)}
|
||||
"""
|
||||
if price_map is None:
|
||||
price_map = {}
|
||||
conn = MagicMock()
|
||||
|
||||
def cursor_ctx():
|
||||
cur = MagicMock()
|
||||
# CRM_POLITICI_PRETURI — PRETURI_CU_TVA flag
|
||||
cu_tva_row = [1 if pol_cu_tva else 0]
|
||||
# CRM_POLITICI_PRET_ART — prices
|
||||
price_rows = [
|
||||
(1, id_art, pret, proc_tvav)
|
||||
for id_art, (pret, proc_tvav) in price_map.items()
|
||||
]
|
||||
# fetchone for PRETURI_CU_TVA, __iter__ for price rows
|
||||
cur.fetchone = MagicMock(return_value=cu_tva_row)
|
||||
cur.__iter__ = MagicMock(return_value=iter(price_rows))
|
||||
return cur
|
||||
|
||||
cm = MagicMock()
|
||||
cm.__enter__ = MagicMock(side_effect=cursor_ctx)
|
||||
cm.__exit__ = MagicMock(return_value=False)
|
||||
conn.cursor.return_value = cm
|
||||
return conn
|
||||
|
||||
|
||||
class TestGetPricesForOrderCantitateRoa:
|
||||
"""Regression: cantitate_roa < 1 must be treated as kit for price normalization.
|
||||
|
||||
Bug: SKU with cantitate_roa=0.5 (GoMag 50buc=7lei, ROA 100buc=14lei)
|
||||
was reported as price mismatch because is_kit only checked > 1.
|
||||
"""
|
||||
|
||||
def test_cantitate_roa_half_matches(self):
|
||||
"""cantitate_roa=0.5: kit item — price check skipped entirely."""
|
||||
items = [{
|
||||
"sku": "1057308134545",
|
||||
"price": 7.00,
|
||||
"quantity": 60,
|
||||
"codmat_details": [{
|
||||
"codmat": "8OZLRLP",
|
||||
"cantitate_roa": 0.5,
|
||||
"id_articol": 100,
|
||||
"cont": "345",
|
||||
}],
|
||||
}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={100: (14.00, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
|
||||
assert result["items"][0]["match"] is None
|
||||
assert result["items"][0]["kit"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_cantitate_roa_half_mismatch(self):
|
||||
"""cantitate_roa=0.5: kit item — price check skipped even if prices differ."""
|
||||
items = [{
|
||||
"sku": "SKU-HALF",
|
||||
"price": 7.00,
|
||||
"quantity": 1,
|
||||
"codmat_details": [{
|
||||
"codmat": "COD1",
|
||||
"cantitate_roa": 0.5,
|
||||
"id_articol": 200,
|
||||
"cont": "345",
|
||||
}],
|
||||
}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={200: (10.00, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
|
||||
assert result["items"][0]["match"] is None
|
||||
assert result["items"][0]["kit"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_cantitate_roa_one_simple_item(self):
|
||||
"""cantitate_roa=1 (default): simple item, direct price comparison."""
|
||||
items = [{
|
||||
"sku": "SKU-SIMPLE",
|
||||
"price": 63.79,
|
||||
"quantity": 8,
|
||||
"codmat_details": [{
|
||||
"codmat": "COD-DIRECT",
|
||||
"cantitate_roa": 1,
|
||||
"id_articol": 300,
|
||||
"cont": "345",
|
||||
}],
|
||||
}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={300: (63.79, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
|
||||
assert result["items"][0]["match"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_cantitate_roa_gt1_kit(self):
|
||||
"""cantitate_roa=2: kit item — price check skipped."""
|
||||
items = [{
|
||||
"sku": "SKU-KIT2",
|
||||
"price": 20.00,
|
||||
"quantity": 1,
|
||||
"codmat_details": [{
|
||||
"codmat": "COD-KIT",
|
||||
"cantitate_roa": 2,
|
||||
"id_articol": 400,
|
||||
"cont": "345",
|
||||
}],
|
||||
}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={400: (10.00, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
|
||||
assert result["items"][0]["match"] is None
|
||||
assert result["items"][0]["kit"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_multi_component_kit_skipped(self):
|
||||
"""Multi-component kit (2 CODMATs): price check skipped, kit=True."""
|
||||
items = [{
|
||||
"sku": "SKU-MULTI",
|
||||
"price": 15.00,
|
||||
"quantity": 1,
|
||||
"codmat_details": [
|
||||
{"codmat": "COMP-A", "cantitate_roa": 1, "id_articol": 500, "cont": "345"},
|
||||
{"codmat": "COMP-B", "cantitate_roa": 1, "id_articol": 501, "cont": "345"},
|
||||
],
|
||||
}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={500: (8.00, 1.19), 501: (9.00, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
|
||||
assert result["items"][0]["match"] is None
|
||||
assert result["items"][0]["kit"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
|
||||
class TestGetPricesDirectionalMatch:
|
||||
"""Price match is directional: gomag <= roa is OK, gomag > roa is mismatch."""
|
||||
|
||||
def test_gomag_below_roa_is_match(self):
|
||||
"""GoMag price lower than ROA (promo/volume discount) → match=True."""
|
||||
items = [{"sku": "SKU-DISC", "price": 28.59, "baseprice": 33.0, "quantity": 48,
|
||||
"codmat_details": [{"codmat": "COD1", "cantitate_roa": 1,
|
||||
"id_articol": 100, "cont": "345"}]}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={100: (28.99, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
assert result["items"][0]["match"] is True
|
||||
assert result["items"][0]["pret_roa"] == 28.99
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_gomag_above_roa_is_mismatch(self):
|
||||
"""GoMag price higher than ROA → match=False, mismatch counted."""
|
||||
items = [{"sku": "SKU-HIGH", "price": 30.00, "quantity": 1,
|
||||
"codmat_details": [{"codmat": "COD2", "cantitate_roa": 1,
|
||||
"id_articol": 200, "cont": "345"}]}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={200: (28.99, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
assert result["items"][0]["match"] is False
|
||||
assert result["summary"]["mismatches"] == 1
|
||||
|
||||
def test_gomag_equals_roa_is_match(self):
|
||||
"""GoMag price equals ROA → match=True."""
|
||||
items = [{"sku": "SKU-FULL", "price": 28.99, "quantity": 1,
|
||||
"codmat_details": [{"codmat": "COD3", "cantitate_roa": 1,
|
||||
"id_articol": 300, "cont": "345"}]}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={300: (28.99, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
assert result["items"][0]["match"] is True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
|
||||
# ── normalize_company_name (II, PFA, INTREPRINDERE INDIVIDUALA) ──
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user