Repository: svthalia/concrexit

Issue:
Setting payment to 'none' in events admin does not work
### Describe the bug
Setting payment to 'none' in events admin does not work

### How to reproduce
Steps to reproduce the behaviour:
0. Make sure your user is superuser
1. Create an event with registrations
2. Register a payment for an event registration
3. Try to remove the payment again
4. You are not authorized!

### Expected behaviour
It should show an more informative error message



Discussion:
Cannot reproduce this specific error. It is true that you cannot remove payments when the `PAYMENT_CHANGE_WINDOW` has passed but that is intended behavior right?
Aaah I forgot we introduced that. But then we should clarify that in the error. I was so confused why the payment could not be changed anymore even though the event has not even been yet.

Resolving patch:
diff --git a/website/events/models/event.py b/website/events/models/event.py
--- a/website/events/models/event.py
+++ b/website/events/models/event.py
@@ -195,6 +195,10 @@ def registration_started(self):
     def registration_required(self):
         return bool(self.registration_start) or bool(self.registration_end)
 
+    @property
+    def payment_required(self):
+        return self.price != 0
+
     def has_fields(self):
         return self.registrationinformationfield_set.count() > 0
 
diff --git a/website/payments/services.py b/website/payments/services.py
--- a/website/payments/services.py
+++ b/website/payments/services.py
@@ -66,9 +66,11 @@ def delete_payment(payable: Payable):
     if payment.created_at < timezone.now() - timezone.timedelta(
         seconds=settings.PAYMENT_CHANGE_WINDOW
     ):
-        raise PaymentError(_("You are not authorized to delete this payment."))
+        raise PaymentError(_("This payment cannot be deleted anymore."))
     if payment.batch and payment.batch.processed:
-        raise PaymentError(_("This payment has already been processed."))
+        raise PaymentError(
+            _("This payment has already been processed and hence cannot be deleted.")
+        )
 
     payable.payment = None
     payable.save()


Test patch:
diff --git a/website/payments/tests/test_services.py b/website/payments/tests/test_services.py
--- a/website/payments/tests/test_services.py
+++ b/website/payments/tests/test_services.py
@@ -70,7 +70,7 @@ def test_delete_payment(self):
                 seconds=settings.PAYMENT_CHANGE_WINDOW + 60
             )
             with self.assertRaisesMessage(
-                PaymentError, "You are not authorized to delete this payment."
+                PaymentError, "This payment cannot be deleted anymore."
             ):
                 services.delete_payment(payable)
             self.assertIsNotNone(payable.payment)
@@ -81,7 +81,8 @@ def test_delete_payment(self):
             payable.payment = existing_payment
             existing_payment.batch = Batch.objects.create(processed=True)
             with self.assertRaisesMessage(
-                PaymentError, "This payment has already been processed."
+                PaymentError,
+                "This payment has already been processed and hence cannot be deleted.",
             ):
                 services.delete_payment(payable)
             self.assertIsNotNone(payable.payment)