Round discounted subscription prices up and clean summary

This commit is contained in:
Egor
2025-09-29 15:43:50 +03:00
parent 88e8a56526
commit ae05ca08ea
2 changed files with 12 additions and 3 deletions

View File

@@ -292,13 +292,15 @@ async def _prepare_subscription_summary(
else:
traffic_display = f"{summary_data.get('traffic_gb', 0)} ГБ"
base_line = f"- Базовый период: {texts.format_price(base_price_original)}"
if base_discount_total > 0:
base_line += (
f"{texts.format_price(base_price)}"
base_line = (
f"- Базовый период: <s>{texts.format_price(base_price_original)}</s> "
f"{texts.format_price(base_price)}"
f" (скидка {period_discount_percent}%:"
f" -{texts.format_price(base_discount_total)})"
)
else:
base_line = f"- Базовый период: {texts.format_price(base_price_original)}"
details_lines = [base_line]

View File

@@ -50,6 +50,13 @@ def apply_percentage_discount(amount: int, percent: int) -> Tuple[int, int]:
discount_value = amount * clamped_percent // 100
discounted_amount = amount - discount_value
# Round the discounted price up to the nearest full ruble (100 kopeks)
# to avoid undercharging users because of fractional kopeks.
if discount_value >= 100 and discounted_amount % 100:
discounted_amount += 100 - (discounted_amount % 100)
discounted_amount = min(discounted_amount, amount)
discount_value = amount - discounted_amount
logger.debug(
"Применена скидка %s%%: %s%s (скидка %s)",
clamped_percent,