Compare commits

..
2 Commits
3 changed files with 26 additions and 16 deletions

No files matched your search

+1
View File
@@ -358,6 +358,7 @@ def convert_product_to_mongo(product: Product) -> dict:
"endDate": timing["end_date"], "endDate": timing["end_date"],
"priceBeforeDrop": pricing["price_before_drop"], "priceBeforeDrop": pricing["price_before_drop"],
"eduPrice": pricing["edu_price"], "eduPrice": pricing["edu_price"],
"hasMsrp": pricing["has_msrp"],
"available": availability["available"], "available": availability["available"],
"availabilityLastChecked": availability["availability_last_checked"], "availabilityLastChecked": availability["availability_last_checked"],
"condition": availability["condition"], "condition": availability["condition"],
+1
View File
@@ -62,6 +62,7 @@ class PricingInfo:
price_before_drop: float | None = None price_before_drop: float | None = None
edu_price: float | None = None edu_price: float | None = None
past_prices: list[dict] | None = None past_prices: list[dict] | None = None
has_msrp: bool = True
@dataclass @dataclass
+24 -16
View File
@@ -167,23 +167,30 @@ def build_product_details(
product_id = product["_id"] product_id = product["_id"]
current_price = product["currentPrice"] current_price = product["currentPrice"]
original_price = product["originalPrice"] original_price = product["originalPrice"]
if not original_price:
LOGGER.warning(
"missing or zero original price, skipping",
extra={"product_id": product_id},
)
return
percentage = int(((original_price - current_price) / original_price) * 100) percentage = 0
price_drop = original_price - current_price has_msrp = product["has_msrp"]
# A percentage code compounds onto the sale price, so an item can clear the if has_msrp:
# threshold on the combined discount even when the base discount would not. if not original_price:
# Dollar codes do not map to a percent and never affect the threshold. LOGGER.warning(
effective_percentage = combined_discount(percentage, product.get("promoPercentage")) "missing or zero original price, skipping",
passes_percentage = effective_percentage >= min_percentage extra={"product_id": product_id},
passes_price_drop = min_price_drop is not None and price_drop >= min_price_drop )
if not passes_percentage and not passes_price_drop: return
return
percentage = int(((original_price - current_price) / original_price) * 100)
price_drop = original_price - current_price
# A percentage code compounds onto the sale price, so an item can clear the
# threshold on the combined discount even when the base discount would not.
# Dollar codes do not map to a percent and never affect the threshold.
effective_percentage = combined_discount(
percentage, product.get("promoPercentage")
)
passes_percentage = effective_percentage >= min_percentage
passes_price_drop = min_price_drop is not None and price_drop >= min_price_drop
if not passes_percentage and not passes_price_drop:
return
built = Product( built = Product(
product_id=product_id, product_id=product_id,
@@ -212,6 +219,7 @@ def build_product_details(
price_before_drop=product["priceBeforeDrop"], price_before_drop=product["priceBeforeDrop"],
edu_price=product["eduPrice"], edu_price=product["eduPrice"],
past_prices=product["pastPrices"], past_prices=product["pastPrices"],
has_msrp=has_msrp,
), ),
availability=AvailabilityInfo( availability=AvailabilityInfo(
available=product["available"], available=product["available"],