improvements to csv product loading
This commit is contained in:
@@ -187,16 +187,19 @@ def product_loader(csv_reader, user, company=None):
|
||||
for row in csv_reader:
|
||||
# trim strings
|
||||
for key in row:
|
||||
if row[key]:
|
||||
if 'imagen' in key or 'categoria' in key:
|
||||
row[key] = row[key].strip()
|
||||
elif key in ['precio', 'gastos-envio']:
|
||||
row[key] = Decimal(row[key][:-1].strip().replace(',','.'))
|
||||
try:
|
||||
if row[key]:
|
||||
if 'imagen' in key or 'categoria' in key:
|
||||
row[key] = row[key].strip()
|
||||
elif key in ['precio', 'gastos-envio']:
|
||||
row[key] = Decimal(row[key][:-1].strip().replace(',','.'))
|
||||
else:
|
||||
row[key] = row[key].strip()
|
||||
else:
|
||||
row[key] = row[key].strip()
|
||||
if row[key] == '':
|
||||
row[key] = None
|
||||
|
||||
row[key] = None
|
||||
except Exception as e:
|
||||
logging.error(f"Could not access key {key}: {str(e)}")
|
||||
continue
|
||||
# check required data
|
||||
if '' in (row['nombre-producto'], row['descripcion'], row['precio'],):
|
||||
logging.error(f"Required data missing: {row}")
|
||||
|
||||
Reference in New Issue
Block a user