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): """