fix(price): skip price check for kit/complex articles
Kit articles (multi-component or cantitate_roa≠1) have expected price differences between GoMag (commercial) and ROA (component sum). Skip comparison entirely, mark with kit=True flag for UI badge. Fix kit detection to use float()!=1 (catches cantitate_roa<1 like 0.5). Update 3 existing tests + add multi-component kit test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -539,7 +539,7 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
"""
|
||||
|
||||
def test_cantitate_roa_half_matches(self):
|
||||
"""cantitate_roa=0.5: ROA price 14.00 * 0.5 = 7.00 should match GoMag 7.00."""
|
||||
"""cantitate_roa=0.5: kit item — price check skipped entirely."""
|
||||
items = [{
|
||||
"sku": "1057308134545",
|
||||
"price": 7.00,
|
||||
@@ -554,12 +554,12 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
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 True
|
||||
assert abs(result["items"][0]["pret_roa"] - 7.00) < 0.01
|
||||
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: ROA price 10.00 * 0.5 = 5.00 != GoMag 7.00."""
|
||||
"""cantitate_roa=0.5: kit item — price check skipped even if prices differ."""
|
||||
items = [{
|
||||
"sku": "SKU-HALF",
|
||||
"price": 7.00,
|
||||
@@ -574,9 +574,9 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
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 False
|
||||
assert abs(result["items"][0]["pret_roa"] - 5.00) < 0.01
|
||||
assert result["summary"]["mismatches"] == 1
|
||||
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."""
|
||||
@@ -598,7 +598,7 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
assert result["summary"]["mismatches"] == 0
|
||||
|
||||
def test_cantitate_roa_gt1_kit(self):
|
||||
"""cantitate_roa=2: kit with 2 ROA units per GoMag unit."""
|
||||
"""cantitate_roa=2: kit item — price check skipped."""
|
||||
items = [{
|
||||
"sku": "SKU-KIT2",
|
||||
"price": 20.00,
|
||||
@@ -613,5 +613,24 @@ class TestGetPricesForOrderCantitateRoa:
|
||||
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 True
|
||||
assert abs(result["items"][0]["pret_roa"] - 20.00) < 0.01
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user