diff --git a/shop/migrations/0001_initial.py b/shop/migrations/0001_initial.py index 77c10dc..708d53f 100644 --- a/shop/migrations/0001_initial.py +++ b/shop/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.3 on 2025-01-02 13:36 +# Generated by Django 5.1.3 on 2025-01-03 11:17 import django.db.models.deletion import django.utils.timezone @@ -275,6 +275,7 @@ class Migration(migrations.Migration): verbose_name="tipo de dirección", ), ), + ("email", models.EmailField(max_length=254, verbose_name="e-mail")), ( "default", models.BooleanField(default=True, verbose_name="por defecto"), @@ -354,6 +355,12 @@ class Migration(migrations.Migration): verbose_name="total", ), ), + ( + "email", + models.EmailField( + blank=True, max_length=254, verbose_name="e-mail" + ), + ), ( "billing_address", models.CharField( @@ -411,6 +418,8 @@ class Migration(migrations.Migration): ( "user", models.ForeignKey( + blank=True, + null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name="cliente", diff --git a/shop/models.py b/shop/models.py index 9bd07b0..472c55c 100644 --- a/shop/models.py +++ b/shop/models.py @@ -356,7 +356,8 @@ class Order(TimestampedModel): default=Decimal("0"), max_digits=13, decimal_places=2, verbose_name=_("total") ) - user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name=_("cliente")) + user = models.ForeignKey(User, blank=True, null=True, on_delete=models.PROTECT, verbose_name=_("cliente")) + email = models.EmailField(blank=True, verbose_name=_('e-mail')) # Datos de facturación billing_address = models.CharField( @@ -492,11 +493,12 @@ class CustomerAddress(models.Model): default=Types.SHIPPING, verbose_name=_("tipo de dirección"), ) + email = models.EmailField(blank=False, null=False, verbose_name=_("e-mail")) 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}' + return f"{self.full_name} - {self.address}, {self.address_zip}, {self.address_state} - {self.address_country}" class Meta: verbose_name = _("dirección de cliente") diff --git a/shop/utils.py b/shop/utils.py index 701e0b7..07c6f4b 100644 --- a/shop/utils.py +++ b/shop/utils.py @@ -73,22 +73,36 @@ def delete_product_batch(batch: ProductBatch): def create_order_from_cart( cart: Cart, - billing_address: CustomerAddress, - shipping_address: CustomerAddress, shipping_method: ShippingMethod, + billing_address_full_name="", + billing_address_address="", + billing_address_town="", + billing_address_state="", + billing_address_country="", + billing_address_zip="", + shipping_address_full_name="", + shipping_address_address="", + shipping_address_town="", + shipping_address_state="", + shipping_address_country="", + shipping_address_zip="", + shipping_address_phone="", + email="", ): order = Order.objects.create( - billing_address=billing_address.address, - billing_city=billing_address.address_town, - billing_state=billing_address.address_state, - billing_country=billing_address.address_country, - billing_zip=billing_address.address_zip, - shipping_address=shipping_address.address, - shipping_city=shipping_address.address_town, - shipping_state=shipping_address.address_state, - shipping_country=shipping_address.address_country, - shipping_zip=shipping_address.address_zip, + billing_address=f'{billing_address_full_name} {billing_address_address}', + billing_city=billing_address_town, + billing_state=billing_address_state, + billing_country=billing_address_country, + billing_zip=billing_address_zip, + contact_phone=shipping_address_phone, + shipping_address=f'{shipping_address_address} {shipping_address_full_name}', + shipping_city=shipping_address_town, + shipping_state=shipping_address_state, + shipping_country=shipping_address_country, + shipping_zip=shipping_address_zip, user=cart.user, + email=email, ) for item in cart.items.all(): diff --git a/web/forms.py b/web/forms.py index 9f412c1..4865cca 100644 --- a/web/forms.py +++ b/web/forms.py @@ -1,6 +1,8 @@ from django import forms from django.forms import widgets +from shop.models import CustomerAddress + class CartItemForm(forms.Form): """ @@ -14,6 +16,24 @@ class CartItemForm(forms.Form): class CreateOrderForm(forms.Form): - shipping_address = forms.IntegerField() - billing_address = forms.IntegerField() + email = forms.CharField(max_length=254) + + shipping_address_full_name = forms.CharField(max_length=128, required=True) + shipping_address = forms.CharField(max_length=128, required=True) + shipping_address_town = forms.CharField(max_length=64, required=True) + shipping_address_zip = forms.CharField(max_length=16, required=True) + shipping_address_state = forms.CharField(max_length=64, required=True) + shipping_address_country = forms.CharField(max_length=64, required=True) + shipping_address_phone = forms.CharField(max_length=16, required=False) + + same_as_shipping = forms.BooleanField(required=False) + + billing_address_full_name = forms.CharField(max_length=128, required=True) + billing_address = forms.CharField(max_length=128, required=True) + billing_address_town = forms.CharField(max_length=64, required=True) + billing_address_zip = forms.CharField(max_length=16, required=True) + billing_address_state = forms.CharField(max_length=64, required=True) + billing_address_country = forms.CharField(max_length=64, required=True) + billing_address_phone = forms.CharField(max_length=16, required=False) + shipping_method = forms.IntegerField() diff --git a/web/templates/components/cart/cart.html b/web/templates/components/cart/cart.html index 4268d2d..e016a47 100644 --- a/web/templates/components/cart/cart.html +++ b/web/templates/components/cart/cart.html @@ -78,27 +78,179 @@ {% translate 'Dirección de envío' %} - {% for address in shipping_addresses %} - - - {% endfor %} +