Validar si existe la factura al importar
This commit is contained in:
parent
b8ab26174d
commit
7630059361
|
@ -957,6 +957,9 @@ class CuentasBanco(BaseModel):
|
|||
.select()
|
||||
.where(CuentasBanco.de_emisor==True, CuentasBanco.activa==True)
|
||||
)
|
||||
if not (len(rows)):
|
||||
return {'ok': False}
|
||||
|
||||
first = rows[0]
|
||||
rows = [{'id': r.id, 'value': '{} ({})'.format(
|
||||
r.banco.name, r.cuenta[-4:])} for r in rows]
|
||||
|
@ -3275,12 +3278,22 @@ def _importar_socios(rows):
|
|||
with database_proxy.atomic() as txn:
|
||||
Socios.create(**row)
|
||||
except IntegrityError:
|
||||
msg = '\tSocio: id: {}'.format(row['nombre'])
|
||||
log.error(msg)
|
||||
msg = '\tSocio existente: {}'.format(row['nombre'])
|
||||
log.info(msg)
|
||||
log.info('\tClientes importados...')
|
||||
return
|
||||
|
||||
|
||||
def _existe_factura(row):
|
||||
filtro = (Facturas.uuid==row['uuid'])
|
||||
if row['uuid'] is None:
|
||||
filtro = (
|
||||
(Facturas.serie==row['serie']) &
|
||||
(Facturas.folio==row['folio'])
|
||||
)
|
||||
return Facturas.select().where(filtro).exists()
|
||||
|
||||
|
||||
def _importar_facturas(rows):
|
||||
log.info('\tImportando Facturas...')
|
||||
for row in rows:
|
||||
|
@ -3290,6 +3303,11 @@ def _importar_facturas(rows):
|
|||
cliente = row.pop('cliente')
|
||||
row['cliente'] = Socios.get(**cliente)
|
||||
with database_proxy.atomic() as txn:
|
||||
if _existe_factura(row):
|
||||
msg = '\tFactura existente: {}{}'.format(
|
||||
row['serie'], row['folio'])
|
||||
log.info(msg)
|
||||
continue
|
||||
obj = Facturas.create(**row)
|
||||
for detalle in detalles:
|
||||
detalle['factura'] = obj
|
||||
|
@ -3303,7 +3321,7 @@ def _importar_facturas(rows):
|
|||
}
|
||||
FacturasImpuestos.create(**new)
|
||||
except IntegrityError as e:
|
||||
print (e)
|
||||
#~ print (e)
|
||||
msg = '\tFactura: id: {}'.format(row['serie'] + str(row['folio']))
|
||||
log.error(msg)
|
||||
log.info('\tFacturas importadas...')
|
||||
|
|
Loading…
Reference in New Issue