Skip to content

Commit

Permalink
🐛(backend) fix order lifecycle issue
Browse files Browse the repository at this point in the history
Currently, it is not possible to transition from `no_payment` state to
`completed` state. But this should be possible to manage orders with a single
installment which was refused and has been fixed.
  • Loading branch information
jbpenrath committed Oct 24, 2024
1 parent 4cc2c94 commit f5a275c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [Unreleased]

### Fixed

- Update order flow to allow transition from `no_payment` to `completed`

## [2.9.1] - 2024-10-23

### Fixed
Expand Down
1 change: 1 addition & 0 deletions src/backend/joanie/core/flows/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def _can_be_state_completed(self):
@state.transition(
source=[
enums.ORDER_STATE_ASSIGNED,
enums.ORDER_STATE_NO_PAYMENT,
enums.ORDER_STATE_PENDING_PAYMENT,
enums.ORDER_STATE_FAILED_PAYMENT,
enums.ORDER_STATE_PENDING,
Expand Down
45 changes: 45 additions & 0 deletions src/backend/joanie/tests/core/test_flows_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,51 @@ def test_flows_order_update_not_free_with_card_with_contract(self):
order.refresh_from_db()
self.assertEqual(order.state, enums.ORDER_STATE_TO_SIGN)

def test_flows_order_update_from_no_payment_to_completed(self):
"""
Test that the order state is set to completed when
the single installment is paid and source state is "no payment".
"""
order = factories.OrderFactory(
state=enums.ORDER_STATE_NO_PAYMENT,
payment_schedule=[
{
"amount": "200.00",
"due_date": "2024-01-17",
"state": enums.PAYMENT_STATE_PAID,
},
],
)

order.flow.update()

self.assertEqual(order.state, enums.ORDER_STATE_COMPLETED)

def test_flows_order_update_from_no_payment_to_pending_payment(self):
"""
Test that the order state is set to pending_payment when
the first installment is paid and source state is "no payment".
"""
order = factories.OrderFactory(
state=enums.ORDER_STATE_NO_PAYMENT,
payment_schedule=[
{
"amount": "200.00",
"due_date": "2024-01-17",
"state": enums.PAYMENT_STATE_PAID,
},
{
"amount": "100.00",
"due_date": "2024-01-18",
"state": enums.PAYMENT_STATE_PENDING,
},
],
)

order.flow.update()

self.assertEqual(order.state, enums.ORDER_STATE_PENDING_PAYMENT)

def test_flows_order_update_free_no_contract(self):
"""
Test that the order state is set to `completed` when the order is free and has no contract.
Expand Down

0 comments on commit f5a275c

Please sign in to comment.