From ebd6bee05ed7d9187de9394c64dfd745bb06b65a Mon Sep 17 00:00:00 2001 From: Fringg Date: Mon, 9 Feb 2026 22:30:26 +0300 Subject: [PATCH] feat: allow tariff deletion with active subscriptions Remove blocking check that prevented tariff deletion when subscriptions exist. DB schema already supports SET NULL on tariff FK, so subscriptions gracefully become "legacy" and users pick a new tariff on renewal. Return affected_subscriptions count in API response. --- app/cabinet/routes/admin_tariffs.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/cabinet/routes/admin_tariffs.py b/app/cabinet/routes/admin_tariffs.py index e6f9afa4..87fdd783 100644 --- a/app/cabinet/routes/admin_tariffs.py +++ b/app/cabinet/routes/admin_tariffs.py @@ -412,21 +412,14 @@ async def delete_existing_tariff( detail='Tariff not found', ) - # Check if tariff has subscriptions subs_count = await get_tariff_subscriptions_count(db, tariff_id) - if subs_count > 0: - raise HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail=f'Cannot delete tariff with {subs_count} active subscriptions', - ) - await delete_tariff(db, tariff) - logger.info(f'Admin {admin.id} deleted tariff {tariff_id}: {tariff.name}') + logger.info(f'Admin {admin.id} deleted tariff {tariff_id}: {tariff.name} (affected subscriptions: {subs_count})') # Перезагружаем периоды из БД для синхронизации с ботом await load_period_prices_from_db(db) - return {'message': 'Tariff deleted successfully'} + return {'message': 'Tariff deleted successfully', 'affected_subscriptions': subs_count} @router.post('/{tariff_id}/toggle', response_model=TariffToggleResponse)