diff --git a/config/settings/base.py b/config/settings/base.py index 90fd365..7ba77fa 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -15,7 +15,6 @@ DJANGO_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - # 'django.contrib.gis', -- Requires gdal-bin ] THIRD_PARTY_APPS = [ diff --git a/config/urls.py b/config/urls.py index 3a44622..436870f 100644 --- a/config/urls.py +++ b/config/urls.py @@ -16,4 +16,4 @@ urlpatterns = [ if settings.DEBUG: urlpatterns.append(path("__debug__/", include(debug_toolbar.urls))) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - urlpatterns += [path('silk/', include('silk.urls'))] + urlpatterns += [path("silk/", include("silk.urls"))] diff --git a/shop/migrations/0004_productbatch_provider.py b/shop/migrations/0004_productbatch_provider.py new file mode 100644 index 0000000..4f32db3 --- /dev/null +++ b/shop/migrations/0004_productbatch_provider.py @@ -0,0 +1,25 @@ +# Generated by Django 5.0.6 on 2024-05-14 15:54 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("shop", "0003_provider_productbatch"), + ] + + operations = [ + migrations.AddField( + model_name="productbatch", + name="provider", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="shop.provider", + verbose_name="Proveedor", + ), + ), + ] diff --git a/shop/models.py b/shop/models.py index b35ae0b..1608931 100644 --- a/shop/models.py +++ b/shop/models.py @@ -92,6 +92,13 @@ class ProductBatch(models.Model): expiration_date = models.DateField( blank=True, null=True, verbose_name=_("Fecha de caducidad / consumo preferente") ) + provider = models.ForeignKey( + "shop.Provider", + on_delete=models.SET_NULL, + blank=True, + null=True, + verbose_name=_("Proveedor"), + ) def __str__(self): return f"{self.code} - {self.product.name} - {self.quantity}" diff --git a/shop/tests/test_api_product_batches.py b/shop/tests/test_api_product_batches.py index 11cb160..965095d 100644 --- a/shop/tests/test_api_product_batches.py +++ b/shop/tests/test_api_product_batches.py @@ -4,7 +4,7 @@ from rest_framework import status from rest_framework.test import APITestCase from config.tests.mixins import TestUserAuthenticationMixin -from shop.models import Product +from shop.models import Product, Provider class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): @@ -13,6 +13,19 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): def setUp(self): self.create_user() + def create_provider(self): + return Provider.objects.create( + vat_id="11111111H", + name="Mandalorians", + email="din@djarin.com", + phone="612345678", + address="Mandalore", + city="Mandalore", + state="Mandalore", + country="Mandalore", + zip="12345", + ) + def create_product(self): self.product = Product.objects.create( name="Papafritas", @@ -24,9 +37,15 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): def test_create_retrieve_product_batch(self): self.login() self.create_product() + provider = self.create_provider() response = self.client.post( "/api/v1/shop/product-batches/", - {"code": "B00001", "product": self.product.pk, "quantity": "5"}, + { + "code": "B00001", + "product": self.product.pk, + "quantity": "5", + "provider": provider.pk, + }, ) assert response.status_code == status.HTTP_201_CREATED pk = response.data.get("id") @@ -34,12 +53,19 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): response = self.client.get(f"/api/v1/shop/product-batches/{pk}/") assert response.status_code == status.HTTP_200_OK - def test_create_update_tax(self): + def test_create_update_product_batch(self): self.login() self.create_product() + provider = self.create_provider() + response = self.client.post( "/api/v1/shop/product-batches/", - {"code": "B00001", "product": self.product.pk, "quantity": "5"}, + { + "code": "B00001", + "product": self.product.pk, + "quantity": "5", + "provider": provider.pk, + }, ) assert response.status_code == status.HTTP_201_CREATED pk = response.data.get("id")