Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
add check, that confirmed order has at least one confirmed payment
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Dec 8, 2022
1 parent fa1efe2 commit 4457061
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion plans_payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.parse import urljoin

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models
from django.dispatch.dispatcher import receiver
from django.urls import reverse
Expand Down Expand Up @@ -39,6 +39,16 @@ class Payment(BasePayment):
default=False,
)

def clean(self):
confirmed_payment_exists = self.order.payment_set.filter(status=Order.STATUS.COMPLETED).exists()
if self.status != PaymentStatus.CONFIRMED and not confirmed_payment_exists:
raise ValidationError(
{
'status': 'Can\'t leave confirmed order without any confirmed payment.'
'Please change Order first if you still want to perform this change.',
},
)

def save(self, **kwargs):
if 'payu' in self.variant:
# TODO: base this on actual payment methods and currency fees on PayU
Expand Down

0 comments on commit 4457061

Please sign in to comment.