Validar unidad al importar productos
This commit is contained in:
parent
6954b74677
commit
b8ab26174d
|
@ -581,6 +581,9 @@ class SATUnidades(BaseModel):
|
||||||
(('key', 'name'), True),
|
(('key', 'name'), True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{} ({})'.format(self.name, self.key)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_(self):
|
def get_(self):
|
||||||
rows = SATUnidades.select().dicts()
|
rows = SATUnidades.select().dicts()
|
||||||
|
@ -3335,24 +3338,31 @@ def _importar_categorias(rows):
|
||||||
|
|
||||||
|
|
||||||
def _get_id_unidad(unidad):
|
def _get_id_unidad(unidad):
|
||||||
obj = SATUnidades.select(SATUnidades.id).where(SATUnidades.name==unidad)
|
try:
|
||||||
|
if 'pieza' in unidad.lower():
|
||||||
if obj is None:
|
unidad = 'pieza'
|
||||||
msg = 'No se encontró: {}'.format(unidad)
|
obj = SATUnidades.get(SATUnidades.name.contains(unidad))
|
||||||
log.error('\t', msg)
|
except SATUnidades.DoesNotExist:
|
||||||
|
msg = '\tNo se encontró la unidad: {}'.format(unidad)
|
||||||
|
log.error(msg)
|
||||||
return unidad
|
return unidad
|
||||||
|
|
||||||
return str(obj[0].id)
|
return str(obj.id)
|
||||||
|
|
||||||
|
|
||||||
def _get_impuestos(impuestos):
|
def _get_impuestos(impuestos):
|
||||||
lines = '|'
|
lines = '|'
|
||||||
for impuesto in impuestos:
|
for impuesto in impuestos:
|
||||||
|
if impuesto['tasa'] == '-2/3':
|
||||||
|
tasa = str(round(2/3, 6))
|
||||||
|
else:
|
||||||
|
tasa = str(round(float(impuesto['tasa']) / 100.0, 6))
|
||||||
|
|
||||||
info = (
|
info = (
|
||||||
IMPUESTOS.get(impuesto['nombre']),
|
IMPUESTOS.get(impuesto['nombre']),
|
||||||
impuesto['nombre'],
|
impuesto['nombre'],
|
||||||
impuesto['tipo'][0],
|
impuesto['tipo'][0],
|
||||||
str(round(float(impuesto['tasa']) / 100.0, 6)),
|
tasa,
|
||||||
)
|
)
|
||||||
lines += '|'.join(info)
|
lines += '|'.join(info)
|
||||||
return lines
|
return lines
|
||||||
|
@ -3402,6 +3412,8 @@ def _generar_archivo_productos(archivo):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
impuestos = row.pop('impuestos', ())
|
impuestos = row.pop('impuestos', ())
|
||||||
line = [str(row[r]) for r in fields]
|
line = [str(row[r]) for r in fields]
|
||||||
|
if line[10] == 'None':
|
||||||
|
line[10] = '0.0'
|
||||||
line[2] = _get_id_unidad(line[2])
|
line[2] = _get_id_unidad(line[2])
|
||||||
line = '|'.join(line) + _get_impuestos(impuestos)
|
line = '|'.join(line) + _get_impuestos(impuestos)
|
||||||
data.append(line)
|
data.append(line)
|
||||||
|
|
Loading…
Reference in New Issue