Skip to content

Commit

Permalink
Revert "add check, that confirmed order has at least one confirmed pa…
Browse files Browse the repository at this point in the history
…yment"

This reverts commit 4457061

We do not need it anymore since the automatic orders returning
  • Loading branch information
radekholy24 authored and PetrDlouhy committed Apr 24, 2024
1 parent 905b662 commit 07a2941
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,11 @@
History
-------

1.4.1 (Unreleased)
++++++++++++++++++

* do not check whether a confirmed payment of a completed order is left anymore

1.4.0 (2024-04-15)
++++++++++++++++++

Expand Down
16 changes: 1 addition & 15 deletions plans_payments/models.py
Expand Up @@ -5,7 +5,7 @@
from urllib.parse import urljoin

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.dispatch.dispatcher import receiver
from django.urls import reverse
Expand Down Expand Up @@ -45,20 +45,6 @@ class Meta:
models.Index(fields=["status", "transaction_id"]),
]

def clean(self):
if self.order.status == Order.STATUS.COMPLETED:
confirmed_payment_count = self.order.payment_set.exclude(pk=self.pk)
confirmed_payment_count = confirmed_payment_count.filter(
status=PaymentStatus.CONFIRMED
).count()
if self.status != PaymentStatus.CONFIRMED and confirmed_payment_count == 0:
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
24 changes: 0 additions & 24 deletions tests/test_models.py
Expand Up @@ -26,30 +26,6 @@ class TestPlansPayments(TestCase):
def setUp(self):
pass

def test_clean(self):
p = models.Payment(order=baker.make("Order", status=Order.STATUS.NEW))
p.clean()
self.assertEqual(p.status, "waiting")

def test_clean_completed(self):
p = models.Payment(
order=baker.make("Order", status=Order.STATUS.COMPLETED),
status=PaymentStatus.CONFIRMED,
)
p.clean()
self.assertEqual(p.status, "confirmed")

def test_clean_completed_no_confirmed_payment(self):
p = models.Payment(
order=baker.make("Order", status=Order.STATUS.COMPLETED),
status=PaymentStatus.WAITING,
)
with self.assertRaisesRegex(
Exception, "Can't leave confirmed order without any confirmed payment."
):
p.clean()
self.assertEqual(p.status, "waiting")

def test_save(self):
p = models.Payment(transaction_fee=1)
p.save()
Expand Down

0 comments on commit 07a2941

Please sign in to comment.