diff --git a/app/handlers/subscription/devices.py b/app/handlers/subscription/devices.py
index 034e9e68..8bbe1804 100644
--- a/app/handlers/subscription/devices.py
+++ b/app/handlers/subscription/devices.py
@@ -183,13 +183,6 @@ async def handle_change_devices(
texts = get_texts(db_user.language)
subscription = db_user.subscription
- if not settings.is_devices_selection_enabled():
- await callback.answer(
- texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
- show_alert=True,
- )
- return
-
if not subscription or subscription.is_trial:
await callback.answer(
texts.t("PAID_FEATURE_ONLY", "⚠️ Эта функция доступна только для платных подписок"),
@@ -197,6 +190,29 @@ async def handle_change_devices(
)
return
+ # Проверяем тариф подписки
+ tariff = None
+ if subscription.tariff_id:
+ from app.database.crud.tariff import get_tariff_by_id
+ tariff = await get_tariff_by_id(db, subscription.tariff_id)
+
+ # Для тарифов - проверяем разрешено ли изменение устройств
+ if tariff:
+ if tariff.device_price_kopeks is None or tariff.device_price_kopeks <= 0:
+ await callback.answer(
+ texts.t("TARIFF_DEVICES_DISABLED", "⚠️ Изменение устройств недоступно для вашего тарифа"),
+ show_alert=True,
+ )
+ return
+ else:
+ # Для обычных подписок проверяем глобальную настройку
+ if not settings.is_devices_selection_enabled():
+ await callback.answer(
+ texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
+ show_alert=True,
+ )
+ return
+
current_devices = subscription.device_limit
period_hint_days = _get_period_hint_from_subscription(subscription)
@@ -206,17 +222,34 @@ async def handle_change_devices(
period_hint_days,
)
- prompt_text = texts.t(
- "CHANGE_DEVICES_PROMPT",
- (
- "📱 Изменение количества устройств\n\n"
- "Текущий лимит: {current_devices} устройств\n"
- "Выберите новое количество устройств:\n\n"
- "💡 Важно:\n"
- "• При увеличении - доплата пропорционально оставшемуся времени\n"
- "• При уменьшении - возврат средств не производится"
- ),
- ).format(current_devices=current_devices)
+ # Для тарифов показываем цену из тарифа
+ if tariff:
+ price_per_device = tariff.device_price_kopeks
+ price_text = texts.format_price(price_per_device)
+ prompt_text = texts.t(
+ "CHANGE_DEVICES_PROMPT_TARIFF",
+ (
+ "📱 Изменение количества устройств\n\n"
+ "Текущий лимит: {current_devices} устройств\n"
+ "Цена за доп. устройство: {price}/мес\n"
+ "Выберите новое количество устройств:\n\n"
+ "💡 Важно:\n"
+ "• При увеличении - доплата пропорционально оставшемуся времени\n"
+ "• При уменьшении - возврат средств не производится"
+ ),
+ ).format(current_devices=current_devices, price=price_text)
+ else:
+ prompt_text = texts.t(
+ "CHANGE_DEVICES_PROMPT",
+ (
+ "📱 Изменение количества устройств\n\n"
+ "Текущий лимит: {current_devices} устройств\n"
+ "Выберите новое количество устройств:\n\n"
+ "💡 Важно:\n"
+ "• При увеличении - доплата пропорционально оставшемуся времени\n"
+ "• При уменьшении - возврат средств не производится"
+ ),
+ ).format(current_devices=current_devices)
await callback.message.edit_text(
prompt_text,
@@ -225,6 +258,7 @@ async def handle_change_devices(
db_user.language,
subscription.end_date,
devices_discount_percent,
+ tariff=tariff,
),
parse_mode="HTML"
)
@@ -240,12 +274,29 @@ async def confirm_change_devices(
texts = get_texts(db_user.language)
subscription = db_user.subscription
- if not settings.is_devices_selection_enabled():
- await callback.answer(
- texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
- show_alert=True,
- )
- return
+ # Проверяем тариф подписки
+ tariff = None
+ if subscription.tariff_id:
+ from app.database.crud.tariff import get_tariff_by_id
+ tariff = await get_tariff_by_id(db, subscription.tariff_id)
+
+ # Для тарифов - проверяем разрешено ли изменение устройств
+ if tariff:
+ if tariff.device_price_kopeks is None or tariff.device_price_kopeks <= 0:
+ await callback.answer(
+ texts.t("TARIFF_DEVICES_DISABLED", "⚠️ Изменение устройств недоступно для вашего тарифа"),
+ show_alert=True,
+ )
+ return
+ price_per_device = tariff.device_price_kopeks
+ else:
+ if not settings.is_devices_selection_enabled():
+ await callback.answer(
+ texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
+ show_alert=True,
+ )
+ return
+ price_per_device = settings.PRICE_PER_DEVICE
current_devices = subscription.device_limit
@@ -271,13 +322,16 @@ async def confirm_change_devices(
if devices_difference > 0:
additional_devices = devices_difference
- if current_devices < settings.DEFAULT_DEVICE_LIMIT:
+ # Для тарифов - все устройства платные (нет бесплатного лимита)
+ if tariff:
+ chargeable_devices = additional_devices
+ elif current_devices < settings.DEFAULT_DEVICE_LIMIT:
free_devices = settings.DEFAULT_DEVICE_LIMIT - current_devices
chargeable_devices = max(0, additional_devices - free_devices)
else:
chargeable_devices = additional_devices
- devices_price_per_month = chargeable_devices * settings.PRICE_PER_DEVICE
+ devices_price_per_month = chargeable_devices * price_per_device
months_hint = get_remaining_months(subscription.end_date)
period_hint_days = months_hint * 30 if months_hint > 0 else None
devices_discount_percent = _get_addon_discount_percent_for_user(
@@ -937,12 +991,29 @@ async def confirm_add_devices(
texts = get_texts(db_user.language)
subscription = db_user.subscription
- if not settings.is_devices_selection_enabled():
- await callback.answer(
- texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
- show_alert=True,
- )
- return
+ # Проверяем тариф подписки
+ tariff = None
+ if subscription.tariff_id:
+ from app.database.crud.tariff import get_tariff_by_id
+ tariff = await get_tariff_by_id(db, subscription.tariff_id)
+
+ # Для тарифов - проверяем разрешено ли добавление устройств
+ if tariff:
+ if tariff.device_price_kopeks is None or tariff.device_price_kopeks <= 0:
+ await callback.answer(
+ texts.t("TARIFF_DEVICES_DISABLED", "⚠️ Добавление устройств недоступно для вашего тарифа"),
+ show_alert=True,
+ )
+ return
+ price_per_device = tariff.device_price_kopeks
+ else:
+ if not settings.is_devices_selection_enabled():
+ await callback.answer(
+ texts.t("DEVICES_SELECTION_DISABLED", "⚠️ Изменение количества устройств недоступно"),
+ show_alert=True,
+ )
+ return
+ price_per_device = settings.PRICE_PER_DEVICE
resume_callback = None
@@ -956,7 +1027,7 @@ async def confirm_add_devices(
)
return
- devices_price_per_month = devices_count * settings.PRICE_PER_DEVICE
+ devices_price_per_month = devices_count * price_per_device
months_hint = get_remaining_months(subscription.end_date)
period_hint_days = months_hint * 30 if months_hint > 0 else None
devices_discount_percent = _get_addon_discount_percent_for_user(
diff --git a/app/handlers/subscription/purchase.py b/app/handlers/subscription/purchase.py
index d83193f1..fb0f1561 100644
--- a/app/handlers/subscription/purchase.py
+++ b/app/handlers/subscription/purchase.py
@@ -2902,6 +2902,12 @@ async def handle_subscription_settings(
texts = get_texts(db_user.language)
subscription = db_user.subscription
+ # Получаем тариф подписки если есть
+ tariff = None
+ if subscription and subscription.tariff_id:
+ from app.database.crud.tariff import get_tariff_by_id
+ tariff = await get_tariff_by_id(db, subscription.tariff_id)
+
if not subscription or subscription.is_trial:
await callback.answer(
texts.t(
@@ -2957,7 +2963,7 @@ async def handle_subscription_settings(
await callback.message.edit_text(
settings_text,
- reply_markup=get_updated_subscription_settings_keyboard(db_user.language, show_countries),
+ reply_markup=get_updated_subscription_settings_keyboard(db_user.language, show_countries, tariff=tariff),
parse_mode="HTML"
)
await callback.answer()