Skip to content

Commit

Permalink
feat: add coupon sf opp line item attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jun 20, 2023
1 parent 2f1437e commit fd5f0c2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-


from django.db import migrations
from oscar.core.loading import get_model

from ecommerce.core.constants import COUPON_PRODUCT_CLASS_NAME

ProductAttribute = get_model("catalogue", "ProductAttribute")
ProductClass = get_model("catalogue", "ProductClass")

SF_LINE_ITEM_ATTRIBUTE_CODE = 'salesforce_opportunity_line_item'


def create_sf_opp_line_item_attribute(apps, schema_editor):
"""Create enterprise coupon salesforce_opportunity_line_item product attribute."""
ProductAttribute.skip_history_when_saving = True
coupon = ProductClass.objects.get(name=COUPON_PRODUCT_CLASS_NAME)
pa = ProductAttribute(
product_class=coupon,
name='Salesforce Opportunity Line Item',
code=SF_LINE_ITEM_ATTRIBUTE_CODE,
type='text',
required=True,
)
pa.save()


def remove_sf_opp_line_item_attribute(apps, schema_editor):
"""Remove enterprise coupon salesforce_opportunity_line_item product attribute."""
coupon = ProductClass.objects.get(name=COUPON_PRODUCT_CLASS_NAME)
ProductAttribute.skip_history_when_saving = True
ProductAttribute.objects.get(product_class=coupon, code=SF_LINE_ITEM_ATTRIBUTE_CODE).delete()


class Migration(migrations.Migration):

dependencies = [
('catalogue', '0054_add_variant_id_product_attr')
]
operations = [
migrations.RunPython(
create_sf_opp_line_item_attribute,
remove_sf_opp_line_item_attribute,
),
]
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
ignore=E501,E722,W504
max_line_length=119
exclude=settings,migrations,ecommerce/static,bower_components,ecommerce/wsgi.py

[flake8]
max-line-length=119

0 comments on commit fd5f0c2

Please sign in to comment.