- Добавлено поле wallet_balance в модель Customer - Создана модель WalletTransaction для истории операций - Реализован сервис WalletService с методами: * add_overpayment - автоматическое зачисление переплаты * pay_with_wallet - оплата заказа из кошелька * adjust_balance - ручная корректировка баланса - Интеграция с Payment.save() для автоматической обработки переплат - UI для оплаты из кошелька в деталях заказа - Отображение баланса и долга на странице клиента - Админка с inline транзакций и запретом ручного создания - Добавлен способ оплаты account_balance - Миграция 0004 для customers приложения
74 lines
2.9 KiB
Python
74 lines
2.9 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
Тест системы кошелька клиента
|
||
"""
|
||
import os
|
||
import django
|
||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
|
||
django.setup()
|
||
|
||
from django_tenants.utils import schema_context
|
||
from customers.models import Customer, WalletTransaction
|
||
from orders.models import Order, PaymentMethod
|
||
|
||
print("\n" + "="*60)
|
||
print("ТЕСТ СИСТЕМЫ КОШЕЛЬКА КЛИЕНТА")
|
||
print("="*60)
|
||
|
||
with schema_context('buba'):
|
||
# 1. Проверяем способ оплаты
|
||
try:
|
||
method = PaymentMethod.objects.get(code='account_balance')
|
||
print(f"\n✓ Способ оплаты найден: {method.name}")
|
||
print(f" Описание: {method.description}")
|
||
print(f" Порядок: {method.order}")
|
||
except PaymentMethod.DoesNotExist:
|
||
print("\n✗ Способ оплаты 'account_balance' не найден!")
|
||
|
||
# 2. Проверяем клиентов
|
||
customers = Customer.objects.filter(is_system_customer=False)
|
||
print(f"\n✓ Всего клиентов: {customers.count()}")
|
||
|
||
if customers.exists():
|
||
customer = customers.first()
|
||
print(f"\n Тестовый клиент: {customer.name}")
|
||
print(f" Баланс кошелька: {customer.wallet_balance} руб.")
|
||
print(f" Всего покупок: {customer.total_spent} руб.")
|
||
|
||
# Транзакции
|
||
txn_count = customer.wallet_transactions.count()
|
||
print(f" Транзакций кошелька: {txn_count}")
|
||
|
||
if txn_count > 0:
|
||
print("\n Последние транзакции:")
|
||
for txn in customer.wallet_transactions.all()[:5]:
|
||
print(f" - {txn.created_at.strftime('%d.%m.%Y %H:%M')}: "
|
||
f"{txn.get_transaction_type_display()} "
|
||
f"{txn.amount} руб.")
|
||
|
||
# 3. Проверяем заказы
|
||
orders = Order.objects.all()
|
||
print(f"\n✓ Всего заказов: {orders.count()}")
|
||
|
||
if orders.exists():
|
||
order = orders.first()
|
||
print(f"\n Тестовый заказ: #{order.order_number}")
|
||
print(f" Клиент: {order.customer.name}")
|
||
print(f" Сумма: {order.total_amount} руб.")
|
||
print(f" Оплачено: {order.amount_paid} руб.")
|
||
print(f" К оплате: {order.amount_due} руб.")
|
||
print(f" Статус оплаты: {order.get_payment_status_display()}")
|
||
|
||
# Платежи
|
||
payments = order.payments.all()
|
||
if payments.exists():
|
||
print(f"\n Платежи по заказу:")
|
||
for payment in payments:
|
||
print(f" - {payment.payment_method.name}: {payment.amount} руб.")
|
||
|
||
print("\n" + "="*60)
|
||
print("ТЕСТ ЗАВЕРШЁН")
|
||
print("="*60 + "\n")
|