feat: cart detail leads to order creation
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
# Generated by Django 5.1.3 on 2024-12-31 09:48
|
||||
|
||||
import uuid
|
||||
from decimal import Decimal
|
||||
# Generated by Django 5.1.3 on 2025-01-02 13:36
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import uuid
|
||||
from decimal import Decimal
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -894,4 +893,51 @@ class Migration(migrations.Migration):
|
||||
"ordering": ("-date",),
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="WishlistedProduct",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"creation_date",
|
||||
models.DateTimeField(
|
||||
auto_now_add=True, verbose_name="fecha de creación"
|
||||
),
|
||||
),
|
||||
(
|
||||
"last_modification_date",
|
||||
models.DateTimeField(
|
||||
auto_now=True, verbose_name="fecha de última modificación"
|
||||
),
|
||||
),
|
||||
(
|
||||
"product",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="shop.product",
|
||||
verbose_name="producto",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="usuario",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "productos deseados",
|
||||
"verbose_name_plural": "productos deseados",
|
||||
"unique_together": {("user", "product")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
# Generated by Django 5.1.3 on 2025-01-02 09:35
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("shop", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="WishlistedProduct",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"creation_date",
|
||||
models.DateTimeField(
|
||||
auto_now_add=True, verbose_name="fecha de creación"
|
||||
),
|
||||
),
|
||||
(
|
||||
"last_modification_date",
|
||||
models.DateTimeField(
|
||||
auto_now=True, verbose_name="fecha de última modificación"
|
||||
),
|
||||
),
|
||||
(
|
||||
"product",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="shop.product",
|
||||
verbose_name="producto",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="usuario",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "productos deseados",
|
||||
"verbose_name_plural": "productos deseados",
|
||||
},
|
||||
),
|
||||
]
|
||||
+10
-7
@@ -122,11 +122,7 @@ class Product(TimestampedModel):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def save(
|
||||
self,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
self.slug = slugify(self.name)[:128]
|
||||
super().save(*args, **kwargs)
|
||||
@@ -362,7 +358,7 @@ class Order(TimestampedModel):
|
||||
|
||||
user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name=_("cliente"))
|
||||
|
||||
# Billing information
|
||||
# Datos de facturación
|
||||
billing_address = models.CharField(
|
||||
max_length=255, blank=False, verbose_name=_("dirección de facturación")
|
||||
)
|
||||
@@ -379,7 +375,7 @@ class Order(TimestampedModel):
|
||||
max_length=32, blank=False, verbose_name=_("código postal de facturación")
|
||||
)
|
||||
|
||||
# Shipping information
|
||||
# Datos de envío
|
||||
shipping_address = models.CharField(
|
||||
max_length=255, blank=False, verbose_name=_("dirección")
|
||||
)
|
||||
@@ -499,6 +495,9 @@ class CustomerAddress(models.Model):
|
||||
default = models.BooleanField(default=True, verbose_name=_("por defecto"))
|
||||
hidden = models.BooleanField(default=False, db_index=True, verbose_name=_("oculto"))
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.full_name} - {self.address}, {self.address_zip}, {self.address_state} - {self.address_country}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("dirección de cliente")
|
||||
verbose_name_plural = _("direcciones de cliente")
|
||||
@@ -529,3 +528,7 @@ class WishlistedProduct(TimestampedModel):
|
||||
class Meta:
|
||||
verbose_name = _("productos deseados")
|
||||
verbose_name_plural = _("productos deseados")
|
||||
unique_together = (
|
||||
"user",
|
||||
"product",
|
||||
)
|
||||
|
||||
+3
-2
@@ -88,6 +88,7 @@ def create_order_from_cart(
|
||||
shipping_state=shipping_address.address_state,
|
||||
shipping_country=shipping_address.address_country,
|
||||
shipping_zip=shipping_address.address_zip,
|
||||
user=cart.user,
|
||||
)
|
||||
|
||||
for item in cart.items.all():
|
||||
@@ -95,7 +96,7 @@ def create_order_from_cart(
|
||||
price: ProductPrice = product.price
|
||||
base_total = price.price * item.quantity
|
||||
tax_value = price.tax.value
|
||||
taxes = base_total * (tax_value / 100)
|
||||
taxes = base_total * tax_value / Decimal(100)
|
||||
total = base_total + taxes
|
||||
|
||||
OrderLine.objects.create(
|
||||
@@ -119,7 +120,7 @@ def add_shipping_order_line(order, shipping_method):
|
||||
shipping_price: ProductPrice = shipping_method.shipping_product.price
|
||||
shipping_base_total = shipping_price.price
|
||||
shipping_tax_value = shipping_price.tax.value
|
||||
shipping_taxes = shipping_base_total * (shipping_tax_value / 100)
|
||||
shipping_taxes = shipping_base_total * (shipping_tax_value / Decimal(100))
|
||||
shipping_total = shipping_base_total + shipping_taxes
|
||||
|
||||
OrderLine.objects.create(
|
||||
|
||||
Reference in New Issue
Block a user