Skip to content

Commit

Permalink
feat: add emeritus course prices
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Jul 15, 2024
1 parent 6227300 commit 552762a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
5 changes: 5 additions & 0 deletions courses/management/commands/sync_external_course_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def handle(self, *args, **options): # noqa: ARG002
f"Course Run courseware_ids: {stats['product_versions_created'] if stats['product_versions_created'] else None}.\n"
)
)
self.stdout.write(
self.style.SUCCESS(
f"Course Runs without prices: {stats['course_runs_without_prices'] if stats['course_runs_without_prices'] else None}.\n"
)
)
self.stdout.write(
self.style.SUCCESS(
f"Number of Courses Pages Created {len(stats['course_pages_created'])}."
Expand Down
37 changes: 26 additions & 11 deletions courses/sync_external_courses/emeritus_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def __init__(self, emeritus_course_json):

self.course_run_code = emeritus_course_json.get("course_run_code")
self.course_run_tag = generate_emeritus_course_run_tag(self.course_run_code)
self.price = float(emeritus_course_json.get("list_price"))
self.price = (
float(emeritus_course_json.get("list_price"))
if emeritus_course_json.get("list_price")
else None
)

self.start_date = strip_datetime(
emeritus_course_json.get("start_date"), EmeritusKeyMap.DATE_FORMAT.value
Expand Down Expand Up @@ -189,6 +193,7 @@ def update_emeritus_course_runs(emeritus_courses): # noqa: C901, PLR0915
"course_runs_expired": set(),
"products_created": set(),
"product_versions_created": set(),
"course_runs_without_prices": set(),
}

for emeritus_course_json in emeritus_courses:
Expand Down Expand Up @@ -258,20 +263,30 @@ def update_emeritus_course_runs(emeritus_courses): # noqa: C901, PLR0915
f"Creating or Updating Product and Product Version, course run courseware_id: {course_run.external_course_run_id}, Price: {emeritus_course.price}" # noqa: G004
)

product_created, product_version_created = (
create_or_update_product_and_product_version(
emeritus_course, course_run
if emeritus_course.price:
product_created, product_version_created = (
create_or_update_product_and_product_version(
emeritus_course, course_run
)
)
)
if product_created:
stats["products_created"].add(course_run.external_course_run_id)
log.info(f"Created Product for course run: {course_run.courseware_id}") # noqa: G004
if product_created:
stats["products_created"].add(course_run.external_course_run_id)
log.info(
f"Created Product for course run: {course_run.courseware_id}" # noqa: G004
)

if product_version_created:
stats["product_versions_created"].add(course_run.external_course_run_id)
if product_version_created:
stats["product_versions_created"].add(
course_run.external_course_run_id
)
log.info(
f"Created Product Version for course run: {course_run.courseware_id}, Price: {emeritus_course.price}" # noqa: G004
)
else:
log.info(
f"Created Product Version for course run: {course_run.courseware_id}, Price: {emeritus_course.price}" # noqa: G004
f"Price is Null for course run code: {emeritus_course.course_run_code}" # noqa: G004
)
stats["course_runs_without_prices"].add(emeritus_course.course_run_code)

log.info(
f"Creating or Updating course page, title: {emeritus_course.course_title}, course_code: {emeritus_course.course_run_code}" # noqa: G004
Expand Down

0 comments on commit 552762a

Please sign in to comment.