This commit is contained in:
parent
3ec9fef3cf
commit
c234285788
@ -154,7 +154,7 @@ class PricingService:
|
||||
tcg_low = Decimal(str(row.get('tcg_low_price'))) if not pd.isna(row.get('tcg_low_price')) else None
|
||||
tcg_low_shipping = Decimal(str(row.get('tcg_low_price_with_shipping'))) if not pd.isna(row.get('tcg_low_price_with_shipping')) else None
|
||||
tcg_market_price = Decimal(str(row.get('tcg_market_price'))) if not pd.isna(row.get('tcg_market_price')) else None
|
||||
current_price = Decimal(str(row.get('tcg_marketplace_price'))) if not pd.isna(row.get('tcgplayer_marketplace_price')) else None
|
||||
current_price = Decimal(str(row.get('tcg_marketplace_price'))) if not pd.isna(row.get('tcg_marketplace_price')) else None
|
||||
total_quantity = str(row.get('total_quantity')) if not pd.isna(row.get('total_quantity')) else "0"
|
||||
added_quantity = str(row.get('add_to_quantity')) if not pd.isna(row.get('add_to_quantity')) else "0"
|
||||
quantity = int(total_quantity) + int(added_quantity)
|
||||
@ -163,10 +163,10 @@ class PricingService:
|
||||
logger.warning(f"Missing pricing data for row: {row}")
|
||||
row['new_price'] = None
|
||||
return row
|
||||
# Define precision for rounding
|
||||
|
||||
TWO_PLACES = Decimal('0.01')
|
||||
|
||||
# Apply pricing rules
|
||||
# Original markup bands
|
||||
markup_bands = {
|
||||
2.53: (Decimal('0.01'), Decimal('0.50')),
|
||||
1.42: (Decimal('0.51'), Decimal('1.00')),
|
||||
@ -179,38 +179,53 @@ class PricingService:
|
||||
1.01: (Decimal('200.01'), Decimal('1000.00'))
|
||||
}
|
||||
|
||||
# Adjust markups if quantity is high
|
||||
if quantity > 3:
|
||||
quantity_markup = Decimal('0.1')
|
||||
for markup in markup_bands:
|
||||
markup = markup + quantity_markup
|
||||
quantity_markup = quantity_markup - Decimal('0.01')
|
||||
|
||||
if FREE_SHIPPING:
|
||||
free_shipping_markup = Decimal('0.05')
|
||||
for markup in markup_bands:
|
||||
markup = markup + free_shipping_markup
|
||||
free_shipping_markup = free_shipping_markup - Decimal('0.005')
|
||||
|
||||
# Apply the smoothed markup
|
||||
new_price = self.smooth_markup(tcg_market_price, markup_bands)
|
||||
adjusted_bands = {}
|
||||
increment = Decimal('0.10')
|
||||
for markup, price_range in zip(markup_bands.keys(), markup_bands.values()):
|
||||
new_markup = Decimal(str(markup)) + increment
|
||||
adjusted_bands[new_markup] = price_range
|
||||
increment -= Decimal('0.01')
|
||||
markup_bands = adjusted_bands
|
||||
|
||||
if tcg_low_shipping is not None and tcg_low_shipping < new_price:
|
||||
new_price = tcg_low_shipping
|
||||
|
||||
if FREE_SHIPPING:
|
||||
if tcg_low_shipping:
|
||||
tcg_compare_price = tcg_low_shipping
|
||||
elif tcg_low:
|
||||
tcg_compare_price = tcg_low + Decimal('1.31')
|
||||
else:
|
||||
logger.warning(f"No TCG low or shipping price available for row: {row}")
|
||||
row['new_price'] = None
|
||||
return row
|
||||
else:
|
||||
tcg_compare_price = tcg_low
|
||||
if tcg_compare_price is None:
|
||||
logger.warning(f"No TCG low price available for row: {row}")
|
||||
row['new_price'] = None
|
||||
return row
|
||||
|
||||
# Apply the smoothed markup
|
||||
new_price = self.smooth_markup(tcg_compare_price, markup_bands)
|
||||
|
||||
# Enforce minimum price
|
||||
if new_price < Decimal('0.25'):
|
||||
new_price = Decimal('0.25')
|
||||
|
||||
if current_price / new_price > Decimal('0.25'):
|
||||
|
||||
# Avoid huge price drops
|
||||
if current_price is not None and new_price / current_price > Decimal('0.25'):
|
||||
logger.warning(f"Price drop too large for row: {row}")
|
||||
new_price = current_price
|
||||
|
||||
# Ensure exactly 2 decimal places
|
||||
|
||||
# Round to 2 decimal places
|
||||
new_price = new_price.quantize(TWO_PLACES, rounding=ROUND_HALF_UP)
|
||||
# Convert back to float or string as needed for your dataframe
|
||||
|
||||
# Convert back to float for dataframe
|
||||
row['new_price'] = float(new_price)
|
||||
|
||||
|
||||
return row
|
||||
|
||||
|
||||
def default_pricing_algo(self, row: pd.Series) -> pd.Series:
|
||||
"""Default pricing algorithm with complex pricing rules"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user