feat: added provider to product batch

This commit is contained in:
Pablo Moreno
2024-05-14 17:59:56 +02:00
parent efae21ee82
commit 3c25c115ca
5 changed files with 63 additions and 6 deletions
-1
View File
@@ -15,7 +15,6 @@ DJANGO_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
# 'django.contrib.gis', -- Requires gdal-bin
] ]
THIRD_PARTY_APPS = [ THIRD_PARTY_APPS = [
+1 -1
View File
@@ -16,4 +16,4 @@ urlpatterns = [
if settings.DEBUG: if settings.DEBUG:
urlpatterns.append(path("__debug__/", include(debug_toolbar.urls))) urlpatterns.append(path("__debug__/", include(debug_toolbar.urls)))
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [path('silk/', include('silk.urls'))] urlpatterns += [path("silk/", include("silk.urls"))]
@@ -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",
),
),
]
+7
View File
@@ -92,6 +92,13 @@ class ProductBatch(models.Model):
expiration_date = models.DateField( expiration_date = models.DateField(
blank=True, null=True, verbose_name=_("Fecha de caducidad / consumo preferente") 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): def __str__(self):
return f"{self.code} - {self.product.name} - {self.quantity}" return f"{self.code} - {self.product.name} - {self.quantity}"
+30 -4
View File
@@ -4,7 +4,7 @@ from rest_framework import status
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from config.tests.mixins import TestUserAuthenticationMixin from config.tests.mixins import TestUserAuthenticationMixin
from shop.models import Product from shop.models import Product, Provider
class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin): class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin):
@@ -13,6 +13,19 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin):
def setUp(self): def setUp(self):
self.create_user() 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): def create_product(self):
self.product = Product.objects.create( self.product = Product.objects.create(
name="Papafritas", name="Papafritas",
@@ -24,9 +37,15 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin):
def test_create_retrieve_product_batch(self): def test_create_retrieve_product_batch(self):
self.login() self.login()
self.create_product() self.create_product()
provider = self.create_provider()
response = self.client.post( response = self.client.post(
"/api/v1/shop/product-batches/", "/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 assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id") pk = response.data.get("id")
@@ -34,12 +53,19 @@ class TestProductBatchesAPI(APITestCase, TestUserAuthenticationMixin):
response = self.client.get(f"/api/v1/shop/product-batches/{pk}/") response = self.client.get(f"/api/v1/shop/product-batches/{pk}/")
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
def test_create_update_tax(self): def test_create_update_product_batch(self):
self.login() self.login()
self.create_product() self.create_product()
provider = self.create_provider()
response = self.client.post( response = self.client.post(
"/api/v1/shop/product-batches/", "/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 assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id") pk = response.data.get("id")