Skip to content
Open
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
7 changes: 6 additions & 1 deletion common/djangoapps/course_modes/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def _enrollment_mode_display(enrollment_mode, course_id):

def get_course_final_price(user, sku, course_price):
"""
Return the course's discounted price for a user if user is eligible for any otherwise return course original price.
Return the course's discounted price for a user (if eligible), otherwise return course original price.

Note: this function is no longer called directly within edx-platform. It is called externally
via the openedx-filters pipeline, by edx-enterprise's CalculateEnterpriseDiscountedPrice
step (org.openedx.learning.course_mode.price.requested.v1). Do not delete this function even
though static analysis may flag it as unused here.
"""
price_details = {}
try:
Expand Down
7 changes: 4 additions & 3 deletions common/djangoapps/course_modes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_suggested_prices(self, price_list):
# that the right template rendered

@httpretty.activate
@patch('common.djangoapps.course_modes.views.enterprise_customer_for_request')
@patch('common.djangoapps.course_modes.views.CourseModeCheckoutStarted.run_filter')
@patch('common.djangoapps.course_modes.views.get_course_final_price')
@ddt.data(
(1.0, True),
Expand All @@ -198,7 +198,7 @@ def test_display_after_discounted_price(
discounted_price,
is_enterprise_enabled,
mock_get_course_final_price,
mock_enterprise_customer_for_request
mock_run_filter,
):
verified_mode = CourseModeFactory.create(mode_slug='verified', course_id=self.course.id, sku='dummy')
CourseEnrollmentFactory(
Expand All @@ -207,7 +207,8 @@ def test_display_after_discounted_price(
user=self.user
)

mock_enterprise_customer_for_request.return_value = {'name': 'dummy'} if is_enterprise_enabled else {}
enterprise_customer = {'name': 'dummy', 'uuid': 'test-uuid'} if is_enterprise_enabled else None
mock_run_filter.return_value = {'enterprise_customer': enterprise_customer}
mock_get_course_final_price.return_value = discounted_price
Comment thread
kiram15 marked this conversation as resolved.
Comment on lines +210 to 212
url = reverse('course_modes_choose', args=[self.course.id])
response = self.client.get(url)
Expand Down
17 changes: 8 additions & 9 deletions common/djangoapps/course_modes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django.views.generic.base import View
from edx_django_utils.monitoring.utils import increment
from opaque_keys.edx.keys import CourseKey
from openedx_filters.learning.filters import CourseModePriceRequested
from urllib.parse import urljoin # lint-amnesty, pylint: disable=wrong-import-order

from common.djangoapps.course_modes.models import CourseMode
Expand All @@ -39,7 +40,6 @@
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.course_duration_limits.access import get_user_course_duration, get_user_course_expiration_date
from openedx.features.course_experience import course_home_url
from openedx.features.enterprise_support.api import enterprise_customer_for_request
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.util.db import outer_atomic
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -187,15 +187,14 @@ def get(self, request, course_id, error=None): # lint-amnesty, pylint: disable=
if x.strip()
]
price_before_discount = verified_mode.min_price
course_price = price_before_discount
enterprise_customer = enterprise_customer_for_request(request)
LOG.info(
'[e-commerce calculate API] Going to hit the API for user [%s] linked to [%s] enterprise',
request.user.username,
enterprise_customer.get('name') if isinstance(enterprise_customer, dict) else None # Test Purpose
# this filter applies discounts (e.g. enterprise-negotiated pricing) to the price
# .. filter_implemented_name: CourseModePriceRequested
# .. filter_type: org.openedx.learning.course_mode.price.requested.v1
_, _, course_price = CourseModePriceRequested.run_filter(
user=request.user,
course_mode_data=verified_mode,
price=price_before_discount,
)
Comment on lines +190 to 197
if enterprise_customer and verified_mode.sku:
course_price = get_course_final_price(request.user, verified_mode.sku, price_before_discount)

context["currency"] = verified_mode.currency.upper()
context["currency_symbol"] = get_currency_symbol(verified_mode.currency.upper())
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ openedx-events==10.5.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==3.7.0
openedx-filters==3.8.0
# via
# -r requirements/edx/kernel.in
# edx-enterprise
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ openedx-events==10.5.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==3.7.0
openedx-filters==3.8.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ openedx-events==10.5.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==3.7.0
openedx-filters==3.8.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ openedx-events==10.5.0
# edx-name-affirmation
# event-tracking
# ora2
openedx-filters==3.7.0
openedx-filters==3.8.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down
Loading