From ae05ca08eae3a651da4df8cf94b7fcb96d44ae02 Mon Sep 17 00:00:00 2001 From: Egor Date: Mon, 29 Sep 2025 15:43:50 +0300 Subject: [PATCH] Round discounted subscription prices up and clean summary --- app/handlers/subscription.py | 8 +++++--- app/utils/pricing_utils.py | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/handlers/subscription.py b/app/handlers/subscription.py index 1eb66101..dbe9a51f 100644 --- a/app/handlers/subscription.py +++ b/app/handlers/subscription.py @@ -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"- Базовый период: {texts.format_price(base_price_original)} " + 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] diff --git a/app/utils/pricing_utils.py b/app/utils/pricing_utils.py index 40d7f589..f54a8302 100644 --- a/app/utils/pricing_utils.py +++ b/app/utils/pricing_utils.py @@ -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,