Skip to content

Commit 26fd68e

Browse files
amickankoopmant
andauthored
Allow changing total amount and payment status simultaneously (#4723)
Closes #4719 --------- Co-authored-by: Thomas Koopman <koopmant@users.noreply.github.com>
1 parent d2a5b29 commit 26fd68e

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

app/grandchallenge/invoices/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ def clean(self):
360360
if (
361361
not self._state.adding
362362
and self.payment_type != PaymentTypeChoices.COMPLIMENTARY
363-
and self.payment_status != PaymentStatusChoices.INITIALIZED
363+
and self.initial_value("payment_status")
364+
!= PaymentStatusChoices.INITIALIZED
364365
):
365366
# Assert total amount unchanged
366367
if (

app/tests/invoices_tests/test_models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@ def test_total_amount_can_change_for_complimentary_invoices():
451451
invoice.clean()
452452

453453

454+
@pytest.mark.parametrize(
455+
"payment_type", (PaymentTypeChoices.PREPAID, PaymentTypeChoices.POSTPAID)
456+
)
457+
@pytest.mark.django_db
458+
def test_updating_total_amount_and_status_simultaneously_is_possible(
459+
payment_type,
460+
):
461+
invoice = InvoiceFactory(
462+
payment_type=payment_type,
463+
payment_status=PaymentStatusChoices.INITIALIZED,
464+
support_costs_euros=0,
465+
compute_costs_euros=1,
466+
storage_costs_euros=2,
467+
)
468+
invoice.support_costs_euros = 2
469+
invoice.payment_status = PaymentStatusChoices.REQUESTED
470+
with nullcontext():
471+
invoice.clean()
472+
473+
454474
@pytest.mark.django_db
455475
def test_invoices_cannot_be_deleted():
456476
invoice = InvoiceFactory()

0 commit comments

Comments
 (0)