Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/joanie/core/tasks/payment_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def debit_pending_installment(order_id):
installment["id"],
order.id,
)
order.set_installment_error(installment)
order.set_installment_error(installment["id"])
continue


Expand Down
29 changes: 28 additions & 1 deletion src/backend/joanie/tests/core/test_models_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# pylint: disable=too-many-lines,too-many-public-methods
import json
from datetime import datetime, timedelta, timezone
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal
from unittest import mock

Expand Down Expand Up @@ -1391,6 +1391,33 @@ def test_models_order_update_order_with_archived_course_run(self):
self.assertEqual(order.state, enums.ORDER_STATE_COMPLETED)
self.assertEqual(order.payment_schedule[0]["state"], enums.PAYMENT_STATE_PAID)

def test_models_order_set_installment_error_in_payment_schedule(self):
"""
When passing the installment object to `set_installment_error` because of an issue with
the payment provider, we should be able to mark the installment in error state.
We should pass the `installment_id` to the method instead.
"""
order = factories.OrderGeneratorFactory(
state=enums.ORDER_STATE_PENDING,
payment_schedule=[
{
"id": "1932fbc5-d971-48aa-8fee-6d637c3154a5",
"amount": "200.00",
"due_date": date(2025, 10, 6),
"state": PAYMENT_STATE_PENDING,
},
],
)

with self.assertRaises(ValueError):
order.set_installment_error(order.payment_schedule)

order.set_installment_error(order.payment_schedule[0]["id"])

order.refresh_from_db()

self.assertEqual(order.payment_schedule[0]["state"], enums.PAYMENT_STATE_ERROR)

def test_models_order_and_offering_rule_discounted_rate_get_discounted_price(self):
"""
When the offering rule that has a discount rate, is active and is enabled then the order
Expand Down