Skip to content

Commit

Permalink
Added currency field
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmanann committed Sep 2, 2024
1 parent 30b73a3 commit b0ecbfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ class Meta:
class CourseRunSearchSerializer(HaystackSerializer):
availability = serializers.SerializerMethodField()
first_enrollable_paid_seat_price = serializers.SerializerMethodField()
first_enrollable_paid_seat_currency = serializers.SerializerMethodField()
type = serializers.SerializerMethodField()
is_enrollable = serializers.SerializerMethodField()

Expand All @@ -2216,6 +2217,9 @@ def get_availability(self, result):
def get_first_enrollable_paid_seat_price(self, result):
return result.object.first_enrollable_paid_seat_price

def get_first_enrollable_paid_seat_currency(self, result):
return result.object.first_enrollable_paid_seat_currency

def get_type(self, result):
return result.object.type_legacy

Expand All @@ -2234,6 +2238,7 @@ class Meta:
'enrollment_start',
'first_enrollable_paid_seat_sku',
'first_enrollable_paid_seat_price',
'first_enrollable_paid_seat_currency',
'full_description',
'go_live_date',
'has_enrollable_seats',
Expand Down
11 changes: 11 additions & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,17 @@ def first_enrollable_paid_seat_price(self):

price = int(seats[0].price) if seats[0].price else None
return price

@property
def first_enrollable_paid_seat_currency(self):
"""
Returns currency code for first enrollable paid seat.
"""
seats = sorted(self._enrollable_paid_seats(), key=self._upgrade_deadline_sort)
if not seats:
return None

return seats[0].currency.code or None

def first_enrollable_paid_seat_sku(self):
# Sort in python to avoid an additional request to the database for order_by
Expand Down
4 changes: 4 additions & 0 deletions course_discovery/apps/course_metadata/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable):
has_enrollable_paid_seats = indexes.BooleanField(null=False)
first_enrollable_paid_seat_sku = indexes.CharField(null=True)
first_enrollable_paid_seat_price = indexes.IntegerField(null=True)
first_enrollable_paid_seat_currency = indexes.CharField(null=True)
paid_seat_enrollment_end = indexes.DateTimeField(null=True)
license = indexes.MultiValueField(model_attr='license', faceted=True)
has_enrollable_seats = indexes.BooleanField(model_attr='has_enrollable_seats', null=False)
Expand Down Expand Up @@ -288,6 +289,9 @@ def prepare_first_enrollable_paid_seat_sku(self, obj):
def prepare_first_enrollable_paid_seat_price(self, obj):
return obj.first_enrollable_paid_seat_price

def prepare_first_enrollable_paid_seat_currency(self, obj):
return obj.first_enrollable_paid_seat_currency

def prepare_is_current_and_still_upgradeable(self, obj):
return obj.is_current_and_still_upgradeable()

Expand Down

0 comments on commit b0ecbfc

Please sign in to comment.