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

feat: convert CEUs to decimal #3217

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

asadali145
Copy link
Contributor

@asadali145 asadali145 commented Nov 4, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5834

Description (What does it do?)

Converts CEUs from string to decimal to avoid issues.

How can this be tested?

  • Checkout master branch and create the data
  • Create a few certificate pages for program and course pages. Add CEUs, Keep a few CEUs empty, and override a couple.
  • Create multiple course runs and program certificates.
  • Now checkout this branch and apply the migration
  • Test the following:
    • CEUs are visible on the product page if the certificate.CEUs exist, but are not visible if only override exists without the certificate.CEUs
    • CEUs are visible in the certificate preview if the certificate.CEUs, not visible if only override
    • CEUs are visible in the certificates if CEUs exist or Override is visible when CEUs exist.
    • Credits are correct in api/courses, should be null or decimal
    • Credits are correct in api/programs, should be null or decimal for each course and null or decimal for the program itself
    • CEUs are visible in the dashboard receipt.
    • I am not sure about the usage of build_course_run_credential and build_program_credential, But we should verify that CEUs are returned in the data. I verified it through shell
  • Verify that nothing changes display-wise and no breaking changes.

@odlbot odlbot temporarily deployed to xpro-ci-pr-3217 November 4, 2024 11:19 Inactive
@odlbot odlbot temporarily deployed to xpro-ci-pr-3217 November 5, 2024 11:53 Inactive
@odlbot odlbot temporarily deployed to xpro-ci-pr-3217 November 5, 2024 12:26 Inactive
@odlbot odlbot temporarily deployed to xpro-ci-pr-3217 November 5, 2024 13:16 Inactive
@odlbot odlbot temporarily deployed to xpro-ci-pr-3217 November 5, 2024 14:41 Inactive
@asadali145 asadali145 force-pushed the asad/convert-ceus-to-decimal branch 2 times, most recently from 638451b to 85b997f Compare November 14, 2024 11:40
@asadali145 asadali145 marked this pull request as ready for review November 14, 2024 12:04
@arslanashraf7 arslanashraf7 self-assigned this Nov 14, 2024
@asadali145 asadali145 force-pushed the asad/convert-ceus-to-decimal branch from 85b997f to ef3d652 Compare November 22, 2024 13:26
@arslanashraf7
Copy link
Contributor

@asadali145 could you rebase this PR?

@asadali145 asadali145 force-pushed the asad/convert-ceus-to-decimal branch from ef3d652 to 5eabdca Compare November 28, 2024 13:11
@asadali145
Copy link
Contributor Author

@asadali145 could you rebase this PR?

@arslanashraf7 Done!

Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of changes.

cms/models.py Outdated
Comment on lines 1077 to 1111
"ceus": self.certificate_page.normalized_ceus
if self.certificate_page
else None,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Keeping the same format of how we are using other properties, we might just want to move the if/else inside the normalized_ceus method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalized_ceus is a property of CertificatePage and this usage is in ProductPage. We cannot check this in normalized_ceus.

cms/models.py Outdated
"""
Normalizes the CEUs from decimal to string. Removes the trailing zeros if any.
"""
return f"{self.CEUs.normalize():f}" if self.CEUs else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a simple str() conversion be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str does not remove trailing zeros, This property is mostly used for display purposes, so, we don't need trailing zeros. That is why I used normalize.

Copy link
Contributor

@arslanashraf7 arslanashraf7 Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted this because there are many courses in production that have .0 format at least. You can find them in /api/courses and search for credits. I don't know if the consumers of the APIs can break if they don't find .0s that's why I wanted to make sure that we keep the exact same format for the APIs to keep the external consumers from breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed with Matt that this is OKay with MIT Learn. I will confirm with Bon today.

cms/models.py Outdated
Comment on lines 2150 to 2189
decimal_places=2,
max_digits=5,
help_text="Optional field for CEU (continuing education unit).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows -ve values too. We will need to add validators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 85b1c00

@@ -120,7 +121,7 @@ def __init__(self, emeritus_course_json):
self.format = emeritus_course_json.get("format")
self.category = emeritus_course_json.get("Category", None)
self.image_name = emeritus_course_json.get("image_name", None)
self.CEUs = str(emeritus_course_json.get("ceu") or "")
self.CEUs = Decimal(str(emeritus_course_json.get("ceu"))) or None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on null CEU values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 85b1c00

@asadali145 asadali145 force-pushed the asad/convert-ceus-to-decimal branch from 4f7601c to 85b1c00 Compare December 2, 2024 08:02
Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Just some thoughts and one small change.

cms/models.py Outdated
help_text="Optional text field for CEU (continuing education unit).",
decimal_places=2,
max_digits=5,
validators=[MinValueValidator(Decimal("0.01"))],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be zero otherwise it will never allow them to make CEUs Zero if needed in future revisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f005f49

Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

review changes
revert unintended change

recreate migration
@asadali145 asadali145 force-pushed the asad/convert-ceus-to-decimal branch from 80d44eb to 88ce0dd Compare January 3, 2025 11:17
@asadali145
Copy link
Contributor Author

@arslanashraf7 This should be good to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants