From 2478ff7c3d0c426c5f64dec71d17df13de60702a Mon Sep 17 00:00:00 2001 From: Fringg Date: Mon, 4 May 2026 05:14:47 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20expired=5F1d=20notification=20=E2=80=94?= =?UTF-8?q?=20use=20PricingEngine=20instead=20of=20hardcoded=20PRICE=5F30?= =?UTF-8?q?=5FDAYS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/handlers/admin/monitoring.py | 3 +++ app/services/monitoring_service.py | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/handlers/admin/monitoring.py b/app/handlers/admin/monitoring.py index 80f90299..b9eccc4b 100644 --- a/app/handlers/admin/monitoring.py +++ b/app/handlers/admin/monitoring.py @@ -175,6 +175,7 @@ async def _build_notification_preview_message(language: str, notification_type: message = template.format( end_date=(now - timedelta(days=1)).strftime('%d.%m.%Y %H:%M'), price=price_30_days, + tariff_label='', ) keyboard = InlineKeyboardMarkup( inline_keyboard=[ @@ -213,6 +214,7 @@ async def _build_notification_preview_message(language: str, notification_type: percent=percent, expires_at=(now + timedelta(hours=valid_hours)).strftime('%d.%m.%Y %H:%M'), trigger_days=3, + tariff_label='', ) keyboard = InlineKeyboardMarkup( inline_keyboard=[ @@ -258,6 +260,7 @@ async def _build_notification_preview_message(language: str, notification_type: percent=percent, trigger_days=trigger_days, expires_at=(now + timedelta(hours=valid_hours)).strftime('%d.%m.%Y %H:%M'), + tariff_label='', ) keyboard = InlineKeyboardMarkup( inline_keyboard=[ diff --git a/app/services/monitoring_service.py b/app/services/monitoring_service.py index a3476e01..acf63e44 100644 --- a/app/services/monitoring_service.py +++ b/app/services/monitoring_service.py @@ -1044,7 +1044,7 @@ class MonitoringService: # Day 1 reminder if NotificationSettingsService.is_expired_1d_enabled() and 1 <= days_since < 2: if not await notification_sent(db, user.id, subscription.id, 'expired_1d'): - success = await self._send_expired_day1_notification(user, subscription) + success = await self._send_expired_day1_notification(db, user, subscription) if success: await record_notification(db, user.id, subscription.id, 'expired_1d') sent_day1 += 1 @@ -1811,12 +1811,29 @@ class MonitoringService: ) return False - async def _send_expired_day1_notification(self, user: User, subscription: Subscription) -> bool: + async def _send_expired_day1_notification(self, db: AsyncSession, user: User, subscription: Subscription) -> bool: try: texts = get_texts(user.language) + tariff = getattr(subscription, 'tariff', None) tariff_label = '' - if settings.is_multi_tariff_enabled() and hasattr(subscription, 'tariff') and subscription.tariff: - tariff_label = f' «{subscription.tariff.name}»' + if settings.is_multi_tariff_enabled() and tariff: + tariff_label = f' «{tariff.name}»' + + renewal_period = (tariff.get_shortest_period() if tariff else None) or 30 + try: + from app.services.pricing_engine import pricing_engine + + pricing = await pricing_engine.calculate_renewal_price(db, subscription, renewal_period, user=user) + renewal_price_kopeks = pricing.final_total + except Exception as price_error: + logger.warning( + 'Не удалось рассчитать цену продления для уведомления expired_1d, используем PRICE_30_DAYS', + subscription_id=subscription.id, + user_id=user.id, + error=str(price_error), + ) + renewal_price_kopeks = settings.PRICE_30_DAYS + template = texts.get( 'SUBSCRIPTION_EXPIRED_1D', ( @@ -1826,7 +1843,7 @@ class MonitoringService: ) message = template.format( end_date=format_local_datetime(subscription.end_date, '%d.%m.%Y %H:%M'), - price=settings.format_price(settings.PRICE_30_DAYS), + price=settings.format_price(renewal_price_kopeks), tariff_label=tariff_label, )