Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rollback hiding course price when zero feature #21

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
1 change: 0 additions & 1 deletion enterprise/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ class Meta:
"enable_audit_data_reporting",
"replace_sensitive_sso_username",
"hide_course_original_price",
"hide_course_price_when_zero",
"allow_enrollment_in_invite_only_courses",
"enable_portal_code_management_screen",
"enable_portal_subscription_management_screen",
Expand Down
21 changes: 21 additions & 0 deletions enterprise/migrations/0173_remove_hide_price_when_zero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.21 on 2024-12-02 06:52

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0172_adds_allow_enrollment_in_invite_only_courses_flag'),
]

operations = [
migrations.RemoveField(
model_name='enterprisecustomer',
name='hide_course_price_when_zero',
),
migrations.RemoveField(
model_name='historicalenterprisecustomer',
name='hide_course_price_when_zero',
),
]
5 changes: 0 additions & 5 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,6 @@ class Meta:
help_text=_("The email address where learner's reply to enterprise emails will be delivered.")
)

hide_course_price_when_zero = models.BooleanField(
default=False,
help_text=_("Specify whether course cost should be hidden in the landing page when the final price is zero.")
)

allow_enrollment_in_invite_only_courses = models.BooleanField(
default=False,
help_text=_(
Expand Down
25 changes: 0 additions & 25 deletions enterprise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,31 +2312,6 @@ def logo_path(instance, filename):
return fullname


def hide_price_when_zero(enterprise_customer, course_modes):
"""
Adds a "hide_price" flag to the course modes if price is zero and "Hide course price when zero" flag is set.

Arguments:
enterprise_customer: The EnterpriseCustomer that the enrollemnt is being done.
course_modes: iterable with dictionaries containing a required 'final_price' key
"""
if not enterprise_customer.hide_course_price_when_zero:
return course_modes

for mode in course_modes:
mode['hide_price'] = False
try:
numbers = re.findall(r'\d+', mode['final_price'])
mode['hide_price'] = int(''.join(numbers)) == 0
except ValueError:
LOGGER.warning(
'hide_price_when_zero: Could not convert price "%s" of course mode "%s" to int.',
mode['final_price'],
mode['title']
)
return course_modes


def ensure_course_enrollment_is_allowed(course_id, email, enrollment_api_client):
"""
Calls the enrollment API to create a CourseEnrollmentAllowed object for
Expand Down
4 changes: 0 additions & 4 deletions enterprise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
get_enterprise_customer_user,
get_platform_logo_url,
get_program_type_description,
hide_price_when_zero,
is_course_run_enrollable,
localized_utcnow,
track_enrollment,
Expand Down Expand Up @@ -1553,9 +1552,6 @@ def get_enterprise_course_enrollment_page(
# Filter audit course modes.
course_modes = filter_audit_course_modes(enterprise_customer, course_modes)

# Set a flag to hide the $0 when the customer doesn't want it to be shown
course_modes = hide_price_when_zero(enterprise_customer, course_modes)

# Allows automatic assignment to a cohort upon enrollment.
cohort = request.GET.get('cohort')
# Add a message to the message display queue if the learner
Expand Down
28 changes: 0 additions & 28 deletions tests/test_enterprise/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
ensure_course_enrollment_is_allowed,
get_idiff_list,
get_platform_logo_url,
hide_price_when_zero,
is_pending_user,
parse_lms_api_datetime,
serialize_notification_content,
Expand Down Expand Up @@ -495,33 +494,6 @@ def expected_email_item(user, activation_links):
expected_email_items = [expected_email_item(user, activation_links) for user in users]
assert email_items == expected_email_items

@ddt.data(True, False)
def test_hide_course_price_when_zero(self, hide_price):
customer = factories.EnterpriseCustomerFactory()
zero_modes = [
{"final_price": "$0"},
{"final_price": "$0.000"},
{"final_price": "Rs. 0.00"},
{"final_price": "0.00 EURO"},
]
non_zero_modes = [
{"final_price": "$100"},
{"final_price": "$73.50"},
{"final_price": "Rs.8000.00"},
{"final_price": "4000 Euros"},
]
customer.hide_course_price_when_zero = hide_price

processed_zero_modes = hide_price_when_zero(customer, zero_modes)
processed_non_zero_modes = hide_price_when_zero(customer, non_zero_modes)

if hide_price:
self.assertTrue(all(mode["hide_price"] for mode in processed_zero_modes))
self.assertFalse(all(mode["hide_price"] for mode in processed_non_zero_modes))
else:
self.assertEqual(zero_modes, processed_zero_modes)
self.assertEqual(non_zero_modes, processed_non_zero_modes)

@ddt.data(True, False)
def test_ensure_course_enrollment_is_allowed(self, invite_only):
"""
Expand Down
1 change: 0 additions & 1 deletion tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def setUp(self):
"system_wide_role_assignments",
"reply_to",
"hide_labor_market_data",
"hide_course_price_when_zero",
]
),
(
Expand Down
Loading