-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add discount payment types (#1390)
* feat: Add payment_type field for discounts * backfill migration * replace for_flexible_pricing & update choices * fmt * lint & fmt * feat: Add staff as a payment type * feat(generate_discount_code): Add support for payment types * fmt * isort * remove usage of for_flexible_pricing from generate_discount codes * feat(generate_legacy_enrollment_codes): sets payment_type to customer-support for legacy discount command * feat: update config_tiers command to set payment_type * isort & ran black * Updated data migration * feat(backfill_payment_types: Add more backfill) * remove for_flexible_pricing field in favour of payment_type * update generate_discount_code docs * add new payment_type `legacy`
- Loading branch information
1 parent
2938128
commit 82d222e
Showing
25 changed files
with
288 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 3.2.15 on 2023-02-09 08:49 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("ecommerce", "0030_alter_discount_for_flexible_pricing"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="discount", | ||
name="payment_type", | ||
field=models.CharField( | ||
choices=[ | ||
("marketing", "marketing"), | ||
("sales", "sales"), | ||
("financial-assistance", "financial-assistance"), | ||
("customer-support", "customer-support"), | ||
("staff", "staff"), | ||
("legacy", "legacy"), | ||
], | ||
max_length=30, | ||
null=True, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 3.2.15 on 2023-02-09 08:49 | ||
|
||
from django.db import migrations | ||
from django.db.models import Q | ||
|
||
from ecommerce.constants import ( | ||
PAYMENT_TYPE_CUSTOMER_SUPPORT, | ||
PAYMENT_TYPE_FINANCIAL_ASSISTANCE, | ||
PAYMENT_TYPE_LEGACY, | ||
PAYMENT_TYPE_MARKETING, | ||
PAYMENT_TYPE_STAFF, | ||
) | ||
|
||
|
||
def backfill_payment_types(apps, schema_editor): | ||
discount = apps.get_model("ecommerce", "Discount") | ||
|
||
# financial-assistance have `for_flexible_pricing=True` | ||
discount.objects.filter(for_flexible_pricing=True).update( | ||
payment_type=PAYMENT_TYPE_FINANCIAL_ASSISTANCE | ||
) | ||
|
||
# customer-support discount codes start with `CS-` | ||
discount.objects.filter(discount_code__startswith="CS-").update( | ||
payment_type=PAYMENT_TYPE_CUSTOMER_SUPPORT | ||
) | ||
|
||
# staff discount codes start with `JPAL-` | ||
discount.objects.filter(discount_code__startswith="JPAL-").update( | ||
payment_type=PAYMENT_TYPE_STAFF | ||
) | ||
|
||
# legacy discounts start with `MM-prepaid-` | ||
discount.objects.filter(discount_code__startswith="MM-prepaid-").update( | ||
payment_type=PAYMENT_TYPE_LEGACY | ||
) | ||
|
||
# marketing discount codes have multiple start codes | ||
discount.objects.filter( | ||
Q(discount_code__startswith="MITALUM15-") | ||
| Q(discount_code__startswith="14750x-") | ||
| Q(discount_code__startswith="14740x-") | ||
| Q(discount_code__startswith="1473x-") | ||
| Q(discount_code__startswith="14310x-") | ||
| Q(discount_code__startswith="JPAL102x-") | ||
| Q(discount_code__startswith="CYB2022-") | ||
| Q(discount_code="CYBER2022") | ||
).update(payment_type=PAYMENT_TYPE_MARKETING) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("ecommerce", "0031_discount_payment_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(backfill_payment_types, migrations.RunPython.noop), | ||
] |
17 changes: 17 additions & 0 deletions
17
ecommerce/migrations/0033_remove_discount_for_flexible_pricing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 3.2.15 on 2023-02-09 08:52 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("ecommerce", "0032_backfill_payment_types"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="discount", | ||
name="for_flexible_pricing", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.