feat(price): detect quantity discounts via baseprice, show Disc. badge
GoMag sends baseprice (catalog price) alongside price (discounted). When baseprice > price, the item is volume-discounted — skip ROA price comparison and show amber "Disc." badge instead of false mismatch. Strikethrough baseprice in price column for transparency. Pipeline: parse baseprice → store in SQLite → skip in validation → pass flag to frontend → render badge (desktop + mobile pill badge with aria-label, opacity 0.6 for dark mode). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -636,6 +636,51 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
|
||||
class TestGetPricesForOrderQuantityDiscount:
|
||||
"""baseprice > price means GoMag applied a discount — skip price comparison."""
|
||||
|
||||
def test_discount_detected(self):
|
||||
"""baseprice > price: quantity_discount=True, match=None, mismatches=0."""
|
||||
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["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,
|
||||
"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
|
||||
|
||||
def test_no_discount_when_baseprice_missing(self):
|
||||
"""baseprice=0 (missing): normal comparison."""
|
||||
items = [{"sku": "SKU-OLD", "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
|
||||
|
||||
|
||||
# ── normalize_company_name (II, PFA, INTREPRINDERE INDIVIDUALA) ──
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user