Add effective price to purchases
This commit is contained in:
@@ -51,6 +51,7 @@ PURCHASE_FIELDS = [
|
|||||||
"price_per_lb_basis",
|
"price_per_lb_basis",
|
||||||
"price_per_oz",
|
"price_per_oz",
|
||||||
"price_per_oz_basis",
|
"price_per_oz_basis",
|
||||||
|
"effective_price",
|
||||||
"is_discount_line",
|
"is_discount_line",
|
||||||
"is_coupon_line",
|
"is_coupon_line",
|
||||||
"is_fee",
|
"is_fee",
|
||||||
@@ -172,6 +173,24 @@ def derive_metrics(row):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def derive_effective_price(row):
|
||||||
|
normalized_quantity = to_decimal(row.get("normalized_quantity"))
|
||||||
|
if normalized_quantity in (None, Decimal("0")):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
net_line_total = to_decimal(row.get("net_line_total"))
|
||||||
|
line_total = to_decimal(row.get("line_total"))
|
||||||
|
numerator = (
|
||||||
|
net_line_total
|
||||||
|
if net_line_total not in (None, Decimal("0"))
|
||||||
|
else line_total
|
||||||
|
)
|
||||||
|
if numerator is None:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
return format_decimal(numerator / normalized_quantity)
|
||||||
|
|
||||||
|
|
||||||
def order_lookup(rows, retailer):
|
def order_lookup(rows, retailer):
|
||||||
return {(retailer, row["order_id"]): row for row in rows}
|
return {(retailer, row["order_id"]): row for row in rows}
|
||||||
|
|
||||||
@@ -353,6 +372,7 @@ def build_purchase_rows(
|
|||||||
"store_number": order_row.get("store_number", ""),
|
"store_number": order_row.get("store_number", ""),
|
||||||
"store_city": order_row.get("store_city", ""),
|
"store_city": order_row.get("store_city", ""),
|
||||||
"store_state": order_row.get("store_state", ""),
|
"store_state": order_row.get("store_state", ""),
|
||||||
|
"effective_price": derive_effective_price(row),
|
||||||
"is_discount_line": row["is_discount_line"],
|
"is_discount_line": row["is_discount_line"],
|
||||||
"is_coupon_line": row["is_coupon_line"],
|
"is_coupon_line": row["is_coupon_line"],
|
||||||
"is_fee": row["is_fee"],
|
"is_fee": row["is_fee"],
|
||||||
|
|||||||
Reference in New Issue
Block a user