fix(price): remove baseprice detection, use directional price match
baseprice > price was wrongly treated as "quantity discount" — it's just GoMag's promotional price. Now: price_gomag <= pret_roa is always OK, only flag when GoMag charges MORE than ROA. Reset cached price_match at startup for re-evaluation. Fix dashboard dot color for mismatches. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -636,49 +636,39 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
|
||||
class TestGetPricesForOrderQuantityDiscount:
|
||||
"""baseprice > price means GoMag applied a discount — skip price comparison."""
|
||||
class TestGetPricesDirectionalMatch:
|
||||
"""Price match is directional: gomag <= roa is OK, gomag > roa is mismatch."""
|
||||
|
||||
def test_discount_detected(self):
|
||||
"""baseprice > price: quantity_discount=True, match=None, mismatches=0."""
|
||||
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].get("quantity_discount") is True
|
||||
assert result["items"][0]["match"] is None
|
||||
assert result["items"][0]["match"] is True
|
||||
assert result["items"][0]["pret_roa"] == 28.99
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_no_discount_when_baseprice_equals_price(self):
|
||||
"""baseprice == price: normal comparison."""
|
||||
items = [{"sku": "SKU-FULL", "price": 28.99, "baseprice": 28.99, "quantity": 1,
|
||||
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].get("quantity_discount") is not True
|
||||
assert result["items"][0]["match"] is True
|
||||
assert result["items"][0]["match"] is False
|
||||
assert result["summary"]["mismatches"] == 1
|
||||
|
||||
def test_no_discount_when_baseprice_missing(self):
|
||||
"""baseprice=0 (missing): normal comparison."""
|
||||
items = [{"sku": "SKU-OLD", "price": 28.99, "quantity": 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].get("quantity_discount") is not True
|
||||
assert result["items"][0]["match"] is True
|
||||
|
||||
def test_kit_takes_precedence_over_discount(self):
|
||||
"""Kit check runs before discount check — kit wins."""
|
||||
items = [{"sku": "SKU-KITDISC", "price": 20.0, "baseprice": 25.0, "quantity": 10,
|
||||
"codmat_details": [{"codmat": "COD4", "cantitate_roa": 2,
|
||||
"id_articol": 400, "cont": "345"}]}]
|
||||
conn = _mock_oracle_conn(pol_cu_tva=True, price_map={400: (10.0, 1.19)})
|
||||
result = get_prices_for_order(items, {"id_pol": "1"}, conn=conn)
|
||||
assert result["items"][0].get("kit") is True
|
||||
assert result["items"][0].get("quantity_discount") is not True
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
|
||||
# ── normalize_company_name (II, PFA, INTREPRINDERE INDIVIDUALA) ──
|
||||
|
||||
Reference in New Issue
Block a user