From 61c4887c38413f1f19b6db5094d6ab16a6d1269a Mon Sep 17 00:00:00 2001 From: TPV Date: Tue, 4 Aug 2026 10:04:32 -0700 Subject: [PATCH] added has_msrp for no msrp based products(new lists) --- src/monitor_utils/database.py | 1 + src/monitor_utils/models.py | 1 + src/monitor_utils/runner.py | 40 +++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/monitor_utils/database.py b/src/monitor_utils/database.py index bf85560..f1a4f29 100644 --- a/src/monitor_utils/database.py +++ b/src/monitor_utils/database.py @@ -358,6 +358,7 @@ def convert_product_to_mongo(product: Product) -> dict: "endDate": timing["end_date"], "priceBeforeDrop": pricing["price_before_drop"], "eduPrice": pricing["edu_price"], + "hasMsrp": pricing["has_msrp"], "available": availability["available"], "availabilityLastChecked": availability["availability_last_checked"], "condition": availability["condition"], diff --git a/src/monitor_utils/models.py b/src/monitor_utils/models.py index d103973..56049f3 100644 --- a/src/monitor_utils/models.py +++ b/src/monitor_utils/models.py @@ -62,6 +62,7 @@ class PricingInfo: price_before_drop: float | None = None edu_price: float | None = None past_prices: list[dict] | None = None + has_msrp: bool = True @dataclass diff --git a/src/monitor_utils/runner.py b/src/monitor_utils/runner.py index 106584e..6dfdd65 100644 --- a/src/monitor_utils/runner.py +++ b/src/monitor_utils/runner.py @@ -167,23 +167,30 @@ def build_product_details( product_id = product["_id"] current_price = product["currentPrice"] 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) - 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 + percentage = 0 + has_msrp = product["has_msrp"] + if has_msrp: + 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) + 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( product_id=product_id, @@ -212,6 +219,7 @@ def build_product_details( price_before_drop=product["priceBeforeDrop"], edu_price=product["eduPrice"], past_prices=product["pastPrices"], + has_msrp=has_msrp, ), availability=AvailabilityInfo( available=product["available"], -- 2.54.0