-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 3.2.20 on 2024-01-04 09:32 | ||
|
||
from django.db import migrations | ||
|
||
from ecommerce.core.constants import SEAT_PRODUCT_CLASS_NAME | ||
|
||
|
||
def create_product_attribute(apps, schema_editor): | ||
""" Create a product attribute for course seat product class""" | ||
ProductAttribute = apps.get_model("catalogue", "ProductAttribute") | ||
ProductClass = apps.get_model("catalogue", "ProductClass") | ||
Check warning on line 11 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py Codecov / codecov/patchecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L10-L11
|
||
|
||
for class_iter in (ProductAttribute, ProductClass): | ||
class_iter.skip_history_when_saving = True | ||
Check warning on line 14 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py Codecov / codecov/patchecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L13-L14
|
||
|
||
seat = ProductClass.objects.get(name=SEAT_PRODUCT_CLASS_NAME) | ||
|
||
# Create product attribute for course seat products | ||
product_attr = ProductAttribute( | ||
product_class=seat, | ||
name="variant_id", | ||
code="variant_id", | ||
type="text", | ||
required=False | ||
) | ||
product_attr.save() | ||
|
||
def remove_product_attribute(apps, schema_editor): | ||
""" Reverse function. """ | ||
ProductAttribute = apps.get_model("catalogue", "ProductAttribute") | ||
ProductAttribute.skip_history_when_saving = True | ||
ProductAttribute.objects.filter(name='variant_id', product_class__name=SEAT_PRODUCT_CLASS_NAME).delete() | ||
Check warning on line 32 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py Codecov / codecov/patchecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L30-L32
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('catalogue', '0055_sf_opp_line_item_ent_attr'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_product_attribute, remove_product_attribute), | ||
] |