Merge branch 'development'
This commit is contained in:
@@ -41,11 +41,11 @@ class Company(models.Model):
|
|||||||
shop_rss_feed = models.URLField('RSS tienda online', null=True, blank=True)
|
shop_rss_feed = models.URLField('RSS tienda online', null=True, blank=True)
|
||||||
sale_terms = models.TextField('Condiciones de venta', null=True, blank=True)
|
sale_terms = models.TextField('Condiciones de venta', null=True, blank=True)
|
||||||
shipping_cost = models.DecimalField('Gastos de envío', max_digits=10, decimal_places=2, null=True, blank=True)
|
shipping_cost = models.DecimalField('Gastos de envío', max_digits=10, decimal_places=2, null=True, blank=True)
|
||||||
tags = TagField(force_lowercase=True,max_count=5, tree=True)
|
tags = TagField(force_lowercase=True,max_count=5, tree=True, null=True, blank=True)
|
||||||
sync = models.BooleanField('Sincronizar tienda', default=False, null=True, blank=True)
|
sync = models.BooleanField('Sincronizar tienda', default=False, null=True, blank=True)
|
||||||
is_validated = models.BooleanField('Validado', default=False, null=True, blank=True)
|
is_validated = models.BooleanField('Validado', default=False, null=True, blank=True)
|
||||||
is_active = models.BooleanField('Activado', default=False, null=True, blank=True)
|
is_active = models.BooleanField('Activado', default=False, null=True, blank=True)
|
||||||
credentials = JSONField(null=True)
|
credentials = JSONField(null=True, blank=True )
|
||||||
shipping_terms = models.TextField('Condiciones de envío', null=True, blank=True)
|
shipping_terms = models.TextField('Condiciones de envío', null=True, blank=True)
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import requests
|
|||||||
from products.models import Product
|
from products.models import Product
|
||||||
from companies.models import Company
|
from companies.models import Company
|
||||||
from history.models import HistorySync
|
from history.models import HistorySync
|
||||||
|
from PIL import Image
|
||||||
|
from io import BytesIO
|
||||||
|
from django.core.files import File
|
||||||
|
|
||||||
|
|
||||||
def extract_search_filters(result_set):
|
def extract_search_filters(result_set):
|
||||||
@@ -217,7 +220,7 @@ def find_related_products_v4(keyword):
|
|||||||
return set(products_qs)
|
return set(products_qs)
|
||||||
|
|
||||||
|
|
||||||
def product_loader(csv_reader, user):
|
def product_loader(csv_reader, user=None, company=None):
|
||||||
"""
|
"""
|
||||||
Parse csv data and extract:
|
Parse csv data and extract:
|
||||||
|
|
||||||
@@ -232,34 +235,41 @@ def product_loader(csv_reader, user):
|
|||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
# trim strings
|
# trim strings
|
||||||
for key in row:
|
for key in row:
|
||||||
if row[key]: row[key] = row[key].strip().lower()
|
if row[key]:
|
||||||
|
if 'imagen' in key or 'categoria' in key:
|
||||||
|
row[key] = row[key].strip()
|
||||||
|
else:
|
||||||
|
row[key] = row[key].strip().lower()
|
||||||
|
|
||||||
# check required data
|
# check required data
|
||||||
if '' in (row['nombre-producto'], row['descripcion'], row['precio'], row['categoria']):
|
if '' in (row['nombre-producto'], row['descripcion'], row['precio'], row['categoria']):
|
||||||
logging.error(f"Required data missing: {row}")
|
logging.error(f"Required data missing: {row}")
|
||||||
continue
|
continue
|
||||||
|
#import ipdb; ipdb.set_trace()
|
||||||
try:
|
try:
|
||||||
# TODO: if tags is empty, auto-generate tags
|
# TODO: if tags is empty, auto-generate tags
|
||||||
|
if not company:
|
||||||
|
company = user.company
|
||||||
|
|
||||||
# assemble instance data
|
# assemble instance data
|
||||||
product_data = {
|
product_data = {
|
||||||
'company': user.company,
|
'company': company,
|
||||||
'name': row['nombre-producto'].strip(),
|
'name': row['nombre-producto'].strip(),
|
||||||
'description': row['descripcion'].strip(),
|
'description': row['descripcion'].strip(),
|
||||||
#'url': row['url'].strip(),
|
'url': row['url'].strip(),
|
||||||
#'price': row['precio'].strip(),
|
'price': float(row['precio'].strip().replace(',','.')),
|
||||||
#'shipping_cost': row['gastos-envio'].strip(),
|
'shipping_cost': float(row['gastos-envio'].strip().replace(',','.')),
|
||||||
#'shipping_terms': row['cond-envio'].strip(),
|
'shipping_terms': row['cond-envio'].strip(),
|
||||||
#'discount': row['descuento'].strip(),
|
'discount': row['descuento'].strip(),
|
||||||
#'stock': row['stock'].strip(),
|
'stock': row['stock'].strip(),
|
||||||
#'tags': row['tags'].strip(),
|
'tags': row['tags'].strip(),
|
||||||
#'category': row['categoria'].strip(),
|
'category': row['categoria'].strip(),
|
||||||
#'identifiers': row['identificadores'].strip(),
|
'identifiers': row['identificadores'].strip(),
|
||||||
#'history': history,
|
#'history': history,
|
||||||
'creator': user,
|
'creator': user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
product = Product.objects.create(**product_data)
|
product = Product.objects.create(**product_data)
|
||||||
# image logo data
|
# image logo data
|
||||||
if row['imagen'] is not None:
|
if row['imagen'] is not None:
|
||||||
@@ -282,7 +292,7 @@ def product_loader(csv_reader, user):
|
|||||||
logging.info(f"Created Product {product.id}")
|
logging.info(f"Created Product {product.id}")
|
||||||
counter += 1
|
counter += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import ipdb; ipdb.set_trace()
|
#import ipdb; ipdb.set_trace()
|
||||||
logging.error(f"Could not parse {row}")
|
logging.error(f"Could not parse {row}")
|
||||||
|
|
||||||
history.quantity = counter
|
history.quantity = counter
|
||||||
|
|||||||
Reference in New Issue
Block a user