fix: prevent 500 error when course mode currency is not the same as the one configured in settings (#31312)
This commit solves the http 500 error when course concurrency is setted different for PAID_COURSE_REGISTRATION_CURRENCY and course modes.
This commit is contained in:
@@ -774,7 +774,10 @@ class CourseMode(models.Model):
|
||||
If there is no mode found, will return the price of DEFAULT_MODE, which is 0
|
||||
"""
|
||||
modes = cls.modes_for_course(course_id)
|
||||
return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower())
|
||||
return min(
|
||||
(mode.min_price for mode in modes if mode.currency.lower() == currency.lower()),
|
||||
default=0
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_eligible_for_certificate(cls, mode_slug, status=None):
|
||||
|
||||
@@ -125,6 +125,11 @@ class CourseModeModelTest(TestCase):
|
||||
# no modes, should get 0
|
||||
assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd')
|
||||
|
||||
# with mode with other currency, should get 0
|
||||
mode = Mode('audit', 'Audit', 30, '', 'eur', None, None, None, None)
|
||||
self.create_mode(mode.slug, mode.name, mode.min_price, mode.suggested_prices, mode.currency)
|
||||
assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd')
|
||||
|
||||
# create some modes
|
||||
mode1 = Mode('honor', 'Honor Code Certificate', 10, '', 'usd', None, None, None, None)
|
||||
mode2 = Mode('verified', 'Verified Certificate', 20, '', 'usd', None, None, None, None)
|
||||
|
||||
Reference in New Issue
Block a user