diff --git a/src/accounts/models.py b/src/accounts/models.py index 70b657d..1647c59 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -18,7 +18,12 @@ class Address(models.Model): postal_code = models.CharField(max_length=20, blank=True) def __str__(self): - return f'{self.street_address_1} — {self.city}' + return f""" + {first_name} {last_name} + {street_address_1} + {street_address_2} + {city}, {state}, {postal_code} + """ class User(AbstractUser): diff --git a/src/core/__init__.py b/src/core/__init__.py index cf1d22b..f8e65f7 100644 --- a/src/core/__init__.py +++ b/src/core/__init__.py @@ -127,3 +127,20 @@ class CoffeeGrind: (PERCOLATOR, 'Percolator'), (CAFE_STYLE, 'BLTC cafe pour over') ] + + +def build_usps_rate_request(weight, container, zip_destination): + return \ + { + 'service': ShippingService.PRIORITY_COMMERCIAL, + 'zip_origination': settings.DEFAULT_ZIP_ORIGINATION, + 'zip_destination': zip_destination, + 'pounds': '0', + 'ounces': weight, + 'container': container, + 'width': '', + 'length': '', + 'height': '', + 'girth': '', + 'machinable': 'TRUE' + } diff --git a/src/core/admin.py b/src/core/admin.py index 6e41d90..324c630 100644 --- a/src/core/admin.py +++ b/src/core/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from .models import ( + SiteSettings, ProductCategory, Product, ProductPhoto, @@ -13,6 +14,7 @@ from .models import ( OrderLine, ) +admin.site.register(SiteSettings) admin.site.register(ProductCategory) admin.site.register(Product) admin.site.register(ProductPhoto) diff --git a/src/core/fixtures/orders.json b/src/core/fixtures/orders.json index f0c17c2..5b40378 100644 --- a/src/core/fixtures/orders.json +++ b/src/core/fixtures/orders.json @@ -10,7 +10,7 @@ "shipping_method": null, "coupon": null, "shipping_total": "9.55", - "total_net_amount": "13.40", + "subtotal_amount": "13.40", "weight": "0.0:oz", "created_at": "2022-03-15T17:18:59.584Z", "updated_at": "2022-03-15T17:18:59.584Z" @@ -26,7 +26,7 @@ "shipping_method": null, "coupon": null, "shipping_total": "9.55", - "total_net_amount": "13.40", + "subtotal_amount": "13.40", "weight": "0.0:oz", "created_at": "2022-03-15T17:22:18.440Z", "updated_at": "2022-03-15T17:22:18.440Z" @@ -42,7 +42,7 @@ "shipping_method": null, "coupon": null, "shipping_total": "9.55", - "total_net_amount": "13.40", + "subtotal_amount": "13.40", "weight": "0.0:oz", "created_at": "2022-03-15T17:26:27.869Z", "updated_at": "2022-03-15T17:26:27.869Z" diff --git a/src/core/migrations/0013_rename_total_net_amount_order_subtotal_amount_and_more.py b/src/core/migrations/0013_rename_total_net_amount_order_subtotal_amount_and_more.py new file mode 100644 index 0000000..975ad85 --- /dev/null +++ b/src/core/migrations/0013_rename_total_net_amount_order_subtotal_amount_and_more.py @@ -0,0 +1,38 @@ +# 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'), + ), + ] diff --git a/src/core/models.py b/src/core/models.py index e1ed7bd..aeff19c 100644 --- a/src/core/models.py +++ b/src/core/models.py @@ -24,7 +24,8 @@ from . import ( TransactionStatus, OrderStatus, ShippingProvider, - ShippingContainer + ShippingContainer, + build_usps_rate_request ) from .weight import WeightUnits, zero_weight @@ -77,13 +78,6 @@ class ProductCategory(models.Model): verbose_name_plural = 'Product Categories' -class ProductManager(models.Manager): - def get_queryset(self): - return super().get_queryset().annotate( - num_ordered=models.Sum('order_lines__quantity') - ) - - class Product(models.Model): category = models.ForeignKey( ProductCategory, @@ -105,8 +99,6 @@ class Product(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - objects = ProductManager() - def __str__(self): return self.name @@ -126,6 +118,13 @@ class Product(models.Model): ordering = ['sorting', 'name'] +class ProductVariantManager(models.Manager): + def get_queryset(self): + return super().get_queryset().annotate( + num_ordered=models.Sum('order_lines__quantity') + ) + + class ProductVariant(models.Model): product = models.ForeignKey( Product, @@ -157,6 +156,8 @@ class ProductVariant(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) + objects = ProductVariantManager() + def __str__(self): return f'{self.product}: {self.name}' @@ -296,7 +297,7 @@ class OrderManager(models.Manager): class Order(models.Model): customer = models.ForeignKey( User, - related_name="orders", + related_name='orders', on_delete=models.SET_NULL, null=True ) @@ -319,7 +320,6 @@ class Order(models.Model): null=True, on_delete=models.SET_NULL ) - coupon = models.ForeignKey( Coupon, related_name='orders', @@ -327,19 +327,22 @@ class Order(models.Model): blank=True, null=True ) - + subtotal_amount = models.DecimalField( + max_digits=10, + decimal_places=2, + default=0 + ) + coupon_amount = models.CharField(max_length=255, blank=True) shipping_total = models.DecimalField( max_digits=5, decimal_places=2, default=0 ) - - total_net_amount = models.DecimalField( + total_amount = models.DecimalField( max_digits=10, decimal_places=2, default=0 ) - weight = MeasurementField( measurement=Weight, unit_choices=WeightUnits.CHOICES, @@ -361,11 +364,11 @@ class Order(models.Model): if self.coupon.discount_value_type == DiscountValueType.FIXED: return self.coupon.discount_value elif self.coupon.discount_value_type == DiscountValueType.PERCENTAGE: - return (self.coupon.discount_value / Decimal('100')) * self.total_net_amount + return (self.coupon.discount_value / Decimal('100')) * self.subtotal_amount return Decimal('0') def get_total_price_after_discount(self): - return round((self.total_net_amount - self.get_discount()) + self.shipping_total, 2) + return round((self.subtotal_amount - self.get_discount()) + self.shipping_total, 2) def get_absolute_url(self): return reverse('dashboard:order-detail', kwargs={'pk': self.pk}) @@ -395,13 +398,13 @@ class Transaction(models.Model): class OrderLine(models.Model): order = models.ForeignKey( Order, - related_name="lines", + related_name='lines', editable=False, on_delete=models.CASCADE ) - product = models.ForeignKey( - Product, - related_name="order_lines", + variant = models.ForeignKey( + ProductVariant, + related_name='order_lines', on_delete=models.SET_NULL, blank=True, null=True, @@ -410,20 +413,17 @@ class OrderLine(models.Model): quantity_fulfilled = models.IntegerField( validators=[MinValueValidator(0)], default=0 ) - customer_note = models.TextField(blank=True, default="") - + customer_note = models.TextField(blank=True, default='') currency = models.CharField( max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH, default=settings.DEFAULT_CURRENCY, ) - unit_price = models.DecimalField( max_digits=settings.DEFAULT_MAX_DIGITS, decimal_places=settings.DEFAULT_DECIMAL_PLACES, ) - tax_rate = models.DecimalField( - max_digits=5, decimal_places=2, default=Decimal("0.0") + max_digits=5, decimal_places=2, default=Decimal('0.0') ) def get_total(self): diff --git a/src/dashboard/templates/dashboard/customer_detail.html b/src/dashboard/templates/dashboard/customer_detail.html index aa00d24..3fefbbf 100644 --- a/src/dashboard/templates/dashboard/customer_detail.html +++ b/src/dashboard/templates/dashboard/customer_detail.html @@ -71,7 +71,7 @@ {{order.get_status_display}} - ${{order.total_net_amount}} + ${{order.total_amount}} {% empty %} No orders diff --git a/src/dashboard/templates/dashboard/order_detail.html b/src/dashboard/templates/dashboard/order_detail.html index ac5f882..a457290 100644 --- a/src/dashboard/templates/dashboard/order_detail.html +++ b/src/dashboard/templates/dashboard/order_detail.html @@ -26,10 +26,10 @@ {% for item in order.lines.all %}
- Subtotal: ${{order.total_net_amount}}
+ Subtotal: ${{order.subtotal_amount}}
{% if order.coupon %}
Discount: {{order.coupon.discount_value}} {{order.coupon.get_discount_value_type_display}}
{% endif %}
diff --git a/src/dashboard/templates/dashboard/product_detail.html b/src/dashboard/templates/dashboard/product_detail.html
index 9fae9a5..e8a2ce5 100644
--- a/src/dashboard/templates/dashboard/product_detail.html
+++ b/src/dashboard/templates/dashboard/product_detail.html
@@ -15,15 +15,33 @@
Category: {{ product.category }}
{{product.description}}
-${{product.price}}
-{{product.weight.oz}} oz
+Checkout limit: {{ product.checkout_limit }}
Visible in listings: {{product.visible_in_listings|yesno:"Yes,No"}}
-Stripe ID: {{ product.stripe_id }}
+Sorting: {{ product.sorting }}
Ordered {{product.num_ordered|default_if_none:"0"}} time{{ product.num_ordered|default_if_none:"0"|pluralize }}.
name: {{ variant.name }}
+sku: {{ variant.sku }}
+stripe_id: {{ variant.stripe_id }}
+price: ${{ variant.price }}
+weight: {{ variant.weight }}
+track_inventory: {{ variant.track_inventory }}
+stock: {{ variant.stock }}
+{{ key|get_grind_display }}
-
{{ key }}: {{ value }}
{% endfor %} + +${{item.price}}
+
+ ${{ item.variant.price }}
+ {% if cart.coupon and cart.coupon.type == 'specific_product' and product in cart.coupon.products.all %}
+
Coupon: {{ cart.coupon.name }} ({{cart.coupon.discount_value}} {{cart.coupon.get_discount_value_type_display}})
+ {% endif %}
+
diff --git a/src/storefront/templates/storefront/order_detail.html b/src/storefront/templates/storefront/order_detail.html index 7c0d48c..d5eb3ca 100644 --- a/src/storefront/templates/storefront/order_detail.html +++ b/src/storefront/templates/storefront/order_detail.html @@ -21,12 +21,12 @@
| Subtotal | -${{order.total_net_amount}} | +${{order.subtotal}} |
| Subtotal | ${{cart.get_total_price|floatformat:"2"}} | |
| Coupon | {{cart.coupon.discount_value}} {{cart.coupon.get_discount_value_type_display}} | diff --git a/src/storefront/templates/storefront/product_detail.html b/src/storefront/templates/storefront/product_detail.html index 3594102..d88686f 100644 --- a/src/storefront/templates/storefront/product_detail.html +++ b/src/storefront/templates/storefront/product_detail.html @@ -21,9 +21,6 @@