# Generated by Django 3.1.2 on 2020-12-16 21:37

from django.db import migrations, models
import django.db.models.deletion


def add_payment_to_existing_sales(apps, schema_editor):
    Sale = apps.get_model("Sales", "Sale")
    SalePayment = apps.get_model("Sales", "SalePayment")

    for sale in Sale.objects.all():
        SalePayment.objects.create(sale=sale, payment_type="cash")


class Migration(migrations.Migration):

    dependencies = [
        ('Sales', '0009_itemvariant'),
    ]

    operations = [
        migrations.CreateModel(
            name='SalePayment',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('payment_type', models.CharField(choices=[('cash', 'cash'), ('card', 'card')], default='cash', max_length=4, verbose_name='Método de pago')),
                ('card', models.CharField(max_length=255, null=True)),
                ('cvc', models.CharField(max_length=255, null=True)),
                ('expiry', models.CharField(max_length=255, null=True)),
                ('sale', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='payment', to='Sales.sale')),
            ],
        ),
        migrations.RunPython(add_payment_to_existing_sales, migrations.RunPython.noop)
    ]
