From 94ddb0424b10ba65e0c8a056a3b438173a101e7b Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Thu, 27 Nov 2025 21:24:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B-=D0=BE?= =?UTF-8?q?=D0=B1=D1=91=D1=80=D1=82=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=88=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE=D0=BC=20=D0=B2=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20Customer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myproject/customers/models.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/myproject/customers/models.py b/myproject/customers/models.py index 8012221..65955a4 100644 --- a/myproject/customers/models.py +++ b/myproject/customers/models.py @@ -216,6 +216,49 @@ class Customer(models.Model): ) return customer, created + # Методы-обёртки для работы с кошельком (вся логика в WalletService) + def pay_from_wallet(self, order, amount, user): + """ + Оплатить заказ из кошелька клиента. + Обёртка над WalletService.pay_with_wallet. + + Args: + order: Заказ для оплаты + amount: Сумма к списанию + user: Пользователь, инициирующий операцию + + Returns: + Decimal: Фактически списанная сумма или None + """ + from customers.services.wallet_service import WalletService + return WalletService.pay_with_wallet(order, amount, user) + + def adjust_wallet(self, amount, description, user): + """ + Корректировка баланса кошелька (для админа). + Обёртка над WalletService.adjust_balance. + + Args: + amount: Сумма корректировки (может быть отрицательной) + description: Обязательное описание причины + user: Пользователь, выполняющий корректировку + + Returns: + WalletTransaction: Созданная транзакция + """ + from customers.services.wallet_service import WalletService + return WalletService.adjust_balance(self.pk, amount, description, user) + + @property + def wallet_transactions_history(self): + """ + История транзакций кошелька клиента. + + Returns: + QuerySet: WalletTransaction для этого клиента + """ + return self.wallet_transactions.all() + class WalletTransaction(models.Model): """