Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "add check, that confirmed order has at least one confirmed payment" #11

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading