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: Add discount payment types #1390

Merged
merged 18 commits into from
Feb 14, 2023
Merged

Conversation

asadali145
Copy link
Contributor

@asadali145 asadali145 commented Jan 26, 2023

Pre-Flight checklist

  • Migrations
    • Migration is backwards-compatible with current production code
  • Testing
    • Code is tested
    • Changes have been manually tested

What are the relevant tickets?

Closes #1074

What's this PR do?

  • Adds a new field payment_type in the discounts model.
  • Replaces all usages of for_flexible_pricing with payment_type.
  • Adds data migration to set the payment types for the existing discounts.
  • Updates the generate_discount_code management command to add a new argument.

How should this be manually tested?

There are a few things that we need to test.

  • Test that the old discounts are updated per the data migration logic /admin/ecommerce/discount/.
    • If for_flexible_pricing=True then payment_type=financial-assistance
    • if the discount code starts with CS- then payment_type=customer-support
    • if the discount code starts with JPAL- then payment_type=staff
    • if the discount code starts with MITALUM15-, 14750x-, 14740x-, 1473x-, 14310x-, JPAL102x- or CYB2022- then payment_type=marketing
    • If discount code is CYBER2022 then payment_type=marketing
  • Test that the new field is added in the Django Admin list and detail view /admin/ecommerce/discount/.
  • Test that the new field is added in refine dashboard. The discounts filter works fine and the new field is also working fine in discounts create, view, and edit forms.
  • Test that the financial assistance request flow is fine. i.e Once a request is approved, the discount is applied automatically on the checkout page.
  • Test that the discounts work fine when applying manually on the checkout page.

@asadali145 asadali145 force-pushed the asad/1074-discount-payment-types branch from 7746aa9 to e76317c Compare January 26, 2023 13:19
migrations.AddField(
model_name='discount',
name='payment_type',
field=models.CharField(choices=[('B2C', 'Marketing'), ('B2B', 'Sales'), ('FA', 'Financial Assistance'), ('CS', 'Customer Support')], max_length=3, null=True),
Copy link
Member

Choose a reason for hiding this comment

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

I need to confirm this list. Please don't merge until I've signed off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pdpinch Do you have an update on this?

Copy link
Member

Choose a reason for hiding this comment

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

Need to add one more: "staff"

@pdpinch
Copy link
Member

pdpinch commented Jan 26, 2023

How should we handle updating existing coupons?

@asadali145
Copy link
Contributor Author

How should we handle updating existing coupons?

I am not really sure about that. I have created a data migration for financial assistance discounts. I am not sure about all the other types of discounts. Maybe if have some kind of a pattern then we can create a data migration for other discounts as well.

For now, I have kept the new field nullable. So, It will be null for all the discounts apart from the ones that are related to financial assistance.

Do you have any information about any pattern that we used for the discounts that we can use and write a data migration?

@pdpinch
Copy link
Member

pdpinch commented Feb 1, 2023

I have created a data migration for financial assistance discounts.

great.

It will be null for all the discounts apart from the ones that are related to financial assistance.

Good idea. That's fine.

Do you have any information about any pattern that we used for the discounts that we can use and write a data migration?

@jkachel may have some suggestions for some of the coupons he created.

To be clear, it's not necessary that we backfill all of them. I just want to update the easy ones.

@jkachel
Copy link
Contributor

jkachel commented Feb 1, 2023

We've only had to do a few runs of these so it shouldn't be too bad to do. The patterns I've been using are:

  • Customer Service - always starts with CS-
  • JPAL staff discounts - starts with JPAL-
  • MIT Alumni discounts - starts with MITALUM15-
  • There were also 100 codes each for $100 fixed price for the individual DEDP courses that start with an abbreviated version of the course number (i.e. 14750x-) - I can't find the ticket that we made these for though. (These are different than the JPAL discounts, which also have the course number in them.)

The create_discount_code management command also needs to be updated to support this. Didn't see that in the code but batches of codes (and thus codes that would generally need to be tagged in this manner) are generated using that command.

@asadali145
Copy link
Contributor Author

The create_discount_code management command also needs to be updated to support this.

Yeah, I will be updating a couple of commands, The work is in progress for that.

MIT Alumni discounts - starts with MITALUM15-

What should be the type for these discounts?

There were also 100 codes each

What should be the type for these course discounts?

@codecov-commenter
Copy link

codecov-commenter commented Feb 2, 2023

Codecov Report

Merging #1390 (44126b5) into main (b1c97ee) will decrease coverage by 0.03%.
The diff coverage is 55.17%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #1390      +/-   ##
==========================================
- Coverage   83.22%   83.19%   -0.03%     
==========================================
  Files         309      309              
  Lines       13135    13148      +13     
  Branches      935      936       +1     
==========================================
+ Hits        10932    10939       +7     
- Misses       1936     1940       +4     
- Partials      267      269       +2     
Impacted Files Coverage Δ
...erce/management/commands/generate_discount_code.py 0.00% <0.00%> (ø)
...ement/commands/generate_legacy_enrollment_codes.py 0.00% <0.00%> (ø)
ecommerce/serializers.py 68.38% <ø> (ø)
...d/public/src/containers/pages/checkout/CartPage.js 40.81% <0.00%> (ø)
frontend/public/src/factories/course.js 98.91% <ø> (ø)
ecommerce/admin.py 64.37% <100.00%> (ø)
ecommerce/api.py 78.06% <100.00%> (ø)
ecommerce/constants.py 100.00% <100.00%> (ø)
ecommerce/factories.py 100.00% <100.00%> (ø)
ecommerce/models.py 85.36% <100.00%> (ø)
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@asadali145
Copy link
Contributor Author

Hey @pdpinch & @jkachel,
I am doing the following mapping for the new payment_type field. Let me know if there is any issue with this.

  • Discounts with for_flexible_pricing=True will have payment_type=financial-assistance
  • Discounts with discount codes starting with CS- will have payment_type=customer-support
  • Discounts with discount codes starting with JPAL- will have payment_type=staff

Also, I am not sure about these 2 discounts. What should be the payment_type for these 2 types of discounts?

MIT Alumni discounts - starts with MITALUM15-

There were also 100 codes each for $100 fixed price for the individual DEDP courses that start with an abbreviated version of the course number (i.e. 14750x-) - I can't find the ticket that we made these for though. (These are different than the JPAL discounts, which also have the course number in them.)

@jkachel
Copy link
Contributor

jkachel commented Feb 2, 2023

MIT Alumni discounts - starts with MITALUM15-

What should be the type for these discounts?

There were also 100 codes each

What should be the type for these course discounts?

After some thought, I think both of these are B2C.

I did find out the purpose for the last group of codes I mentioned. They're for the lottery - https://odl.zendesk.com/agent/tickets/145641 is the Zendesk ticket for that (which you'll probably not be able to get into, just including for completeness) and this is it in HQ: https://github.com/mitodl/hq/issues/558. The relevant info from the ticket is:

These coupons are used for a lottery that's run every term for DEDP. The specific products change each term because not every course is offered every term.

In addition, I also found a couple more groups that will need backfilling:

  • CYB2022- (batch) and CYBER2022 (singular) - we have a handful of these codes that were for this past Cyber Monday sale - those are definitely B2C. (There was an issue with the actual CYBER2022 singular code I'd set up for this so there are also a batch of codes to hand out to folks who had issues with the code.)
  • MM-prepaid- - there are a bunch of these from the MicroMasters migration. I'm not sure if these are B2C or CS, though, or if we should leave these as-is because this is a one-off special case.

@asadali145
Copy link
Contributor Author

@jkachel There are also some discount codes starting with JPAL102x-. Are they the same as JPAL-? Or are they more like lottery discounts? What should be the type of these? staff or marketing?

@asadali145
Copy link
Contributor Author

MM-prepaid- - there are a bunch of these from the MicroMasters migration. I'm not sure if these are B2C or CS, though, or if we should leave these as-is because this is a one-off special case.

@pdpinch What do you suggest about these?

@jkachel
Copy link
Contributor

jkachel commented Feb 3, 2023

@jkachel There are also some discount codes starting with JPAL102x-. Are they the same as JPAL-? Or are they more like lottery discounts? What should be the type of these? staff or marketing?

JPAL102x- are lottery codes and JPAL- are for JPAL staff.

@asadali145 asadali145 force-pushed the asad/1074-discount-payment-types branch from ffda830 to 0fd5e11 Compare February 3, 2023 13:46
@asadali145 asadali145 marked this pull request as ready for review February 3, 2023 13:49
@asadali145 asadali145 requested review from jkachel and pdpinch February 3, 2023 14:01
@jkachel jkachel self-assigned this Feb 3, 2023
Copy link
Contributor

@jkachel jkachel left a comment

Choose a reason for hiding this comment

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

Everything looks good - staff dashboard looked OK, management command is good, workflow is fine on the frontend. Approving conditionally because of two things:

  • waiting on resolution for MM-prepaid codes from @pdpinch (my thought is to leave them blank because we're never going to do anything like that again probably, or at least not without it being a whole thing that gets tracked like a project)
  • can you update the docs for generate_discount_code in docs/source/commands? It needs the new flag added.

Other than those two things, LGTM 👍

Copy link
Contributor

@jkachel jkachel left a comment

Choose a reason for hiding this comment

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

Rescinding previous approval - did not notice but the financial assistance emails are broken. I can't link to a Sentry log for this because it's on my local Sentry instance but here's the relevant stack trace:

image

@asadali145
Copy link
Contributor Author

Rescinding previous approval - did not notice but the financial assistance emails are broken. I can't link to a Sentry log for this because it's on my local Sentry instance but here's the relevant stack trace:

@jkachel Could you please verify if this is a legit issue? It seems like a migrations issue to me. Not sure if you tried to change something there. Everything is working fine for me. I am getting the emails. I have also tried to reapply all the migrations as well.

Screen Shot 2023-02-06 at 11 39 25 AM

@jkachel
Copy link
Contributor

jkachel commented Feb 6, 2023

@jkachel Could you please verify if this is a legit issue? It seems like a migrations issue to me. Not sure if you tried to change something there. Everything is working fine for me. I am getting the emails. I have also tried to reapply all the migrations as well.

After some checking I have no idea. The local copy I use most of the time has issues (even with a fresh database and the migrations applied), but I tested it on a separate system and it works OK there. So, this does seem like a local-to-me issue or maybe at worst a macOS issue.

Copy link
Contributor

@jkachel jkachel left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@pdpinch
Copy link
Member

pdpinch commented Feb 8, 2023

waiting on resolution for MM-prepaid codes from @pdpinch (my thought is to leave them blank because we're never going to do anything like that again probably, or at least not without it being a whole thing that gets tracked like a project)

I think we should make a new category for these, "legacy"

@asadali145 asadali145 force-pushed the asad/1074-discount-payment-types branch from 44126b5 to 23f0b3d Compare February 9, 2023 09:13
@asadali145
Copy link
Contributor Author

23f0b3d adds a new payment type legacy.
@jkachel Could you have one last look?

@pdpinch pdpinch mentioned this pull request Feb 10, 2023
2 tasks
Copy link
Contributor

@jkachel jkachel left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@asadali145 asadali145 merged commit 82d222e into main Feb 14, 2023
@odlbot odlbot mentioned this pull request Feb 15, 2023
2 tasks
@asadali145 asadali145 deleted the asad/1074-discount-payment-types branch March 17, 2023 12:17
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.

tracking types of discounts
4 participants