Use picked weight for Giant quantity basis
This commit is contained in:
@@ -199,6 +199,7 @@ def parse_costco_item(order_id, order_date, raw_path, line_no, item):
|
||||
size_unit,
|
||||
pack_qty,
|
||||
measure_type,
|
||||
"",
|
||||
)
|
||||
identity_key, normalization_basis = normalization_identity(
|
||||
{
|
||||
|
||||
@@ -344,10 +344,11 @@ def derive_prices(item, measure_type, size_value="", size_unit="", pack_qty=""):
|
||||
return price_per_each, price_per_lb, price_per_oz
|
||||
|
||||
|
||||
def derive_normalized_quantity(qty, size_value, size_unit, pack_qty, measure_type):
|
||||
def derive_normalized_quantity(qty, size_value, size_unit, pack_qty, measure_type, picked_weight=""):
|
||||
parsed_qty = to_decimal(qty)
|
||||
parsed_size = to_decimal(size_value)
|
||||
parsed_pack = to_decimal(pack_qty)
|
||||
parsed_picked_weight = to_decimal(picked_weight)
|
||||
total_multiplier = None
|
||||
if parsed_qty not in (None, Decimal("0")):
|
||||
total_multiplier = parsed_qty * (parsed_pack or Decimal("1"))
|
||||
@@ -358,6 +359,8 @@ def derive_normalized_quantity(qty, size_value, size_unit, pack_qty, measure_typ
|
||||
and total_multiplier not in (None, Decimal("0"))
|
||||
):
|
||||
return format_decimal(parsed_size * total_multiplier), size_unit
|
||||
if measure_type == "weight" and parsed_picked_weight not in (None, Decimal("0")):
|
||||
return format_decimal(parsed_picked_weight), "lb"
|
||||
if measure_type == "count" and total_multiplier not in (None, Decimal("0")):
|
||||
return format_decimal(total_multiplier), "count"
|
||||
if measure_type == "each" and parsed_qty not in (None, Decimal("0")):
|
||||
@@ -441,6 +444,7 @@ def parse_item(order_id, order_date, raw_path, line_no, item):
|
||||
size_unit,
|
||||
pack_qty,
|
||||
measure_type,
|
||||
item.get("totalPickedWeight"),
|
||||
)
|
||||
identity_key, normalization_basis = normalization_identity(
|
||||
{
|
||||
|
||||
@@ -129,6 +129,63 @@ class EnrichGiantTests(unittest.TestCase):
|
||||
("2", "each"),
|
||||
enrich_giant.derive_normalized_quantity("2", "", "", "", "each"),
|
||||
)
|
||||
self.assertEqual(
|
||||
("1.68", "lb"),
|
||||
enrich_giant.derive_normalized_quantity("1", "", "", "", "weight", "1.68"),
|
||||
)
|
||||
|
||||
def test_parse_item_uses_picked_weight_for_loose_weight_items(self):
|
||||
banana = enrich_giant.parse_item(
|
||||
order_id="abc123",
|
||||
order_date="2026-03-01",
|
||||
raw_path=Path("raw/abc123.json"),
|
||||
line_no=1,
|
||||
item={
|
||||
"podId": 1,
|
||||
"shipQy": 1,
|
||||
"totalPickedWeight": 1.68,
|
||||
"unitPrice": 0.99,
|
||||
"itemName": "FRESH BANANA",
|
||||
"lbEachCd": "LB",
|
||||
"groceryAmount": 0.99,
|
||||
"primUpcCd": "111",
|
||||
"mvpSavings": 0,
|
||||
"rewardSavings": 0,
|
||||
"couponSavings": 0,
|
||||
"couponPrice": 0,
|
||||
"categoryId": "1",
|
||||
"categoryDesc": "Grocery",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual("weight", banana["measure_type"])
|
||||
self.assertEqual("1.68", banana["normalized_quantity"])
|
||||
self.assertEqual("lb", banana["normalized_quantity_unit"])
|
||||
|
||||
patty = enrich_giant.parse_item(
|
||||
order_id="abc123",
|
||||
order_date="2026-03-01",
|
||||
raw_path=Path("raw/abc123.json"),
|
||||
line_no=2,
|
||||
item={
|
||||
"podId": 2,
|
||||
"shipQy": 1,
|
||||
"totalPickedWeight": 1.29,
|
||||
"unitPrice": 10.05,
|
||||
"itemName": "80% PATTIES PK12",
|
||||
"lbEachCd": "LB",
|
||||
"groceryAmount": 10.05,
|
||||
"primUpcCd": "222",
|
||||
"mvpSavings": 0,
|
||||
"rewardSavings": 0,
|
||||
"couponSavings": 0,
|
||||
"couponPrice": 0,
|
||||
"categoryId": "1",
|
||||
"categoryDesc": "Grocery",
|
||||
},
|
||||
)
|
||||
self.assertEqual("1.29", patty["normalized_quantity"])
|
||||
self.assertEqual("lb", patty["normalized_quantity_unit"])
|
||||
|
||||
def test_build_items_enriched_reads_raw_order_files_and_writes_csv(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
|
||||
Reference in New Issue
Block a user