# intended to run in shell plus
from django.contrib.auth.models import User
from django.db import transaction

from catalog.constants import INCOUNTY, INSTATE, OUTSTATE, REGULAR, FIRST_CLASS, FOREIGN
from catalog.models import Subscription

TITLES = ("The Weekly Packet", "Island Advantages", "Castine Patriot")
PREFIXES = (("IC", INCOUNTY), ("IS", INSTATE), ("OOS", OUTSTATE))  # 'F'
DURATIONS = ["9", "12", "24"]
SHIPPING = (("R", REGULAR),)  # 'FC'

pricing = {
    "IC9R": 23.95,
    "IS9R": 24.95,
    "OOS9R": 34.95,
    "IC12R": 29.95,
    "IS12R": 31.95,
    "OOS12R": 44.95,
    "IC24R": 54.95,
    "IS24R": 57.95,
    "OOS24R": 79.95,
}

with transaction.commit_on_success():
    admin, rc = User.objects.get_or_create(username="admin")
    for title in TITLES:
        for prefix, value in PREFIXES:
            for duration in DURATIONS:
                for shipping_prefix, shipping_value in SHIPPING:
                    sku = prefix + duration + shipping_prefix
                    price = pricing[sku]
                    # first letter in title
                    title_abbrev = "".join([i[0] for i in title.upper().split()])
                    sku = title_abbrev + sku
                    # regular flavor
                    # subscription, rc = Subscription.objects.get_or_create(
                    #     sku=sku,
                    #     created_by=admin,
                    #     last_updated_by=admin,
                    #     price=price,
                    #     shipping_cost=0.00,
                    #     shipping_cost_multiple=1,
                    #     duration=duration,
                    #     title=title,
                    #     shipping_type=value,
                    #     shipping_method=shipping_value)
                    # subscription.save()
                    # renewal flavor
                    sku += "REN"
                    subscription, rc = Subscription.objects.get_or_create(
                        sku=sku,
                        created_by=admin,
                        last_updated_by=admin,
                        price=price,
                        shipping_cost=0.00,
                        shipping_cost_multiple=1,
                        duration=duration,
                        title=title,
                        shipping_type=value,
                        shipping_method=shipping_value,
                        renewal=True,
                    )
                    subscription.save()

# intended to run in shell plus
from django.contrib.auth.models import User
from django.db import transaction

from catalog.constants import INCOUNTY, INSTATE, OUTSTATE, REGULAR, FIRST_CLASS, FOREIGN
from catalog.models import Subscription

TITLES = ("The Weekly Packet", "Island Advantages", "Castine Patriot")
PREFIXES = (
    ("IC", INCOUNTY),
    ("IS", INSTATE),
    ("OOS", OUTSTATE),
    ("F", FOREIGN),
)  # 'F'
DURATIONS = ["12"]
SHIPPING = (("FC", FIRST_CLASS),)  # 'FC'

pricing = {"IC12FC": 169.95, "IS12FC": 169.95, "OOS12FC": 169.95, "F12FC": 279.95}

with transaction.commit_on_success():
    admin = User.objects.get(username="admin")
    for title in TITLES:
        for prefix, value in PREFIXES:
            for duration in DURATIONS:
                for shipping_prefix, shipping_value in SHIPPING:
                    sku = prefix + duration + shipping_prefix
                    price = pricing[sku]
                    # first letter in title
                    title_abbrev = "".join([i[0] for i in title.upper().split()])
                    sku = title_abbrev + sku
                    # regular flavor
                    subscription, rc = Subscription.objects.get_or_create(
                        sku=sku,
                        created_by=admin,
                        last_updated_by=admin,
                        price=price,
                        shipping_cost=0.00,
                        shipping_cost_multiple=1,
                        duration=duration,
                        title=title,
                        shipping_type=value,
                        shipping_method=shipping_value,
                    )
                    subscription.save()
                    # renewal flavor
                    sku += "REN"
                    subscription, rc = Subscription.objects.get_or_create(
                        sku=sku,
                        created_by=admin,
                        last_updated_by=admin,
                        price=price,
                        shipping_cost=0.00,
                        shipping_cost_multiple=1,
                        duration=duration,
                        title=title,
                        shipping_type=value,
                        shipping_method=shipping_value,
                        renewal=True,
                    )
                    subscription.save()
