# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-01-22 09:46
from __future__ import unicode_literals

from django.db import migrations
from oscar.apps.catalogue.categories import create_from_breadcrumbs
from oscar.core.loading import get_model

Category = get_model('catalogue', 'Category')

COUPON_CATEGORY_NAME = 'Coupons'

EDX_EMPLOYEE_COUPON_CATEGORY = 'edX Employee Request'

def create_edx_employee_category(apps, schema_editor):
    """Create edX employee coupon category."""
    Category.skip_history_when_saving = True
    create_from_breadcrumbs(
        '{} > {}'.format(
            COUPON_CATEGORY_NAME, EDX_EMPLOYEE_COUPON_CATEGORY
        )
    )


def remove_edx_employee_category(apps, schema_editor):
    """Remove edX employee coupon category."""
    Category.skip_history_when_saving = True
    Category.objects.get(
        name=COUPON_CATEGORY_NAME
    ).get_children().filter(
        name=EDX_EMPLOYEE_COUPON_CATEGORY
    ).delete()


class Migration(migrations.Migration):
    dependencies = [
        ('catalogue', '0044_add_enterprisecontractmetadata_product_attribute'),
    ]

    operations = [
        migrations.RunPython(create_edx_employee_category, remove_edx_employee_category)
    ]

Add new coupon category for edX.
Add new coupon category for edX.

Added a data migration to create a new coupon category for edX
employees.

PROD-1177
