Convert stock and price to numeric types in BulkUploadView
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 28s

This commit is contained in:
vickytechkey 2026-08-12 20:53:44 +05:30
parent b0f8a869b6
commit 707281c17e

View file

@ -344,13 +344,23 @@ class BulkUploadView(APIView):
if not image_url:
image_url = p_data.get('image', 'https://images.unsplash.com/photo-1544022613-e87ca75a784a?auto=format&fit=crop&q=80&w=100')
try:
stock_val = int(p_data.get('stock') or 0)
except (TypeError, ValueError):
stock_val = 0
try:
price_val = float(p_data.get('price') or 0.00)
except (TypeError, ValueError):
price_val = 0.00
Product.objects.filter(sku=sku).delete()
product = Product.objects.create(
supplier=user,
title=p_data.get('title'),
category=p_data.get('category'),
price=p_data.get('price'),
stock=p_data.get('stock'),
price=price_val,
stock=stock_val,
sku=sku,
image=image_url
)