From 36ad9a9751c86d67065a8acb95ddec1fcbc8e9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Hol=C3=BD?= Date: Tue, 23 Apr 2024 16:51:47 +0200 Subject: [PATCH] Revert "add check, that confirmed order has at least one confirmed payment" This reverts commit 4457061c We do not need it anymore since the automatic orders returning --- HISTORY.rst | 5 +++++ plans_payments/models.py | 16 +--------------- tests/test_models.py | 24 ------------------------ 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 56625f2..77b877c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ++++++++++++++++++ diff --git a/plans_payments/models.py b/plans_payments/models.py index 599ae57..27a0c5d 100644 --- a/plans_payments/models.py +++ b/plans_payments/models.py @@ -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 @@ -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 diff --git a/tests/test_models.py b/tests/test_models.py index 83c3100..080297e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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()