File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" ]
Original file line number Diff line number Diff line change 1+ from contextlib import nullcontext
2+
13import pytest
24from 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 ()
You can’t perform that action at this time.
0 commit comments