diff --git a/myproject/orders/models/payment.py b/myproject/orders/models/payment.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/orders/services/transaction_service.py b/myproject/orders/services/transaction_service.py index 0d4145f..1b2fa32 100644 --- a/myproject/orders/services/transaction_service.py +++ b/myproject/orders/services/transaction_service.py @@ -54,6 +54,13 @@ class TransactionService: except PaymentMethod.DoesNotExist: raise ValueError(f'Способ оплаты "{payment_method}" не найден') + # Ограничение для кошелька: нельзя оплатить больше чем к оплате + if payment_method.code == 'account_balance' and amount > order.amount_due: + raise ValidationError( + f'Сумма оплаты из кошелька ({amount} руб.) не может превышать ' + f'остаток к оплате ({order.amount_due} руб.)' + ) + # Создаём транзакцию txn = Transaction.objects.create( order=order, diff --git a/myproject/orders/templates/orders/order_detail.html b/myproject/orders/templates/orders/order_detail.html index 21fbd5d..c5c6012 100644 --- a/myproject/orders/templates/orders/order_detail.html +++ b/myproject/orders/templates/orders/order_detail.html @@ -358,7 +358,11 @@ {{ transaction.transaction_date|date:"d.m.Y H:i" }}
- {{ transaction.payment_method.name }} + {% if transaction.transaction_type == 'refund' and transaction.payment_method.code == 'account_balance' %} + Возврат на баланс счёта + {% else %} + {{ transaction.payment_method.name }} + {% endif %} {% if transaction.notes or transaction.reason %}
{{ transaction.notes|default:transaction.reason }} {% endif %} diff --git a/myproject/orders/templates/orders/order_form.html b/myproject/orders/templates/orders/order_form.html index bdb5619..b98e282 100644 --- a/myproject/orders/templates/orders/order_form.html +++ b/myproject/orders/templates/orders/order_form.html @@ -671,7 +671,13 @@ {{ transaction.transaction_date|date:"d.m.Y H:i" }}
- {{ transaction.payment_method.name }} + + {% if transaction.transaction_type == 'refund' and transaction.payment_method.code == 'account_balance' %} + Возврат на баланс счёта + {% else %} + {{ transaction.payment_method.name }} + {% endif %} + {% if transaction.transaction_type == 'refund' %}−{% else %}+{% endif %}{{ transaction.amount|floatformat:2 }} @@ -727,12 +733,12 @@
- {% load orders_tags %} {% get_payment_methods as payment_methods %} {% for pm in payment_methods %} - + {% endfor %}
@@ -740,10 +746,11 @@
0 %}value="{{ order.amount_due|unlocalize }}"{% endif %} required> руб.
+
@@ -887,6 +894,36 @@ document.addEventListener('DOMContentLoaded', function() { }); + +