Skip to content

Commit 0575897

Browse files
committed
Allow changing invoice total when payment status is initialized
1 parent a124c0b commit 0575897

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

app/grandchallenge/invoices/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ def _current_state(self):
263263
return state
264264

265265
def clean(self):
266-
if not self._state.adding:
266+
if (
267+
not self._state.adding
268+
and self.payment_status != PaymentStatusChoices.INITIALIZED
269+
):
267270
# Assert total amount unchanged
268271
if (
269272
self._current_state["total_amount_euros"]

app/tests/invoices_tests/test_models.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from contextlib import nullcontext
2+
13
import pytest
24
from django.core.exceptions import ValidationError
35

@@ -392,17 +394,36 @@ def test_payment_type_non_complimentary_requires_details(
392394
assert expected_error_message == e.value.messages[0]
393395

394396

397+
@pytest.mark.parametrize(
398+
"payment_status",
399+
set(PaymentStatusChoices).difference([PaymentStatusChoices.INITIALIZED]),
400+
)
395401
@pytest.mark.django_db
396-
def test_total_amount_cannot_change():
402+
def test_total_amount_cannot_change(payment_status):
397403
invoice = InvoiceFactory(
404+
payment_status=payment_status,
398405
support_costs_euros=0,
399406
compute_costs_euros=1,
400407
storage_costs_euros=2,
401408
)
402409
invoice.support_costs_euros = 1
403410
with pytest.raises(ValidationError) as e:
404411
invoice.clean()
405-
assert ("The total amount may not change") in e.value.message
412+
assert "The total amount may not change" in e.value.message
406413

407414
invoice.storage_costs_euros = 1
408-
invoice.clean()
415+
with nullcontext():
416+
invoice.clean()
417+
418+
419+
@pytest.mark.django_db
420+
def test_total_amount_can_change_for_initialized_payment_status():
421+
invoice = InvoiceFactory(
422+
payment_status=PaymentStatusChoices.INITIALIZED,
423+
support_costs_euros=0,
424+
compute_costs_euros=1,
425+
storage_costs_euros=2,
426+
)
427+
invoice.support_costs_euros = 1
428+
with nullcontext():
429+
invoice.clean()

0 commit comments

Comments
 (0)