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:
Henrry Pulgarin
2022-11-30 09:50:48 -05:00
committed by GitHub
parent 929d4b97d2
commit 93fd8cc148
2 changed files with 9 additions and 1 deletions

View File

@@ -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):

View File

@@ -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)