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