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