Skip to content

Orders: Add a tracking table for course run purchases #738

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

Closed
3 tasks done
rhysyngsun opened this issue Jul 25, 2022 · 1 comment · Fixed by #745
Closed
3 tasks done

Orders: Add a tracking table for course run purchases #738

rhysyngsun opened this issue Jul 25, 2022 · 1 comment · Fixed by #745
Assignees
Milestone

Comments

@rhysyngsun
Copy link
Collaborator

rhysyngsun commented Jul 25, 2022

We need to be able to have a simpler way of determining which runs a learner has purchased. Currently you have to go through User -> Order -> Line -> Product -> CourseRun, which makes querying inefficient and messy.

I've proposed a join table that would track information on what course runs have been paid for, something like this:

class PaidCourseRun(TimestampedModel):
    user = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name="paid_course_runs"
    )
    course_run = models.ForeignKey(
        CourseRun, on_delete=models.CASCADE, related_name="paid_course_runs"
    )
    order = models.ForeignKey(
        Order, on_delete=models.CASCADE, related_name="paid_course_runs"
    )

This would simplify the joins down to User -> PaidCourseRun -> CourseRun.

We would only create these for orders in the FULFILLED or REVIEW state and keep the records in the event of a refund.

Tasks

  • Add a model similar to the above psuedocode
  • Where we currently mark an order as fulfilled or in review state, add code to create and/or update a record
  • In a PR that is merged and deployed after the above logic change is deployed add a migration that backpopulates records for existing orders
@dseaton
Copy link

dseaton commented Aug 4, 2022

@rhysyngsun @rachellougee I have confirmed that this works for me. Thank you!

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

Successfully merging a pull request may close this issue.

3 participants