Stall stripe

This commit is contained in:
Nathan Chapman 2022-10-15 20:58:49 -06:00
parent 8b4eb80fbb
commit 8f10b38f9a
22 changed files with 170 additions and 545 deletions

View File

@ -5,7 +5,7 @@ class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts' name = 'accounts'
def ready(self): # def ready(self):
from .signals import ( # from .signals import (
user_saved # user_saved
) # )

View File

@ -7,7 +7,7 @@ class CoreConfig(AppConfig):
def ready(self): def ready(self):
from .signals import ( from .signals import (
product_saved, # variant_saved,
order_created, order_created,
transaction_created, transaction_created,
order_line_post_save, order_line_post_save,

View File

@ -1,8 +1,9 @@
# Generated by Django 4.0.2 on 2022-03-11 02:25 # Generated by Django 4.0.2 on 2022-10-16 02:36
import core.weight import core.weight
from decimal import Decimal from decimal import Decimal
from django.conf import settings from django.conf import settings
import django.contrib.postgres.fields
import django.core.validators import django.core.validators
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -16,46 +17,101 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('accounts', '0001_initial'), ('accounts', '0003_user_stripe_id'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
migrations.CreateModel(
name='Coupon',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('type', models.CharField(choices=[('entire_order', 'Entire order'), ('shipping', 'Shipping'), ('specific_product', 'Specific products, collections and categories')], default='entire_order', max_length=20)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('code', models.CharField(db_index=True, max_length=12, unique=True)),
('valid_from', models.DateTimeField(default=django.utils.timezone.now)),
('valid_to', models.DateTimeField(blank=True, null=True)),
('discount_value_type', models.CharField(choices=[('fixed', 'USD'), ('percentage', '%')], default='fixed', max_length=10)),
('discount_value', models.DecimalField(decimal_places=2, max_digits=12)),
],
options={
'ordering': ('code',),
},
),
migrations.CreateModel( migrations.CreateModel(
name='Order', name='Order',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.CharField(choices=[('draft', 'Draft'), ('unfulfilled', 'Unfulfilled'), ('partially fulfilled', 'Partially fulfilled'), ('partially_returned', 'Partially returned'), ('returned', 'Returned'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled')], default='unfulfilled', max_length=32)), ('status', models.CharField(choices=[('draft', 'Draft'), ('unfulfilled', 'Unfulfilled'), ('partially_fulfilled', 'Partially fulfilled'), ('partially_returned', 'Partially returned'), ('returned', 'Returned'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled')], default='unfulfilled', max_length=32)),
('total_net_amount', models.DecimalField(decimal_places=2, default=0, max_digits=10)), ('subtotal_amount', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
('weight', django_measurement.models.MeasurementField(default=core.weight.zero_weight, measurement=measurement.measures.mass.Mass)), ('coupon_amount', models.CharField(blank=True, max_length=255)),
('shipping_total', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
('total_amount', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
('weight', django_measurement.models.MeasurementField(blank=True, default=core.weight.zero_weight, measurement=measurement.measures.mass.Mass, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)), ('updated_at', models.DateTimeField(auto_now=True)),
('billing_address', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounts.address')), ('billing_address', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounts.address')),
('coupon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='core.coupon')),
('customer', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to=settings.AUTH_USER_MODEL)), ('customer', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to=settings.AUTH_USER_MODEL)),
('shipping_address', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounts.address')), ('shipping_address', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='accounts.address')),
], ],
options={
'ordering': ('-created_at',),
},
), ),
migrations.CreateModel( migrations.CreateModel(
name='Product', name='Product',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=250)), ('name', models.CharField(max_length=250)),
('subtitle', models.CharField(blank=True, max_length=250)),
('description', models.TextField(blank=True)), ('description', models.TextField(blank=True)),
('sku', models.CharField(max_length=255, unique=True)), ('checkout_limit', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)])),
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
('weight', django_measurement.models.MeasurementField(blank=True, measurement=measurement.measures.mass.Mass, null=True)),
('visible_in_listings', models.BooleanField(default=False)), ('visible_in_listings', models.BooleanField(default=False)),
('sorting', models.PositiveIntegerField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)), ('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)), ('updated_at', models.DateTimeField(auto_now=True)),
], ],
options={
'ordering': ['sorting', 'name'],
},
), ),
migrations.CreateModel( migrations.CreateModel(
name='ShippingMethod', name='ProductCategory',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)), ('name', models.CharField(max_length=255)),
('type', models.CharField(choices=[('price', 'Price based shipping'), ('weight', 'Weight based shipping')], max_length=30)), ('main_category', models.BooleanField(default=True)),
], ],
options={
'verbose_name': 'Product Category',
'verbose_name_plural': 'Product Categories',
},
),
migrations.CreateModel(
name='ShippingRate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shipping_provider', models.CharField(choices=[('USPS', 'USPS')], default='USPS', max_length=255)),
('name', models.CharField(max_length=255)),
('container', models.CharField(choices=[('LG FLAT RATE BOX', 'Flate Rate Box - Large'), ('MD FLAT RATE BOX', 'Flate Rate Box - Medium'), ('REGIONALRATEBOXA', 'Regional Rate Box A'), ('REGIONALRATEBOXB', 'Regional Rate Box B'), ('VARIABLE', 'Variable')], default='VARIABLE', max_length=255)),
('min_order_weight', models.PositiveIntegerField(blank=True, null=True)),
('max_order_weight', models.PositiveIntegerField(blank=True, null=True)),
],
options={
'ordering': ['min_order_weight'],
},
),
migrations.CreateModel(
name='SiteSettings',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('usps_user_id', models.CharField(max_length=255)),
],
options={
'verbose_name': 'Site Settings',
'verbose_name_plural': 'Site Settings',
},
), ),
migrations.CreateModel( migrations.CreateModel(
name='Transaction', name='Transaction',
@ -67,6 +123,47 @@ class Migration(migrations.Migration):
('order', models.OneToOneField(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.order')), ('order', models.OneToOneField(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.order')),
], ],
), ),
migrations.CreateModel(
name='TrackingNumber',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tracking_id', models.CharField(max_length=256)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('order', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='tracking_numbers', to='core.order')),
],
options={
'verbose_name': 'Tracking Number',
'verbose_name_plural': 'Tracking Numbers',
},
),
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_id', models.CharField(blank=True, max_length=255)),
('customer', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subscription', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='ProductVariant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('sku', models.CharField(max_length=255, unique=True)),
('stripe_id', models.CharField(blank=True, max_length=255)),
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
('weight', django_measurement.models.MeasurementField(blank=True, measurement=measurement.measures.mass.Mass, null=True)),
('track_inventory', models.BooleanField(default=False)),
('stock', models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)])),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='variants', to='core.product')),
],
options={
'ordering': ['weight'],
},
),
migrations.CreateModel( migrations.CreateModel(
name='ProductPhoto', name='ProductPhoto',
fields=[ fields=[
@ -75,6 +172,20 @@ class Migration(migrations.Migration):
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.product')), ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.product')),
], ],
), ),
migrations.CreateModel(
name='ProductOption',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('options', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), size=None)),
('products', models.ManyToManyField(related_name='options', to='core.Product')),
],
),
migrations.AddField(
model_name='product',
name='category',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.productcategory'),
),
migrations.CreateModel( migrations.CreateModel(
name='OrderLine', name='OrderLine',
fields=[ fields=[
@ -86,29 +197,17 @@ class Migration(migrations.Migration):
('unit_price', models.DecimalField(decimal_places=2, max_digits=12)), ('unit_price', models.DecimalField(decimal_places=2, max_digits=12)),
('tax_rate', models.DecimalField(decimal_places=2, default=Decimal('0.0'), max_digits=5)), ('tax_rate', models.DecimalField(decimal_places=2, default=Decimal('0.0'), max_digits=5)),
('order', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='core.order')), ('order', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='core.order')),
('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_lines', to='core.product')), ('variant', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_lines', to='core.productvariant')),
], ],
), ),
migrations.AddField( migrations.AddField(
model_name='order', model_name='coupon',
name='shipping_method', name='products',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='core.shippingmethod'), field=models.ManyToManyField(blank=True, to='core.Product'),
), ),
migrations.CreateModel( migrations.AddField(
name='Coupon', model_name='coupon',
fields=[ name='users',
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), field=models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL),
('type', models.CharField(choices=[('entire_order', 'Entire order'), ('shipping', 'Shipping'), ('specific_product', 'Specific products, collections and categories')], default='entire_order', max_length=20)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('code', models.CharField(db_index=True, max_length=12, unique=True)),
('valid_from', models.DateTimeField(default=django.utils.timezone.now)),
('valid_to', models.DateTimeField(blank=True, null=True)),
('discount_value_type', models.CharField(choices=[('fixed', 'USD'), ('percentage', '%')], default='fixed', max_length=10)),
('discount_value', models.DecimalField(decimal_places=2, max_digits=12)),
('products', models.ManyToManyField(blank=True, to='core.Product')),
],
options={
'ordering': ('code',),
},
), ),
] ]

View File

@ -1,36 +0,0 @@
# Generated by Django 4.0.2 on 2022-03-23 16:25
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='shippingmethod',
name='price',
field=models.DecimalField(decimal_places=2, default=0, max_digits=12),
),
migrations.AlterField(
model_name='order',
name='status',
field=models.CharField(choices=[('draft', 'Draft'), ('unfulfilled', 'Unfulfilled'), ('partially_fulfilled', 'Partially fulfilled'), ('partially_returned', 'Partially returned'), ('returned', 'Returned'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled')], default='unfulfilled', max_length=32),
),
migrations.CreateModel(
name='TrackingNumber',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tracking_id', models.CharField(max_length=256)),
('order', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='tracking_numbers', to='core.order')),
],
options={
'verbose_name': 'Tracking Number',
'verbose_name_plural': 'Tracking Numbers',
},
),
]

View File

@ -1,25 +0,0 @@
# Generated by Django 4.0.2 on 2022-03-23 17:04
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('core', '0002_shippingmethod_price_alter_order_status_and_more'),
]
operations = [
migrations.AddField(
model_name='trackingnumber',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='trackingnumber',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 4.0.2 on 2022-03-23 21:30
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0003_trackingnumber_created_at_trackingnumber_updated_at'),
]
operations = [
migrations.AddField(
model_name='order',
name='coupon',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='core.coupon'),
),
]

View File

@ -1,22 +0,0 @@
# Generated by Django 4.0.2 on 2022-03-28 17:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_order_coupon'),
]
operations = [
migrations.AlterModelOptions(
name='product',
options={'ordering': ['sorting', 'name']},
),
migrations.AddField(
model_name='product',
name='sorting',
field=models.PositiveIntegerField(blank=True, null=True),
),
]

View File

@ -1,22 +0,0 @@
# Generated by Django 4.0.2 on 2022-04-24 16:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_alter_product_options_product_sorting'),
]
operations = [
migrations.AlterModelOptions(
name='order',
options={'ordering': ('-created_at',)},
),
migrations.AddField(
model_name='order',
name='shipping_total',
field=models.DecimalField(decimal_places=2, default=0, max_digits=5),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 4.0.2 on 2022-04-30 15:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0006_alter_order_options_order_shipping_total'),
]
operations = [
migrations.AddField(
model_name='product',
name='subtitle',
field=models.CharField(blank=True, max_length=250),
),
]

View File

@ -1,27 +0,0 @@
# Generated by Django 4.0.2 on 2022-04-30 23:11
import core.weight
from django.db import migrations, models
import django.db.models.deletion
import django_measurement.models
import measurement.measures.mass
class Migration(migrations.Migration):
dependencies = [
('core', '0007_product_subtitle'),
]
operations = [
migrations.AlterField(
model_name='order',
name='coupon',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='core.coupon'),
),
migrations.AlterField(
model_name='order',
name='weight',
field=django_measurement.models.MeasurementField(blank=True, default=core.weight.zero_weight, measurement=measurement.measures.mass.Mass, null=True),
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 4.0.2 on 2022-05-11 00:55
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0008_alter_order_coupon_alter_order_weight'),
]
operations = [
migrations.AddField(
model_name='coupon',
name='users',
field=models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 4.0.2 on 2022-07-23 17:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0009_coupon_users'),
]
operations = [
migrations.AddField(
model_name='product',
name='stripe_id',
field=models.CharField(blank=True, max_length=255),
),
]

View File

@ -1,29 +0,0 @@
# Generated by Django 4.0.2 on 2022-08-07 19:40
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0010_product_stripe_id'),
]
operations = [
migrations.AddField(
model_name='product',
name='stripe_price_id',
field=models.CharField(blank=True, max_length=255),
),
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_id', models.CharField(blank=True, max_length=255)),
('customer', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subscription', to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -1,130 +0,0 @@
# Generated by Django 4.0.2 on 2022-09-07 20:34
from django.conf import settings
import django.contrib.postgres.fields
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django_measurement.models
import measurement.measures.mass
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0010_product_stripe_id'),
]
operations = [
migrations.CreateModel(
name='ProductCategory',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
options={
'verbose_name': 'Product Category',
'verbose_name_plural': 'Product Categories',
},
),
migrations.CreateModel(
name='ProductOption',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('options', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=255), size=None)),
],
),
migrations.CreateModel(
name='ProductVariant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('sku', models.CharField(max_length=255, unique=True)),
('stripe_id', models.CharField(blank=True, max_length=255)),
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
('weight', django_measurement.models.MeasurementField(blank=True, measurement=measurement.measures.mass.Mass, null=True)),
('track_inventory', models.BooleanField(default=False)),
('stock', models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)])),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='ShippingRate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shipping_provider', models.CharField(choices=[('USPS', 'USPS')], default='USPS', max_length=255)),
('name', models.CharField(max_length=255)),
('container', models.CharField(choices=[('LG FLAT RATE BOX', 'Flate Rate Box - Large'), ('MD FLAT RATE BOX', 'Flate Rate Box - Medium'), ('REGIONALRATEBOXA', 'Regional Rate Box A'), ('REGIONALRATEBOXB', 'Regional Rate Box B'), ('VARIABLE', 'Variable')], default='VARIABLE', max_length=255)),
('min_order_weight', models.PositiveIntegerField(blank=True, null=True)),
('max_order_weight', models.PositiveIntegerField(blank=True, null=True)),
],
options={
'ordering': ['min_order_weight'],
},
),
migrations.CreateModel(
name='SiteSettings',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('usps_user_id', models.CharField(max_length=255)),
],
options={
'verbose_name': 'Site Settings',
'verbose_name_plural': 'Site Settings',
},
),
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_id', models.CharField(blank=True, max_length=255)),
('customer', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subscription', to=settings.AUTH_USER_MODEL)),
],
),
migrations.RemoveField(
model_name='order',
name='shipping_method',
),
migrations.RemoveField(
model_name='product',
name='price',
),
migrations.RemoveField(
model_name='product',
name='sku',
),
migrations.RemoveField(
model_name='product',
name='stripe_id',
),
migrations.RemoveField(
model_name='product',
name='weight',
),
migrations.AddField(
model_name='product',
name='checkout_limit',
field=models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.DeleteModel(
name='ShippingMethod',
),
migrations.AddField(
model_name='productvariant',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.product'),
),
migrations.AddField(
model_name='productoption',
name='product',
field=models.ManyToManyField(related_name='options', to='core.Product'),
),
migrations.AddField(
model_name='product',
name='category',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.productcategory'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 4.0.2 on 2022-09-07 21:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0011_productcategory_productoption_productvariant_and_more'),
]
operations = [
migrations.AlterField(
model_name='productvariant',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='variants', to='core.product'),
),
]

View File

@ -1,38 +0,0 @@
# Generated by Django 4.0.2 on 2022-10-01 18:45
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0012_alter_productvariant_product'),
]
operations = [
migrations.RenameField(
model_name='order',
old_name='total_net_amount',
new_name='subtotal_amount',
),
migrations.RemoveField(
model_name='orderline',
name='product',
),
migrations.AddField(
model_name='order',
name='coupon_amount',
field=models.CharField(blank=True, max_length=255),
),
migrations.AddField(
model_name='order',
name='total_amount',
field=models.DecimalField(decimal_places=2, default=0, max_digits=10),
),
migrations.AddField(
model_name='orderline',
name='variant',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_lines', to='core.productvariant'),
),
]

View File

@ -1,22 +0,0 @@
# Generated by Django 4.0.2 on 2022-10-13 01:23
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0013_rename_total_net_amount_order_subtotal_amount_and_more'),
]
operations = [
migrations.AlterModelOptions(
name='productvariant',
options={'ordering': ['weight']},
),
migrations.RenameField(
model_name='productoption',
old_name='product',
new_name='products',
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 4.0.2 on 2022-10-15 22:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0014_alter_productvariant_options_and_more'),
]
operations = [
migrations.AddField(
model_name='productcategory',
name='main_product',
field=models.BooleanField(default=True),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 4.0.2 on 2022-10-15 22:15
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0015_productcategory_main_product'),
]
operations = [
migrations.RenameField(
model_name='productcategory',
old_name='main_product',
new_name='main_category',
),
]

View File

@ -272,6 +272,9 @@ class ShippingRate(models.Model):
null=True null=True
) )
def get_absolute_url(self):
return reverse('dashboard:rate-detail', kwargs={'pk': self.pk})
def __str__(self): def __str__(self):
return f'{self.shipping_provider}: {self.name} ({self.min_order_weight}{self.max_order_weight})' return f'{self.shipping_provider}: {self.name} ({self.min_order_weight}{self.max_order_weight})'

View File

@ -8,7 +8,9 @@ from django.db import models
from django.conf import settings from django.conf import settings
from . import OrderStatus, TransactionStatus from . import OrderStatus, TransactionStatus
from .models import Product, Order, OrderLine, Transaction, TrackingNumber from .models import (
Product, ProductVariant, Order, OrderLine, Transaction, TrackingNumber
)
from .tasks import ( from .tasks import (
send_order_confirmation_email, send_order_confirmation_email,
send_order_shipped_email send_order_shipped_email
@ -17,33 +19,33 @@ from .tasks import (
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@receiver(post_save, sender=Product, dispatch_uid="product_created") # @receiver(post_save, sender=ProductVariant, dispatch_uid='variant_created')
def product_saved(sender, instance, created, **kwargs): # def variant_saved(sender, instance, created, **kwargs):
logger.info('Product was saved') # logger.info('Product was saved')
if created or not instance.stripe_id: # if created or not instance.stripe_id:
stripe.api_key = settings.STRIPE_API_KEY # stripe.api_key = settings.STRIPE_API_KEY
prod_response = stripe.Product.create( # prod_response = stripe.Product.create(
name=instance.name, # name=instance.product.name + ': ' + instance.name,
description=instance.description # description=instance.product.description
) # )
price_response = stripe.Price.create( # price_response = stripe.Price.create(
unit_amount=int(instance.price * 100), # unit_amount=int(instance.price * 100),
currency=settings.DEFAULT_CURRENCY, # currency=settings.DEFAULT_CURRENCY,
product=prod_response['id'] # product=prod_response['id']
) # )
instance.stripe_id = prod_response['id'] # instance.stripe_id = prod_response['id']
instance.stripe_price_id = price_response['id'] # instance.stripe_price_id = price_response['id']
instance.save() # instance.save()
else: # else:
stripe.Product.modify( # stripe.Product.modify(
instance.stripe_id, # instance.stripe_id,
name=instance.name, # name=instance.product.name + ': ' + instance.name,
description=instance.description # description=instance.product.description
) # )
stripe.Price.modify( # stripe.Price.modify(
instance.stripe_price_id, # instance.stripe_price_id,
unit_amount=int(instance.price * 100) # unit_amount=int(instance.price * 100)
) # )
@receiver(post_save, sender=Order, dispatch_uid="order_created") @receiver(post_save, sender=Order, dispatch_uid="order_created")

View File

@ -15,6 +15,7 @@ SHIP_ORDER_TEMPLATE = 'storefront/order_shipped'
ORDER_CANCEl_TEMPLATE = 'storefront/order_cancel' ORDER_CANCEl_TEMPLATE = 'storefront/order_cancel'
ORDER_REFUND_TEMPLATE = 'storefront/order_refund' ORDER_REFUND_TEMPLATE = 'storefront/order_refund'
@shared_task(name='send_order_confirmation_email') @shared_task(name='send_order_confirmation_email')
def send_order_confirmation_email(order): def send_order_confirmation_email(order):
send_templated_mail( send_templated_mail(
@ -26,6 +27,7 @@ def send_order_confirmation_email(order):
logger.info(f"Order confirmation email sent to {order['email']}") logger.info(f"Order confirmation email sent to {order['email']}")
@shared_task(name='send_order_shipped_email') @shared_task(name='send_order_shipped_email')
def send_order_shipped_email(data): def send_order_shipped_email(data):
send_templated_mail( send_templated_mail(