From a97fc39a2c21159ed924710145051b49eabba2cb Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Sat, 29 Nov 2025 01:49:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3:=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=87=D0=B5=D1=80=D0=BD=D0=BE=D0=B2=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B8=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Убран черновик как отдельная сущность с процессом финализации - Черновик теперь просто обычный OrderStatus - Удалены кнопки 'Сохранить как черновик' и 'Финализировать черновик' - Унифицирована логика сохранения/обновления заказов для всех статусов Улучшения шаблонов: - Стандартизировано форматирование валюты через floatformat:2 - Исправлено отображение статуса (используется OrderStatus.label и color) - Исправлено отображение способа оплаты (корректное использование ForeignKey) - Добавлены иконки к заголовкам секций для лучшего UX - Удалены избыточные console.log (~160 строк) - Очищены комментарии и улучшена читаемость кода - Убрано использование переменной is_draft в контексте - Добавлена визуальная согласованность между шаблонами заказов --- .../customers/services/wallet_service.py | 40 ++ .../orders/templates/orders/order_detail.html | 55 ++- .../orders/templates/orders/order_form.html | 355 ++++++------------ myproject/orders/views.py | 161 +++----- 4 files changed, 228 insertions(+), 383 deletions(-) diff --git a/myproject/customers/services/wallet_service.py b/myproject/customers/services/wallet_service.py index 21b4d56..8b94c04 100644 --- a/myproject/customers/services/wallet_service.py +++ b/myproject/customers/services/wallet_service.py @@ -139,6 +139,46 @@ class WalletService: return usable_amount + @staticmethod + @transaction.atomic + def refund_wallet_payment(order, amount, user): + """ + Возврат средств в кошелёк при удалении платежа. + Увеличивает баланс кошелька и создаёт транзакцию deposit. + + Args: + order: Заказ, по которому был платёж + amount: Сумма возврата + user: Пользователь, инициировавший возврат + + Returns: + Decimal: Возвращённая сумма + """ + from customers.models import Customer, WalletTransaction + + amount = _quantize(amount) + if amount <= 0: + return None + + # Блокируем запись клиента + customer = Customer.objects.select_for_update().get(pk=order.customer_id) + + # Увеличиваем баланс + customer.wallet_balance = _quantize(customer.wallet_balance + amount) + customer.save(update_fields=['wallet_balance']) + + # Создаём транзакцию возврата + WalletTransaction.objects.create( + customer=customer, + amount=amount, + transaction_type='deposit', + order=order, + description=f'Возврат платежа по заказу #{order.order_number}', + created_by=user + ) + + return amount + @staticmethod @transaction.atomic def adjust_balance(customer_id, amount, description, user): diff --git a/myproject/orders/templates/orders/order_detail.html b/myproject/orders/templates/orders/order_detail.html index 051f030..460d4da 100644 --- a/myproject/orders/templates/orders/order_detail.html +++ b/myproject/orders/templates/orders/order_detail.html @@ -45,18 +45,12 @@
Статус:
- {% if order.status == 'new' %} - Новый - {% elif order.status == 'confirmed' %} - Подтвержден - {% elif order.status == 'in_assembly' %} - В сборке - {% elif order.status == 'in_delivery' %} - В доставке - {% elif order.status == 'delivered' %} - Доставлен - {% elif order.status == 'cancelled' %} - Отменен + {% if order.status %} + + {{ order.status.label|default:order.status.name }} + + {% else %} + Не установлен {% endif %}
@@ -126,7 +120,7 @@
Стоимость доставки:
-
{{ order.delivery_cost }} руб.
+
{{ order.delivery_cost|floatformat:2 }} руб.
{% else %}
@@ -207,25 +201,25 @@ {% endif %} - {{ item.quantity }} + {{ item.quantity }} шт. - {{ item.price }} руб. + {{ item.price|floatformat:2 }} руб. {% if item.is_custom_price %} Изменена
- Оригинальная: {{ item.original_price }} руб. + Оригинальная: {{ item.original_price|floatformat:2 }} руб. {% if item.price_difference %} {% if item.price_difference > 0 %} - (+{{ item.price_difference }} руб.) + (+{{ item.price_difference|floatformat:2 }} руб.) {% else %} - ({{ item.price_difference }} руб.) + ({{ item.price_difference|floatformat:2 }} руб.) {% endif %} {% endif %} {% endif %} - {{ item.get_total_price }} руб. + {{ item.get_total_price|floatformat:2 }} руб. {% endfor %} @@ -315,27 +309,27 @@ {% if order.is_delivery %}
Доставка:
-
{{ order.delivery_cost }} руб.
+
{{ order.delivery_cost|floatformat:2 }} руб.
{% endif %} {% if order.discount_amount > 0 %}
Скидка:
-
-{{ order.discount_amount }} руб.
+
-{{ order.discount_amount|floatformat:2 }} руб.
{% endif %}
Итого:
-
{{ order.total_amount }} руб.
+
{{ order.total_amount|floatformat:2 }} руб.
Оплачено:
-
{{ order.amount_paid }} руб.
+
{{ order.amount_paid|floatformat:2 }} руб.
К оплате:
-
{{ order.amount_due }} руб.
+
{{ order.amount_due|floatformat:2 }} руб.
@@ -349,12 +343,6 @@ {% endif %}
-
-
- Способ оплаты:
- {{ order.get_payment_method_display }} -
-
@@ -368,10 +356,13 @@