Добавлена проверка на транзакции кошелька при удалении заказа
Удаление заказа теперь блокируется если есть связанные WalletTransaction (on_delete=PROTECT). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
<a href="{% url 'orders:order-update' order.order_number %}" class="btn btn-primary">
|
||||
<i class="bi bi-pencil"></i> Редактировать
|
||||
</a>
|
||||
{% if order.status and order.status.code == 'draft' and order.amount_paid == 0 %}
|
||||
{% if order.status and order.status.code == 'draft' and order.amount_paid == 0 and not order.wallet_transactions.exists %}
|
||||
<a href="{% url 'orders:order-delete' order.order_number %}" class="btn btn-danger">
|
||||
<i class="bi bi-trash"></i> Удалить
|
||||
</a>
|
||||
|
||||
@@ -434,6 +434,15 @@ def order_delete(request, order_number):
|
||||
)
|
||||
return redirect('orders:order-detail', order_number=order.order_number)
|
||||
|
||||
# Проверка: нельзя удалять заказы с транзакциями кошелька
|
||||
if order.wallet_transactions.exists():
|
||||
messages.error(
|
||||
request,
|
||||
'Удаление невозможно. Заказ имеет транзакции кошелька клиента. '
|
||||
'Сначала удалите связанные транзакции.'
|
||||
)
|
||||
return redirect('orders:order-detail', order_number=order.order_number)
|
||||
|
||||
if request.method == 'POST':
|
||||
order_number_saved = order.order_number
|
||||
order.delete()
|
||||
|
||||
Reference in New Issue
Block a user