Update inline.py

This commit is contained in:
Egor
2026-01-31 17:04:59 +03:00
committed by GitHub
parent 38ff15e794
commit 1bb5ef85aa
+33 -10
View File
@@ -1924,12 +1924,28 @@ def get_change_devices_keyboard(
texts = get_texts(language)
months_multiplier = 1
period_text = ''
if subscription_end_date:
months_multiplier = get_remaining_months(subscription_end_date)
if months_multiplier > 1:
period_text = f' (за {months_multiplier} мес)'
# Проверяем является ли тариф суточным
is_daily_tariff = tariff and getattr(tariff, 'is_daily', False)
# Для суточных тарифов считаем по дням, для обычных - по месяцам
if is_daily_tariff and subscription_end_date:
# Суточный тариф: цена за оставшиеся дни (обычно 1 день)
from datetime import datetime
now = datetime.utcnow()
days_left = max(1, (subscription_end_date - now).days)
# Множитель = days_left / 30 (как в кабинете)
price_multiplier = days_left / 30
period_text = f' (за {days_left} дн.)' if days_left > 1 else ' (за 1 день)'
else:
# Обычный тариф: цена за оставшиеся месяцы
months_multiplier = 1
period_text = ''
if subscription_end_date:
months_multiplier = get_remaining_months(subscription_end_date)
if months_multiplier > 1:
period_text = f' (за {months_multiplier} мес)'
price_multiplier = months_multiplier
# Используем цену из тарифа если есть, иначе глобальную настройку
tariff_device_price = getattr(tariff, 'device_price_kopeks', None) if tariff else None
@@ -1943,7 +1959,12 @@ def get_change_devices_keyboard(
buttons = []
max_devices = settings.MAX_DEVICES_LIMIT if settings.MAX_DEVICES_LIMIT > 0 else 20
# Используем max_device_limit из тарифа если есть, иначе глобальную настройку
tariff_max_devices = getattr(tariff, 'max_device_limit', None) if tariff else None
if tariff_max_devices and tariff_max_devices > 0:
max_devices = tariff_max_devices
else:
max_devices = settings.MAX_DEVICES_LIMIT if settings.MAX_DEVICES_LIMIT > 0 else 20
start_range = max(1, min(current_devices - 3, max_devices - 6))
end_range = min(max_devices + 1, max(current_devices + 4, 7))
@@ -1967,10 +1988,12 @@ def get_change_devices_keyboard(
price_per_month,
discount_percent,
)
total_price = discounted_per_month * months_multiplier
total_price = int(discounted_per_month * price_multiplier)
total_price = max(100, total_price) # Минимум 1 рубль
price_text = f' (+{total_price // 100}{period_text})'
if discount_percent > 0 and discount_per_month * months_multiplier > 0:
price_text += f' (скидка {discount_percent}%: -{(discount_per_month * months_multiplier) // 100}₽)'
total_discount = int(discount_per_month * price_multiplier)
if discount_percent > 0 and total_discount > 0:
price_text += f' (скидка {discount_percent}%: -{total_discount // 100}₽)'
action_text = ''
else:
price_text = ' (бесплатно)'