Fix normalized quantity basis
This commit is contained in:
@@ -224,13 +224,17 @@ def normalize_unit(unit):
|
||||
"OZ": "oz",
|
||||
"FZ": "fl_oz",
|
||||
"FL OZ": "fl_oz",
|
||||
"FLOZ": "fl_oz",
|
||||
"LB": "lb",
|
||||
"LBS": "lb",
|
||||
"ML": "ml",
|
||||
"L": "l",
|
||||
"QT": "qt",
|
||||
"QTS": "qt",
|
||||
"PT": "pt",
|
||||
"PTS": "pt",
|
||||
"GAL": "gal",
|
||||
"GALS": "gal",
|
||||
"GA": "gal",
|
||||
}.get(collapsed, collapsed.lower())
|
||||
|
||||
@@ -340,16 +344,24 @@ 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(size_value, size_unit, pack_qty, measure_type):
|
||||
def derive_normalized_quantity(qty, size_value, size_unit, pack_qty, measure_type):
|
||||
parsed_qty = to_decimal(qty)
|
||||
parsed_size = to_decimal(size_value)
|
||||
parsed_pack = to_decimal(pack_qty) or Decimal("1")
|
||||
parsed_pack = to_decimal(pack_qty)
|
||||
total_multiplier = None
|
||||
if parsed_qty not in (None, Decimal("0")):
|
||||
total_multiplier = parsed_qty * (parsed_pack or Decimal("1"))
|
||||
|
||||
if parsed_size not in (None, Decimal("0")) and size_unit:
|
||||
return format_decimal(parsed_size * parsed_pack), size_unit
|
||||
if parsed_pack not in (None, Decimal("0")) and measure_type == "count":
|
||||
return format_decimal(parsed_pack), "count"
|
||||
if measure_type == "each":
|
||||
return "1", "each"
|
||||
if (
|
||||
parsed_size not in (None, Decimal("0"))
|
||||
and size_unit
|
||||
and total_multiplier not in (None, Decimal("0"))
|
||||
):
|
||||
return format_decimal(parsed_size * total_multiplier), size_unit
|
||||
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")):
|
||||
return format_decimal(parsed_qty), "each"
|
||||
return "", ""
|
||||
|
||||
|
||||
@@ -424,6 +436,7 @@ def parse_item(order_id, order_date, raw_path, line_no, item):
|
||||
|
||||
normalized_row_id = f"{RETAILER}:{order_id}:{line_no}"
|
||||
normalized_quantity, normalized_quantity_unit = derive_normalized_quantity(
|
||||
item.get("shipQy"),
|
||||
size_value,
|
||||
size_unit,
|
||||
pack_qty,
|
||||
|
||||
Reference in New Issue
Block a user