fix: Allow payment saving during new order creation
Fixed PaymentForm.clean() validation that was preventing payments from being saved on new orders. The validation required order to exist, but during creation self.instance.order is None until formset is saved. Changes: - Removed hard requirement for order in PaymentForm.clean() - Wallet balance checks now only run when order exists - Empty payment forms still allowed (for deletion in formset) - Basic amount validation maintained This fixes the issue where payments wouldn't persist when creating a new order, even though no validation errors were shown to user. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -524,12 +524,10 @@ class PaymentForm(forms.ModelForm):
|
||||
# Базовые проверки
|
||||
if amount is None or amount <= 0:
|
||||
self.add_error('amount', 'Введите сумму больше 0.')
|
||||
|
||||
if not order:
|
||||
raise forms.ValidationError('Заказ не найден для платежа.')
|
||||
|
||||
# Проверка для оплаты из кошелька
|
||||
if method and getattr(method, 'code', None) == 'account_balance':
|
||||
|
||||
# ВАЖНО: order может быть None при создании нового заказа!
|
||||
# Проверки кошелька делаем только если order уже существует
|
||||
if order and method and getattr(method, 'code', None) == 'account_balance':
|
||||
wallet_balance = order.customer.wallet_balance if order.customer else Decimal('0')
|
||||
amount_due = max(order.total_amount - order.amount_paid, Decimal('0'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user