feat: added provider to product batch
This commit is contained in:
@@ -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",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -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}"
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user