improvements to csv product loading

This commit is contained in:
Sam
2021-03-03 10:41:34 +00:00
parent 794250a6ab
commit ddf7aee312
4 changed files with 25 additions and 24 deletions

View File

@@ -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}")