Skip to content

Commit

Permalink
feat: add fixed usd pricing course run level (#4392)
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 authored Jul 29, 2024
1 parent cc6e734 commit 733ad88
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.14 on 2024-07-26 11:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('course_metadata', '0343_alter_program_taxi_form'),
]

operations = [
migrations.AddField(
model_name='courserun',
name='fixed_price_usd',
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),
),
migrations.AddField(
model_name='historicalcourserun',
name='fixed_price_usd',
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),
),
]
10 changes: 10 additions & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,11 @@ class CourseRun(ManageHistoryMixin, DraftModelMixin, CachedMixin, TimeStampedMod
(False, _('Unrestricted')),
)

PRICE_FIELD_CONFIG = {
'decimal_places': 2,
'max_digits': 10,
}

IN_REVIEW_STATUS = [CourseRunStatus.InternalReview, CourseRunStatus.LegalReview]
POST_REVIEW_STATUS = [CourseRunStatus.Reviewed, CourseRunStatus.Published]

Expand Down Expand Up @@ -2230,6 +2235,11 @@ class CourseRun(ManageHistoryMixin, DraftModelMixin, CachedMixin, TimeStampedMod
)
)

fixed_price_usd = models.DecimalField(
**PRICE_FIELD_CONFIG, null=True, blank=True, editable=True,
help_text=('The fixed USD price for course runs to minimize the impact of currency fluctuations.')
)

STATUS_CHANGE_EXEMPT_FIELDS = [
'start',
'end',
Expand Down
1 change: 1 addition & 0 deletions course_discovery/apps/course_metadata/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ class CourseRunFactory(SalesforceRecordFactory):
enterprise_subscription_inclusion = False
type = factory.SubFactory(CourseRunTypeFactory)
variant_id = factory.LazyFunction(uuid4)
fixed_price_usd = FuzzyDecimal(0.0, 650.0)

@factory.post_generation
def staff(self, create, extracted, **kwargs):
Expand Down
24 changes: 24 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,30 @@ def test_str(self):
course_run = self.course_run
assert str(course_run) == f'{course_run.key}: {course_run.title}'

def test_course_run_fixed_usd_price(self):
"""
Verify that the course_run_fixed_usd_price attribute returns the correct fixed usd price for the course run.
"""
ee_course_type = factories.CourseRunTypeFactory(slug=CourseRunType.UNPAID_EXECUTIVE_EDUCATION)

ee_course_run = factories.CourseRunFactory(
type=ee_course_type,
course=CourseFactory(additional_metadata=AdditionalMetadataFactory()),
fixed_price_usd=100
)
assert ee_course_run.fixed_price_usd == 100

ee_course_run = factories.CourseRunFactory(
type=ee_course_type,
course=CourseFactory(additional_metadata=AdditionalMetadataFactory()),
)
assert ee_course_run.fixed_price_usd >= 0

course_run = factories.CourseRunFactory(
fixed_price_usd=None
)
assert course_run.fixed_price_usd is None

@ddt.data('full_description_override', 'outcome_override', 'short_description_override')
def test_html_fields_are_validated(self, field_name):
# Happy path
Expand Down

0 comments on commit 733ad88

Please sign in to comment.