categorias-productos #51 #52

Open
mono wants to merge 13 commits from feat/51-categorias-productos into main
2 changed files with 34 additions and 1 deletions
Showing only changes of commit 436f5300fa - Show all commits

View File

@@ -49,7 +49,15 @@ class Product(models.Model):
"price_list": product.price,
"uom": product.measuring_unit,
"external_id": product.external_id,
"categories": [c.name for c in product.categories.all()],
"categories": [
{
"id": c.id,
"name": c.name,
"alternative_name": c.alternative_name,
"active": c.active,
}
for c in product.categories.all()
],
}
products_list.append(rproduct)
return products_list

View File

@@ -74,4 +74,29 @@ class TestProductCategorySerializers(TestCase):
"active": True,
}
],
)
def test_product_to_list_incluye_categorias_anidadas(self):
category = ProductCategory.objects.create(
name="Bebidas", external_id="8", alternative_name="Jugos"
)
product = Product.objects.create(
name="Jugo de naranja",
price=2500,
measuring_unit="UNIT",
external_id="10",
)
product.categories.add(category)
data = Product.to_list()
self.assertEqual(
data[0]["categories"],
[
{
"id": category.pk,
"name": "Bebidas",
"alternative_name": "Jugos",
"active": True,
}
],
)