From ef91ef9090c484d7d3420a413caf7dcf094d98bc Mon Sep 17 00:00:00 2001 From: Pablo Moreno Date: Sat, 7 Dec 2024 11:34:00 +0100 Subject: [PATCH] feat: removed customer modl --- shop/admin.py | 10 ----- shop/api/v1/routers.py | 2 - shop/api/v1/serializers.py | 18 -------- shop/api/v1/viewsets.py | 8 ---- shop/migrations/0001_initial.py | 51 +-------------------- shop/models.py | 27 ------------ shop/tests/api/test_api_customers.py | 66 ---------------------------- shop/tests/api/test_api_orders.py | 2 +- shop/tests/api/test_shop_models.py | 2 +- shop/utils.py | 14 +----- 10 files changed, 4 insertions(+), 196 deletions(-) delete mode 100644 shop/tests/api/test_api_customers.py diff --git a/shop/admin.py b/shop/admin.py index 90c936d..557e7b3 100644 --- a/shop/admin.py +++ b/shop/admin.py @@ -5,7 +5,6 @@ from shop.models import ( Brand, Cart, CartItem, - Customer, Order, OrderLine, Product, @@ -49,15 +48,6 @@ class TaxAdmin(ModelAdmin): ) -@admin.register(Customer) -class CustomerAdmin(ModelAdmin): - list_display = ( - "vat_id", - "first_name", - "last_name", - ) - - @admin.register(OrderLine) class OrderLineAdmin(ModelAdmin): autocomplete_fields = ("product",) diff --git a/shop/api/v1/routers.py b/shop/api/v1/routers.py index 3f351aa..55ad122 100644 --- a/shop/api/v1/routers.py +++ b/shop/api/v1/routers.py @@ -2,7 +2,6 @@ from rest_framework.routers import DefaultRouter from shop.api.v1.viewsets import ( BrandViewSet, - CustomerViewSet, OrderLineViewSet, OrderViewSet, ProductBatchViewSet, @@ -21,7 +20,6 @@ router = DefaultRouter() router.register("taxes", TaxViewSet) router.register("tags", TagViewSet) router.register("brands", BrandViewSet) -router.register("customers", CustomerViewSet) router.register("providers", ProviderViewSet) router.register("products", ProductViewSet) router.register("products/(?P[^/.]+)/prices", ProductPriceViewSet) diff --git a/shop/api/v1/serializers.py b/shop/api/v1/serializers.py index e0a4597..db6f95e 100644 --- a/shop/api/v1/serializers.py +++ b/shop/api/v1/serializers.py @@ -4,7 +4,6 @@ from rest_framework import serializers from files.api.v1.serializers import FileUploadSerializer, NoIDFileUploadSerializer from shop.models import ( Brand, - Customer, Order, OrderLine, Product, @@ -176,23 +175,6 @@ class ProductBatchSerializer(serializers.ModelSerializer): ) -class CustomerSerializer(serializers.ModelSerializer): - class Meta: - model = Customer - fields = ( - "id", - "vat_id", - "first_name", - "last_name", - "email", - "address", - "city", - "state", - "country", - "zip", - ) - - class ProviderSerializer(serializers.ModelSerializer): class Meta: model = Provider diff --git a/shop/api/v1/viewsets.py b/shop/api/v1/viewsets.py index 8149f71..f43e734 100644 --- a/shop/api/v1/viewsets.py +++ b/shop/api/v1/viewsets.py @@ -13,7 +13,6 @@ from shop.api.v1.serializers import ( BrandSerializer, CreateProductPriceSerializer, CreateProductSerializer, - CustomerSerializer, ListProductSerializer, OrderLineSerializer, OrderSerializer, @@ -28,7 +27,6 @@ from shop.api.v1.serializers import ( from shop.filters import ProductFilter from shop.models import ( Brand, - Customer, Order, OrderLine, Product, @@ -118,12 +116,6 @@ class ProductBatchViewSet(ModelViewSet): product.save() -class CustomerViewSet(ModelViewSet): - serializer_class = CustomerSerializer - queryset = Customer.objects.all() - permission_classes = (IsAdminUser,) - - class ProviderViewSet(ModelViewSet): serializer_class = ProviderSerializer queryset = Provider.objects.all() diff --git a/shop/migrations/0001_initial.py b/shop/migrations/0001_initial.py index ea2650e..75729a7 100644 --- a/shop/migrations/0001_initial.py +++ b/shop/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.3 on 2024-12-07 08:59 +# Generated by Django 5.1.3 on 2024-12-07 10:15 import django.db.models.deletion import django.utils.timezone @@ -54,55 +54,6 @@ class Migration(migrations.Migration): "verbose_name_plural": "marcas", }, ), - migrations.CreateModel( - name="Customer", - 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" - ), - ), - ( - "vat_id", - models.CharField( - max_length=32, - unique=True, - verbose_name="documento de identidad", - ), - ), - ("first_name", models.CharField(max_length=64, verbose_name="nombre")), - ( - "last_name", - models.CharField(max_length=64, verbose_name="apellidos"), - ), - ("email", models.EmailField(max_length=254, verbose_name="e-mail")), - ("address", models.CharField(max_length=255, verbose_name="dirección")), - ("city", models.CharField(max_length=64, verbose_name="ciudad")), - ("state", models.CharField(max_length=64, verbose_name="región")), - ("country", models.CharField(max_length=64, verbose_name="país")), - ("zip", models.CharField(max_length=32, verbose_name="código postal")), - ], - options={ - "verbose_name": "cliente", - "verbose_name_plural": "clientes", - }, - ), migrations.CreateModel( name="Provider", fields=[ diff --git a/shop/models.py b/shop/models.py index f505926..983313b 100644 --- a/shop/models.py +++ b/shop/models.py @@ -189,33 +189,6 @@ class Tax(TimestampedModel): ordering = ("id",) -class Customer(TimestampedModel): - vat_id = models.CharField( - max_length=32, - blank=False, - unique=True, - verbose_name=_("documento de identidad"), - ) - first_name = models.CharField(max_length=64, blank=False, verbose_name=_("nombre")) - last_name = models.CharField( - max_length=64, blank=False, verbose_name=_("apellidos") - ) - email = models.EmailField(blank=False, verbose_name=_("e-mail")) - - address = models.CharField(max_length=255, blank=False, verbose_name=_("dirección")) - city = models.CharField(max_length=64, blank=False, verbose_name=_("ciudad")) - state = models.CharField(max_length=64, blank=False, verbose_name=_("región")) - country = models.CharField(max_length=64, blank=False, verbose_name=_("país")) - zip = models.CharField(max_length=32, blank=False, verbose_name=_("código postal")) - - def __str__(self): - return f"{self.vat_id} - {self.first_name} {self.last_name}" - - class Meta: - verbose_name = _("cliente") - verbose_name_plural = _("clientes") - - class Provider(TimestampedModel): vat_id = models.CharField( max_length=32, diff --git a/shop/tests/api/test_api_customers.py b/shop/tests/api/test_api_customers.py deleted file mode 100644 index 85b8da3..0000000 --- a/shop/tests/api/test_api_customers.py +++ /dev/null @@ -1,66 +0,0 @@ -from rest_framework import status -from rest_framework.test import APITestCase - -from config.tests.mixins import TestUserAuthenticationMixin - - -class TestCustomersAPI(APITestCase, TestUserAuthenticationMixin): - model_name = "customer" - - def setUp(self): - self.create_user() - - def test_create_retrieve_customer(self): - self.login() - response = self.client.post( - f"/api/v1/shop/customers/", - { - "vat_id": "11111111H", - "first_name": "Darth", - "last_name": "Maull", - "email": "darth@maul.com", - "address": "Dathomir", - "city": "Dathomir", - "state": "Dathomir", - "country": "Dathomir", - "zip": "00001", - }, - ) - - assert response.status_code == status.HTTP_201_CREATED - pk = response.data.get("id") - response = self.client.get(f"/api/v1/shop/customers/{pk}/") - assert response.status_code == status.HTTP_200_OK - - def test_create_update_customer(self): - self.login() - response = self.client.post( - f"/api/v1/shop/customers/", - { - "vat_id": "11111111H", - "first_name": "Darth", - "last_name": "Maull", - "email": "darth@maul.com", - "address": "Dathomir", - "city": "Dathomir", - "state": "Dathomir", - "country": "Dathomir", - "zip": "00001", - }, - ) - - assert response.status_code == status.HTTP_201_CREATED - pk = response.data.get("id") - response = self.client.get(f"/api/v1/shop/customers/{pk}/") - assert response.status_code == status.HTTP_200_OK - - response = self.client.patch( - f"/api/v1/shop/customers/{pk}/", - { - "address": "Mandalore", - }, - ) - assert response.status_code == status.HTTP_200_OK - response = self.client.get(f"/api/v1/shop/customers/{pk}/") - assert response.status_code == status.HTTP_200_OK - assert response.data.get("address") == "Mandalore" diff --git a/shop/tests/api/test_api_orders.py b/shop/tests/api/test_api_orders.py index b7c8776..35ff34e 100644 --- a/shop/tests/api/test_api_orders.py +++ b/shop/tests/api/test_api_orders.py @@ -5,7 +5,7 @@ from rest_framework import status from rest_framework.test import APITestCase from config.tests.mixins import TestUserAuthenticationMixin -from shop.models import Product, ProductPrice, Tax, Customer, CustomerAddress +from shop.models import Product, ProductPrice, Tax, CustomerAddress User = get_user_model() diff --git a/shop/tests/api/test_shop_models.py b/shop/tests/api/test_shop_models.py index 9d6c22d..c7a3685 100644 --- a/shop/tests/api/test_shop_models.py +++ b/shop/tests/api/test_shop_models.py @@ -3,7 +3,7 @@ from decimal import Decimal from django.contrib.auth import get_user_model from rest_framework.test import APITestCase as TestCase -from shop.models import Customer, Product, ProductPrice, Tax, CustomerAddress +from shop.models import Product, ProductPrice, Tax, CustomerAddress from shop.utils import create_order, create_order_line_for_product User = get_user_model() diff --git a/shop/utils.py b/shop/utils.py index 9886507..bfcb16d 100644 --- a/shop/utils.py +++ b/shop/utils.py @@ -1,6 +1,6 @@ from decimal import Decimal -from shop.models import Customer, Order, OrderLine, Product, ProductBatch +from shop.models import Order, OrderLine, Product, ProductBatch from django.contrib.auth import get_user_model User = get_user_model() @@ -37,18 +37,6 @@ def create_order( shipping_country: str = "", shipping_zip: str = "", ) -> Order: - billing_address = billing_address if billing_address else customer.address - billing_city = billing_city if billing_city else customer.city - billing_state = billing_state if billing_state else customer.state - billing_country = billing_country if billing_country else customer.country - billing_zip = billing_zip if billing_zip else customer.zip - - shipping_address = shipping_address if shipping_address else billing_address - shipping_city = shipping_city if shipping_city else billing_city - shipping_state = shipping_state if shipping_state else billing_state - shipping_country = shipping_country if shipping_country else billing_country - shipping_zip = shipping_zip if shipping_zip else billing_zip - order = Order.objects.create( user=customer, billing_address=billing_address,