Feat: enviando las categorias en la lista de productos.
This commit is contained in:
parent
ef0c0c52db
commit
252720b324
@ -17,13 +17,14 @@ class TestProducts(TestCase):
|
|||||||
example_csv = os.path.join(app_dir, 'example_products.csv')
|
example_csv = os.path.join(app_dir, 'example_products.csv')
|
||||||
products_in_example = 3
|
products_in_example = 3
|
||||||
with open(example_csv, 'rb') as csv:
|
with open(example_csv, 'rb') as csv:
|
||||||
response = self.client.post(
|
self.client.post(
|
||||||
"/don_confiao/importar_productos",
|
"/don_confiao/importar_productos",
|
||||||
{"csv_file": csv}
|
{"csv_file": csv}
|
||||||
)
|
)
|
||||||
products_response = self.client.get("/don_confiao/productos")
|
products_response = self.client.get("/don_confiao/productos")
|
||||||
products = json.loads(products_response.content.decode('utf-8'))
|
all_products = json.loads(products_response.content.decode('utf-8'))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(products),
|
len(all_products),
|
||||||
products_in_example
|
products_in_example
|
||||||
)
|
)
|
||||||
|
self.assertIn("Aceites", all_products[0]["categories"])
|
||||||
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
|||||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
|
|
||||||
from .models import Sale, Product
|
from .models import Sale, Product, ProductCategory
|
||||||
from .forms import ImportProductsForm
|
from .forms import ImportProductsForm
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
@ -32,7 +32,7 @@ def products(request):
|
|||||||
"name": product.name,
|
"name": product.name,
|
||||||
"price_list": product.price,
|
"price_list": product.price,
|
||||||
"uom": product.measuring_unit,
|
"uom": product.measuring_unit,
|
||||||
"category": ""#.join('&', [c for c in product.categories])
|
"categories": [c.name for c in product.categories.all()]
|
||||||
}
|
}
|
||||||
rproducts.append(rproduct)
|
rproducts.append(rproduct)
|
||||||
|
|
||||||
@ -64,3 +64,10 @@ def handle_import_products_file(csv_file):
|
|||||||
product.price = row['precio']
|
product.price = row['precio']
|
||||||
product.measuring_unit = row['unidad']
|
product.measuring_unit = row['unidad']
|
||||||
product.save()
|
product.save()
|
||||||
|
|
||||||
|
categories = [n.strip for n in row["categorias"].split("&")]
|
||||||
|
for category in categories:
|
||||||
|
category_model, _ = ProductCategory.objects.get_or_create(
|
||||||
|
name=category
|
||||||
|
)
|
||||||
|
product.categories.add(category_model)
|
||||||
|
Loading…
Reference in New Issue
Block a user