feat: removed customer modl

This commit is contained in:
2024-12-07 11:34:00 +01:00
parent 48d39f55ba
commit ef91ef9090
10 changed files with 4 additions and 196 deletions
-10
View File
@@ -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",)
-2
View File
@@ -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<product_id>[^/.]+)/prices", ProductPriceViewSet)
-18
View File
@@ -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
-8
View File
@@ -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()
+1 -50
View File
@@ -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=[
-27
View File
@@ -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,
-66
View File
@@ -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"
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -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()
+1 -13
View File
@@ -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,