Skip to content

Commit 733ad88

Browse files
authored
feat: add fixed usd pricing course run level (#4392)
1 parent cc6e734 commit 733ad88

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.14 on 2024-07-26 11:00
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('course_metadata', '0343_alter_program_taxi_form'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='courserun',
15+
name='fixed_price_usd',
16+
field=models.DecimalField(blank=True, decimal_places=2, help_text='The fixed USD price for course runs to minimize the impact of currency fluctuations.', max_digits=10, null=True),
17+
),
18+
migrations.AddField(
19+
model_name='historicalcourserun',
20+
name='fixed_price_usd',
21+
field=models.DecimalField(blank=True, decimal_places=2, help_text='The fixed USD price for course runs to minimize the impact of currency fluctuations.', max_digits=10, null=True),
22+
),
23+
]

course_discovery/apps/course_metadata/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,11 @@ class CourseRun(ManageHistoryMixin, DraftModelMixin, CachedMixin, TimeStampedMod
21122112
(False, _('Unrestricted')),
21132113
)
21142114

2115+
PRICE_FIELD_CONFIG = {
2116+
'decimal_places': 2,
2117+
'max_digits': 10,
2118+
}
2119+
21152120
IN_REVIEW_STATUS = [CourseRunStatus.InternalReview, CourseRunStatus.LegalReview]
21162121
POST_REVIEW_STATUS = [CourseRunStatus.Reviewed, CourseRunStatus.Published]
21172122

@@ -2230,6 +2235,11 @@ class CourseRun(ManageHistoryMixin, DraftModelMixin, CachedMixin, TimeStampedMod
22302235
)
22312236
)
22322237

2238+
fixed_price_usd = models.DecimalField(
2239+
**PRICE_FIELD_CONFIG, null=True, blank=True, editable=True,
2240+
help_text=('The fixed USD price for course runs to minimize the impact of currency fluctuations.')
2241+
)
2242+
22332243
STATUS_CHANGE_EXEMPT_FIELDS = [
22342244
'start',
22352245
'end',

course_discovery/apps/course_metadata/tests/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ class CourseRunFactory(SalesforceRecordFactory):
481481
enterprise_subscription_inclusion = False
482482
type = factory.SubFactory(CourseRunTypeFactory)
483483
variant_id = factory.LazyFunction(uuid4)
484+
fixed_price_usd = FuzzyDecimal(0.0, 650.0)
484485

485486
@factory.post_generation
486487
def staff(self, create, extracted, **kwargs):

course_discovery/apps/course_metadata/tests/test_models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,30 @@ def test_str(self):
942942
course_run = self.course_run
943943
assert str(course_run) == f'{course_run.key}: {course_run.title}'
944944

945+
def test_course_run_fixed_usd_price(self):
946+
"""
947+
Verify that the course_run_fixed_usd_price attribute returns the correct fixed usd price for the course run.
948+
"""
949+
ee_course_type = factories.CourseRunTypeFactory(slug=CourseRunType.UNPAID_EXECUTIVE_EDUCATION)
950+
951+
ee_course_run = factories.CourseRunFactory(
952+
type=ee_course_type,
953+
course=CourseFactory(additional_metadata=AdditionalMetadataFactory()),
954+
fixed_price_usd=100
955+
)
956+
assert ee_course_run.fixed_price_usd == 100
957+
958+
ee_course_run = factories.CourseRunFactory(
959+
type=ee_course_type,
960+
course=CourseFactory(additional_metadata=AdditionalMetadataFactory()),
961+
)
962+
assert ee_course_run.fixed_price_usd >= 0
963+
964+
course_run = factories.CourseRunFactory(
965+
fixed_price_usd=None
966+
)
967+
assert course_run.fixed_price_usd is None
968+
945969
@ddt.data('full_description_override', 'outcome_override', 'short_description_override')
946970
def test_html_fields_are_validated(self, field_name):
947971
# Happy path

0 commit comments

Comments
 (0)