fix: evitando duplicado de productos en la importacion.

This commit is contained in:
2024-06-29 16:57:50 -05:00
parent 84c295e7de
commit 64a9b75ad7
6 changed files with 37 additions and 6 deletions

View File

@@ -59,8 +59,10 @@ def handle_import_products_file(csv_file):
data = io.StringIO(csv_file.read().decode('utf-8'))
reader = csv.DictReader(data, quotechar='"')
for row in reader:
product = Product()
product.name = row['producto']
product, _ = Product.objects.get_or_create(
name=row['producto'],
defaults={'price': row['precio']}
)
product.price = row['precio']
product.measuring_unit = row['unidad']
product.save()