forked from elmau/empresa-libre
Clean methods to import from old FacturaLibre
This commit is contained in:
parent
cb04910a84
commit
0389c0734f
|
@ -50,10 +50,11 @@ from dateutil import parser
|
||||||
|
|
||||||
from .cfdi_xml import CFDI
|
from .cfdi_xml import CFDI
|
||||||
|
|
||||||
from settings import DEBUG, DB_COMPANIES, PATHS
|
from settings import DEBUG, DB_COMPANIES, PATHS, TEMPLATE_CANCEL
|
||||||
|
|
||||||
from .cfdi_cert import SATCertificate
|
from .cfdi_cert import SATCertificate
|
||||||
from .pacs import PACComercioDigital
|
from .pacs import PACComercioDigital
|
||||||
|
# ~ from .pacs import PACFinkok
|
||||||
from .pac import Finkok as PACFinkok
|
from .pac import Finkok as PACFinkok
|
||||||
# ~ from .finkok import PACFinkok
|
# ~ from .finkok import PACFinkok
|
||||||
|
|
||||||
|
|
|
@ -9780,388 +9780,387 @@ def _importar_valores(archivo='', rfc=''):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def _importar_socios(rows):
|
# ~ def _importar_socios(rows):
|
||||||
log.info('\tImportando Clientes...')
|
# ~ log.info('\tImportando Clientes...')
|
||||||
totals = len(rows)
|
# ~ totals = len(rows)
|
||||||
for i, row in enumerate(rows):
|
# ~ for i, row in enumerate(rows):
|
||||||
msg = '\tGuardando cliente {} de {}'.format(i+1, totals)
|
# ~ msg = '\tGuardando cliente {} de {}'.format(i+1, totals)
|
||||||
log.info(msg)
|
# ~ log.info(msg)
|
||||||
try:
|
# ~ try:
|
||||||
with database_proxy.atomic() as txn:
|
# ~ with database_proxy.atomic() as txn:
|
||||||
Socios.create(**row)
|
# ~ Socios.create(**row)
|
||||||
except IntegrityError:
|
# ~ except IntegrityError:
|
||||||
msg = '\tSocio existente: {}'.format(row['nombre'])
|
# ~ msg = '\tSocio existente: {}'.format(row['nombre'])
|
||||||
log.info(msg)
|
# ~ log.info(msg)
|
||||||
log.info('\tClientes importados...')
|
# ~ log.info('\tClientes importados...')
|
||||||
return
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
def _existe_factura(row):
|
# ~ def _existe_factura(row):
|
||||||
filtro = (Facturas.uuid==row['uuid'])
|
# ~ filtro = (Facturas.uuid==row['uuid'])
|
||||||
if row['uuid'] is None:
|
# ~ if row['uuid'] is None:
|
||||||
filtro = (
|
# ~ filtro = (
|
||||||
(Facturas.serie==row['serie']) &
|
# ~ (Facturas.serie==row['serie']) &
|
||||||
(Facturas.folio==row['folio'])
|
# ~ (Facturas.folio==row['folio'])
|
||||||
)
|
# ~ )
|
||||||
return Facturas.select().where(filtro).exists()
|
# ~ return Facturas.select().where(filtro).exists()
|
||||||
|
|
||||||
|
|
||||||
def _importar_facturas(rows):
|
# ~ def _importar_facturas(rows):
|
||||||
log.info('\tImportando Facturas...')
|
# ~ log.info('\tImportando Facturas...')
|
||||||
totals = len(rows)
|
# ~ totals = len(rows)
|
||||||
for i, row in enumerate(rows):
|
# ~ for i, row in enumerate(rows):
|
||||||
msg = '\tGuardando factura {} de {}'.format(i+1, totals)
|
# ~ msg = '\tGuardando factura {} de {}'.format(i+1, totals)
|
||||||
log.info(msg)
|
# ~ log.info(msg)
|
||||||
|
|
||||||
try:
|
# ~ try:
|
||||||
detalles = row.pop('detalles')
|
# ~ detalles = row.pop('detalles')
|
||||||
impuestos = row.pop('impuestos')
|
# ~ impuestos = row.pop('impuestos')
|
||||||
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):
|
# ~ if _existe_factura(row):
|
||||||
msg = '\tFactura existente: {}{}'.format(
|
# ~ msg = '\tFactura existente: {}{}'.format(
|
||||||
row['serie'], row['folio'])
|
# ~ row['serie'], row['folio'])
|
||||||
log.info(msg)
|
# ~ log.info(msg)
|
||||||
continue
|
# ~ continue
|
||||||
obj = Facturas.create(**row)
|
# ~ obj = Facturas.create(**row)
|
||||||
for detalle in detalles:
|
# ~ for detalle in detalles:
|
||||||
detalle['factura'] = obj
|
# ~ detalle['factura'] = obj
|
||||||
FacturasDetalle.create(**detalle)
|
# ~ FacturasDetalle.create(**detalle)
|
||||||
for impuesto in impuestos:
|
# ~ for impuesto in impuestos:
|
||||||
imp = SATImpuestos.get(**impuesto['filtro'])
|
# ~ imp = SATImpuestos.get(**impuesto['filtro'])
|
||||||
new = {
|
# ~ new = {
|
||||||
'factura': obj,
|
# ~ 'factura': obj,
|
||||||
'impuesto': imp,
|
# ~ 'impuesto': imp,
|
||||||
'importe': impuesto['importe'],
|
# ~ 'importe': impuesto['importe'],
|
||||||
}
|
# ~ }
|
||||||
try:
|
# ~ try:
|
||||||
with database_proxy.atomic() as txn:
|
# ~ with database_proxy.atomic() as txn:
|
||||||
FacturasImpuestos.create(**new)
|
# ~ FacturasImpuestos.create(**new)
|
||||||
except IntegrityError as e:
|
# ~ except IntegrityError as e:
|
||||||
pass
|
# ~ pass
|
||||||
|
|
||||||
except IntegrityError as e:
|
# ~ except IntegrityError as e:
|
||||||
print (e)
|
|
||||||
msg = '\tFactura: id: {}'.format(row['serie'] + str(row['folio']))
|
|
||||||
log.error(msg)
|
|
||||||
break
|
|
||||||
|
|
||||||
log.info('\tFacturas importadas...')
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _importar_categorias(rows):
|
|
||||||
log.info('\tImportando Categorías...')
|
|
||||||
for row in rows:
|
|
||||||
with database_proxy.atomic() as txn:
|
|
||||||
try:
|
|
||||||
Categorias.create(**row)
|
|
||||||
except IntegrityError:
|
|
||||||
msg = '\tCategoria: ({}) {}'.format(row['padre'], row['categoria'])
|
|
||||||
log.error(msg)
|
|
||||||
|
|
||||||
log.info('\tCategorías importadas...')
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _get_id_unidad(unidad):
|
|
||||||
try:
|
|
||||||
if 'pieza' in unidad.lower():
|
|
||||||
unidad = 'pieza'
|
|
||||||
if 'metros' in unidad.lower():
|
|
||||||
unidad = 'metro'
|
|
||||||
if 'tramo' in unidad.lower():
|
|
||||||
unidad = 'paquete'
|
|
||||||
if 'juego' in unidad.lower():
|
|
||||||
unidad = 'par'
|
|
||||||
if 'bolsa' in unidad.lower():
|
|
||||||
unidad = 'globo'
|
|
||||||
if unidad.lower() == 'no aplica':
|
|
||||||
unidad = 'servicio'
|
|
||||||
|
|
||||||
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.id)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_impuestos(impuestos):
|
|
||||||
lines = '|'
|
|
||||||
for impuesto in impuestos:
|
|
||||||
if impuesto['tasa'] == '-2/3':
|
|
||||||
tasa = str(round(2/3, 6))
|
|
||||||
else:
|
|
||||||
if impuesto['tasa'] == 'EXENTO':
|
|
||||||
tasa = '0.00'
|
|
||||||
else:
|
|
||||||
tasa = str(round(float(impuesto['tasa']) / 100.0, 6))
|
|
||||||
|
|
||||||
info = (
|
|
||||||
IMPUESTOS.get(impuesto['nombre']),
|
|
||||||
impuesto['nombre'],
|
|
||||||
impuesto['tipo'][0],
|
|
||||||
tasa,
|
|
||||||
)
|
|
||||||
lines += '|'.join(info) + '|'
|
|
||||||
return lines
|
|
||||||
|
|
||||||
|
|
||||||
def _generar_archivo_productos(archivo):
|
|
||||||
rfc = input('Introduce el RFC: ').strip().upper()
|
|
||||||
if not rfc:
|
|
||||||
msg = 'El RFC es requerido'
|
|
||||||
log.error(msg)
|
|
||||||
return
|
|
||||||
|
|
||||||
args = util.get_con(rfc)
|
|
||||||
if not args:
|
|
||||||
return
|
|
||||||
|
|
||||||
conectar(args)
|
|
||||||
|
|
||||||
log.info('Importando datos...')
|
|
||||||
app = util.ImportFacturaLibre(archivo, rfc)
|
|
||||||
if not app.is_connect:
|
|
||||||
log.error('\t{}'.format(app._error))
|
|
||||||
return
|
|
||||||
|
|
||||||
rows = app.import_productos()
|
|
||||||
|
|
||||||
p, _, _, _ = util.get_path_info(archivo)
|
|
||||||
path_txt = util._join(p, 'productos_{}.txt'.format(rfc))
|
|
||||||
log.info('\tGenerando archivo: {}'.format(path_txt))
|
|
||||||
|
|
||||||
fields = (
|
|
||||||
'clave',
|
|
||||||
'clave_sat',
|
|
||||||
'unidad',
|
|
||||||
'categoria',
|
|
||||||
'descripcion',
|
|
||||||
'valor_unitario',
|
|
||||||
'existencia',
|
|
||||||
'inventario',
|
|
||||||
'codigo_barras',
|
|
||||||
'cuenta_predial',
|
|
||||||
'ultimo_precio',
|
|
||||||
'minimo',
|
|
||||||
)
|
|
||||||
|
|
||||||
data = ['|'.join(fields)]
|
|
||||||
not_units = []
|
|
||||||
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])
|
|
||||||
try:
|
|
||||||
int(line[2])
|
|
||||||
except ValueError:
|
|
||||||
if not line[2] in not_units:
|
|
||||||
not_units.append(line[2])
|
|
||||||
msg = 'No se encontró la unidad: {}'.format(line[2])
|
|
||||||
log.error(msg)
|
|
||||||
continue
|
|
||||||
line = '|'.join(line) + _get_impuestos(impuestos)
|
|
||||||
data.append(line)
|
|
||||||
|
|
||||||
with open(path_txt, 'w') as fh:
|
|
||||||
fh.write('\n'.join(data))
|
|
||||||
|
|
||||||
log.info('\tArchivo generado: {}'.format(path_txt))
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def importar_bdfl():
|
|
||||||
try:
|
|
||||||
emisor = Emisor.select()[0]
|
|
||||||
except IndexError:
|
|
||||||
msg = 'Configura primero al emisor'
|
|
||||||
return {'ok': False, 'msg': msg}
|
|
||||||
|
|
||||||
name = '{}.sqlite'.format(emisor.rfc.lower())
|
|
||||||
path = util._join('/tmp', name)
|
|
||||||
|
|
||||||
log.info('Importando datos...')
|
|
||||||
app = util.ImportFacturaLibre(path, emisor.rfc)
|
|
||||||
if not app.is_connect:
|
|
||||||
msg = app._error
|
|
||||||
log.error('\t{}'.format(msg))
|
|
||||||
return {'ok': False, 'msg': msg}
|
|
||||||
|
|
||||||
data = app.import_data()
|
|
||||||
|
|
||||||
_importar_socios(data['Socios'])
|
|
||||||
_importar_facturas(data['Facturas'])
|
|
||||||
_importar_categorias(data['Categorias'])
|
|
||||||
|
|
||||||
msg = 'Importación terminada...'
|
|
||||||
log.info(msg)
|
|
||||||
|
|
||||||
return {'ok': True, 'msg': msg}
|
|
||||||
|
|
||||||
|
|
||||||
def _importar_factura_libre(archivo):
|
|
||||||
rfc = input('Introduce el RFC: ').strip().upper()
|
|
||||||
if not rfc:
|
|
||||||
msg = 'El RFC es requerido'
|
|
||||||
log.error(msg)
|
|
||||||
return
|
|
||||||
|
|
||||||
args = util.get_con(rfc)
|
|
||||||
if not args:
|
|
||||||
return
|
|
||||||
|
|
||||||
conectar(args)
|
|
||||||
|
|
||||||
log.info('Importando datos...')
|
|
||||||
app = util.ImportFacturaLibre(archivo, rfc)
|
|
||||||
if not app.is_connect:
|
|
||||||
log.error('\t{}'.format(app._error))
|
|
||||||
return
|
|
||||||
|
|
||||||
data = app.import_data()
|
|
||||||
|
|
||||||
_importar_socios(data['Socios'])
|
|
||||||
_importar_facturas(data['Facturas'])
|
|
||||||
_importar_categorias(data['Categorias'])
|
|
||||||
|
|
||||||
log.info('Importación terminada...')
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _exist_ticket(row):
|
|
||||||
filters = (
|
|
||||||
(Tickets.serie==row['serie']) &
|
|
||||||
(Tickets.folio==row['folio'])
|
|
||||||
)
|
|
||||||
return Tickets.select().where(filters).exists()
|
|
||||||
|
|
||||||
|
|
||||||
def _import_tickets(rows):
|
|
||||||
log.info('\tImportando Tickets...')
|
|
||||||
for row in rows:
|
|
||||||
try:
|
|
||||||
details = row.pop('details')
|
|
||||||
taxes = row.pop('taxes')
|
|
||||||
with database_proxy.atomic() as txn:
|
|
||||||
if _exist_ticket(row):
|
|
||||||
msg = '\tTicket existente: {}{}'.format(
|
|
||||||
row['serie'], row['folio'])
|
|
||||||
log.info(msg)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not row['factura'] is None and row['factura']:
|
|
||||||
row['factura'] = Facturas.get(
|
|
||||||
Facturas.serie==row['factura']['serie'],
|
|
||||||
Facturas.folio==row['factura']['folio'])
|
|
||||||
else:
|
|
||||||
row['factura'] = None
|
|
||||||
|
|
||||||
obj = Tickets.create(**row)
|
|
||||||
for detail in details:
|
|
||||||
detail['ticket'] = obj
|
|
||||||
TicketsDetalle.create(**detail)
|
|
||||||
for tax in taxes:
|
|
||||||
imp = SATImpuestos.get(**tax['filter'])
|
|
||||||
new = {
|
|
||||||
'ticket': obj,
|
|
||||||
'impuesto': imp,
|
|
||||||
'importe': tax['import'],
|
|
||||||
}
|
|
||||||
TicketsImpuestos.create(**new)
|
|
||||||
except IntegrityError as e:
|
|
||||||
# ~ print (e)
|
# ~ print (e)
|
||||||
msg = '\tTicket: id: {}'.format(row['serie'] + str(row['folio']))
|
# ~ msg = '\tFactura: id: {}'.format(row['serie'] + str(row['folio']))
|
||||||
log.error(msg)
|
# ~ log.error(msg)
|
||||||
|
# ~ break
|
||||||
|
|
||||||
log.info('\tTickets importadas...')
|
# ~ log.info('\tFacturas importadas...')
|
||||||
return
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
def _importar_productos(archivo):
|
# ~ def _importar_categorias(rows):
|
||||||
rfc = input('Introduce el RFC: ').strip().upper()
|
# ~ log.info('\tImportando Categorías...')
|
||||||
if not rfc:
|
# ~ for row in rows:
|
||||||
msg = 'El RFC es requerido'
|
# ~ with database_proxy.atomic() as txn:
|
||||||
log.error(msg)
|
# ~ try:
|
||||||
return
|
# ~ Categorias.create(**row)
|
||||||
|
# ~ except IntegrityError:
|
||||||
|
# ~ msg = '\tCategoria: ({}) {}'.format(row['padre'], row['categoria'])
|
||||||
|
# ~ log.error(msg)
|
||||||
|
|
||||||
args = util.get_con(rfc)
|
# ~ log.info('\tCategorías importadas...')
|
||||||
if not args:
|
# ~ return
|
||||||
return
|
|
||||||
|
|
||||||
conectar(args)
|
|
||||||
log.info('Importando productos...')
|
|
||||||
|
|
||||||
fields = (
|
# ~ def _get_id_unidad(unidad):
|
||||||
'clave',
|
# ~ try:
|
||||||
'clave_sat',
|
# ~ if 'pieza' in unidad.lower():
|
||||||
'unidad',
|
# ~ unidad = 'pieza'
|
||||||
'categoria',
|
# ~ if 'metros' in unidad.lower():
|
||||||
'descripcion',
|
# ~ unidad = 'metro'
|
||||||
'valor_unitario',
|
# ~ if 'tramo' in unidad.lower():
|
||||||
'existencia',
|
# ~ unidad = 'paquete'
|
||||||
'inventario',
|
# ~ if 'juego' in unidad.lower():
|
||||||
'codigo_barras',
|
# ~ unidad = 'par'
|
||||||
'cuenta_predial',
|
# ~ if 'bolsa' in unidad.lower():
|
||||||
'ultimo_precio',
|
# ~ unidad = 'globo'
|
||||||
'minimo',
|
# ~ if unidad.lower() == 'no aplica':
|
||||||
)
|
# ~ unidad = 'servicio'
|
||||||
|
|
||||||
rows = util.read_file(archivo, 'r').split('\n')
|
# ~ obj = SATUnidades.get(SATUnidades.name.contains(unidad))
|
||||||
for i, row in enumerate(rows):
|
# ~ except SATUnidades.DoesNotExist:
|
||||||
if i == 0:
|
# ~ msg = '\tNo se encontró la unidad: {}'.format(unidad)
|
||||||
continue
|
# ~ return unidad
|
||||||
data = row.split('|')
|
|
||||||
|
# ~ 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:
|
||||||
|
# ~ if impuesto['tasa'] == 'EXENTO':
|
||||||
|
# ~ tasa = '0.00'
|
||||||
|
# ~ else:
|
||||||
|
# ~ tasa = str(round(float(impuesto['tasa']) / 100.0, 6))
|
||||||
|
|
||||||
|
# ~ info = (
|
||||||
|
# ~ IMPUESTOS.get(impuesto['nombre']),
|
||||||
|
# ~ impuesto['nombre'],
|
||||||
|
# ~ impuesto['tipo'][0],
|
||||||
|
# ~ tasa,
|
||||||
|
# ~ )
|
||||||
|
# ~ lines += '|'.join(info) + '|'
|
||||||
|
# ~ return lines
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def _generar_archivo_productos(archivo):
|
||||||
|
# ~ rfc = input('Introduce el RFC: ').strip().upper()
|
||||||
|
# ~ if not rfc:
|
||||||
|
# ~ msg = 'El RFC es requerido'
|
||||||
|
# ~ log.error(msg)
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ args = util.get_con(rfc)
|
||||||
|
# ~ if not args:
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ conectar(args)
|
||||||
|
|
||||||
|
# ~ log.info('Importando datos...')
|
||||||
|
# ~ app = util.ImportFacturaLibre(archivo, rfc)
|
||||||
|
# ~ if not app.is_connect:
|
||||||
|
# ~ log.error('\t{}'.format(app._error))
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ rows = app.import_productos()
|
||||||
|
|
||||||
|
# ~ p, _, _, _ = util.get_path_info(archivo)
|
||||||
|
# ~ path_txt = util._join(p, 'productos_{}.txt'.format(rfc))
|
||||||
|
# ~ log.info('\tGenerando archivo: {}'.format(path_txt))
|
||||||
|
|
||||||
|
# ~ fields = (
|
||||||
|
# ~ 'clave',
|
||||||
|
# ~ 'clave_sat',
|
||||||
|
# ~ 'unidad',
|
||||||
|
# ~ 'categoria',
|
||||||
|
# ~ 'descripcion',
|
||||||
|
# ~ 'valor_unitario',
|
||||||
|
# ~ 'existencia',
|
||||||
|
# ~ 'inventario',
|
||||||
|
# ~ 'codigo_barras',
|
||||||
|
# ~ 'cuenta_predial',
|
||||||
|
# ~ 'ultimo_precio',
|
||||||
|
# ~ 'minimo',
|
||||||
|
# ~ )
|
||||||
|
|
||||||
|
# ~ data = ['|'.join(fields)]
|
||||||
|
# ~ not_units = []
|
||||||
|
# ~ 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])
|
||||||
|
# ~ try:
|
||||||
|
# ~ int(line[2])
|
||||||
|
# ~ except ValueError:
|
||||||
|
# ~ if not line[2] in not_units:
|
||||||
|
# ~ not_units.append(line[2])
|
||||||
|
# ~ msg = 'No se encontró la unidad: {}'.format(line[2])
|
||||||
|
# ~ log.error(msg)
|
||||||
|
# ~ continue
|
||||||
|
# ~ line = '|'.join(line) + _get_impuestos(impuestos)
|
||||||
|
# ~ data.append(line)
|
||||||
|
|
||||||
|
# ~ with open(path_txt, 'w') as fh:
|
||||||
|
# ~ fh.write('\n'.join(data))
|
||||||
|
|
||||||
|
# ~ log.info('\tArchivo generado: {}'.format(path_txt))
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def importar_bdfl():
|
||||||
|
# ~ try:
|
||||||
|
# ~ emisor = Emisor.select()[0]
|
||||||
|
# ~ except IndexError:
|
||||||
|
# ~ msg = 'Configura primero al emisor'
|
||||||
|
# ~ return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
# ~ name = '{}.sqlite'.format(emisor.rfc.lower())
|
||||||
|
# ~ path = util._join('/tmp', name)
|
||||||
|
|
||||||
|
# ~ log.info('Importando datos...')
|
||||||
|
# ~ app = util.ImportFacturaLibre(path, emisor.rfc)
|
||||||
|
# ~ if not app.is_connect:
|
||||||
|
# ~ msg = app._error
|
||||||
|
# ~ log.error('\t{}'.format(msg))
|
||||||
|
# ~ return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
# ~ data = app.import_data()
|
||||||
|
|
||||||
|
# ~ _importar_socios(data['Socios'])
|
||||||
|
# ~ _importar_facturas(data['Facturas'])
|
||||||
|
# ~ _importar_categorias(data['Categorias'])
|
||||||
|
|
||||||
|
# ~ msg = 'Importación terminada...'
|
||||||
|
# ~ log.info(msg)
|
||||||
|
|
||||||
|
# ~ return {'ok': True, 'msg': msg}
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def _importar_factura_libre(archivo):
|
||||||
|
# ~ rfc = input('Introduce el RFC: ').strip().upper()
|
||||||
|
# ~ if not rfc:
|
||||||
|
# ~ msg = 'El RFC es requerido'
|
||||||
|
# ~ log.error(msg)
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ args = util.get_con(rfc)
|
||||||
|
# ~ if not args:
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ conectar(args)
|
||||||
|
|
||||||
|
# ~ log.info('Importando datos...')
|
||||||
|
# ~ app = util.ImportFacturaLibre(archivo, rfc)
|
||||||
|
# ~ if not app.is_connect:
|
||||||
|
# ~ log.error('\t{}'.format(app._error))
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ data = app.import_data()
|
||||||
|
|
||||||
|
# ~ _importar_socios(data['Socios'])
|
||||||
|
# ~ _importar_facturas(data['Facturas'])
|
||||||
|
# ~ _importar_categorias(data['Categorias'])
|
||||||
|
|
||||||
|
# ~ log.info('Importación terminada...')
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def _exist_ticket(row):
|
||||||
|
# ~ filters = (
|
||||||
|
# ~ (Tickets.serie==row['serie']) &
|
||||||
|
# ~ (Tickets.folio==row['folio'])
|
||||||
|
# ~ )
|
||||||
|
# ~ return Tickets.select().where(filters).exists()
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def _import_tickets(rows):
|
||||||
|
# ~ log.info('\tImportando Tickets...')
|
||||||
|
# ~ for row in rows:
|
||||||
|
# ~ try:
|
||||||
|
# ~ details = row.pop('details')
|
||||||
|
# ~ taxes = row.pop('taxes')
|
||||||
|
# ~ with database_proxy.atomic() as txn:
|
||||||
|
# ~ if _exist_ticket(row):
|
||||||
|
# ~ msg = '\tTicket existente: {}{}'.format(
|
||||||
|
# ~ row['serie'], row['folio'])
|
||||||
|
# ~ log.info(msg)
|
||||||
|
# ~ continue
|
||||||
|
|
||||||
|
# ~ if not row['factura'] is None and row['factura']:
|
||||||
|
# ~ row['factura'] = Facturas.get(
|
||||||
|
# ~ Facturas.serie==row['factura']['serie'],
|
||||||
|
# ~ Facturas.folio==row['factura']['folio'])
|
||||||
|
# ~ else:
|
||||||
|
# ~ row['factura'] = None
|
||||||
|
|
||||||
|
# ~ obj = Tickets.create(**row)
|
||||||
|
# ~ for detail in details:
|
||||||
|
# ~ detail['ticket'] = obj
|
||||||
|
# ~ TicketsDetalle.create(**detail)
|
||||||
|
# ~ for tax in taxes:
|
||||||
|
# ~ imp = SATImpuestos.get(**tax['filter'])
|
||||||
|
# ~ new = {
|
||||||
|
# ~ 'ticket': obj,
|
||||||
|
# ~ 'impuesto': imp,
|
||||||
|
# ~ 'importe': tax['import'],
|
||||||
|
# ~ }
|
||||||
|
# ~ TicketsImpuestos.create(**new)
|
||||||
|
# ~ except IntegrityError as e:
|
||||||
|
# ~ print (e)
|
||||||
|
# ~ msg = '\tTicket: id: {}'.format(row['serie'] + str(row['folio']))
|
||||||
|
# ~ log.error(msg)
|
||||||
|
|
||||||
|
# ~ log.info('\tTickets importadas...')
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
|
# ~ def _importar_productos(archivo):
|
||||||
|
# ~ rfc = input('Introduce el RFC: ').strip().upper()
|
||||||
|
# ~ if not rfc:
|
||||||
|
# ~ msg = 'El RFC es requerido'
|
||||||
|
# ~ log.error(msg)
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ args = util.get_con(rfc)
|
||||||
|
# ~ if not args:
|
||||||
|
# ~ return
|
||||||
|
|
||||||
|
# ~ conectar(args)
|
||||||
|
# ~ log.info('Importando productos...')
|
||||||
|
|
||||||
|
# ~ fields = (
|
||||||
|
# ~ 'clave',
|
||||||
|
# ~ 'clave_sat',
|
||||||
|
# ~ 'unidad',
|
||||||
|
# ~ 'categoria',
|
||||||
|
# ~ 'descripcion',
|
||||||
|
# ~ 'valor_unitario',
|
||||||
|
# ~ 'existencia',
|
||||||
|
# ~ 'inventario',
|
||||||
|
# ~ 'codigo_barras',
|
||||||
|
# ~ 'cuenta_predial',
|
||||||
|
# ~ 'ultimo_precio',
|
||||||
|
# ~ 'minimo',
|
||||||
|
# ~ )
|
||||||
|
|
||||||
|
# ~ rows = util.read_file(archivo, 'r').split('\n')
|
||||||
|
# ~ for i, row in enumerate(rows):
|
||||||
|
# ~ if i == 0:
|
||||||
|
# ~ continue
|
||||||
|
# ~ data = row.split('|')
|
||||||
# ~ print (data)
|
# ~ print (data)
|
||||||
new = {}
|
# ~ new = {}
|
||||||
for i, f in enumerate(fields):
|
# ~ for i, f in enumerate(fields):
|
||||||
if not len(data[0]):
|
# ~ if not len(data[0]):
|
||||||
continue
|
# ~ continue
|
||||||
|
|
||||||
if i in (2, 3):
|
# ~ if i in (2, 3):
|
||||||
try:
|
# ~ try:
|
||||||
new[f] = int(data[i])
|
# ~ new[f] = int(data[i])
|
||||||
except ValueError:
|
# ~ except ValueError:
|
||||||
continue
|
# ~ continue
|
||||||
elif i in (5, 6, 10, 11):
|
# ~ elif i in (5, 6, 10, 11):
|
||||||
new[f] = float(data[i])
|
# ~ new[f] = float(data[i])
|
||||||
elif i == 7:
|
# ~ elif i == 7:
|
||||||
new[f] = bool(data[i])
|
# ~ new[f] = bool(data[i])
|
||||||
else:
|
# ~ else:
|
||||||
new[f] = data[i]
|
# ~ new[f] = data[i]
|
||||||
|
|
||||||
impuestos = data[i + 1:-1]
|
# ~ impuestos = data[i + 1:-1]
|
||||||
if not impuestos:
|
# ~ if not impuestos:
|
||||||
taxes = [SATImpuestos.select().where(SATImpuestos.id==6)]
|
# ~ taxes = [SATImpuestos.select().where(SATImpuestos.id==6)]
|
||||||
else:
|
# ~ else:
|
||||||
taxes = []
|
# ~ taxes = []
|
||||||
try:
|
# ~ try:
|
||||||
for i in range(0, len(impuestos), 4):
|
# ~ for i in range(0, len(impuestos), 4):
|
||||||
w = {
|
# ~ w = {
|
||||||
'key': impuestos[i],
|
# ~ 'key': impuestos[i],
|
||||||
'name': impuestos[i+1],
|
# ~ 'name': impuestos[i+1],
|
||||||
'tipo': impuestos[i+2],
|
# ~ 'tipo': impuestos[i+2],
|
||||||
'tasa': float(impuestos[i+3]),
|
# ~ 'tasa': float(impuestos[i+3]),
|
||||||
}
|
# ~ }
|
||||||
taxes.append(SATImpuestos.get_o_crea(w))
|
# ~ taxes.append(SATImpuestos.get_o_crea(w))
|
||||||
except IndexError:
|
# ~ except IndexError:
|
||||||
print ('IE', data)
|
# ~ print ('IE', data)
|
||||||
continue
|
# ~ continue
|
||||||
|
|
||||||
with database_proxy.transaction():
|
# ~ with database_proxy.transaction():
|
||||||
try:
|
# ~ try:
|
||||||
obj = Productos.create(**new)
|
# ~ obj = Productos.create(**new)
|
||||||
obj.impuestos = taxes
|
# ~ obj.impuestos = taxes
|
||||||
except IntegrityError as e:
|
# ~ except IntegrityError as e:
|
||||||
pass
|
# ~ pass
|
||||||
|
|
||||||
log.info('Importación terminada...')
|
# ~ log.info('Importación terminada...')
|
||||||
return
|
# ~ return
|
||||||
|
|
||||||
|
|
||||||
def _import_from_folder(path):
|
def _import_from_folder(path):
|
||||||
|
|
|
@ -73,8 +73,8 @@ PATH_SESSIONS = {
|
||||||
|
|
||||||
IV = 'valores_iniciales.json'
|
IV = 'valores_iniciales.json'
|
||||||
INIT_VALUES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', IV))
|
INIT_VALUES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', IV))
|
||||||
CT = 'cancel_template.xml'
|
# ~ CT = 'cancel_template.xml'
|
||||||
TEMPLATE_CANCEL = os.path.abspath(os.path.join(PATH_TEMPLATES, CT))
|
# ~ TEMPLATE_CANCEL = os.path.abspath(os.path.join(PATH_TEMPLATES, CT))
|
||||||
|
|
||||||
PATH_XSLT = os.path.abspath(os.path.join(BASE_DIR, '..', 'xslt'))
|
PATH_XSLT = os.path.abspath(os.path.join(BASE_DIR, '..', 'xslt'))
|
||||||
PATH_BIN = os.path.abspath(os.path.join(BASE_DIR, '..', 'bin'))
|
PATH_BIN = os.path.abspath(os.path.join(BASE_DIR, '..', 'bin'))
|
||||||
|
@ -245,3 +245,32 @@ DEFAULT_GLOBAL = {
|
||||||
'descripcion': 'Venta',
|
'descripcion': 'Venta',
|
||||||
'clave_sat': '01010101',
|
'clave_sat': '01010101',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEMPLATE_CANCEL = """<Cancelacion RfcEmisor="{rfc}" Fecha="{fecha}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://cancelacfd.sat.gob.mx">
|
||||||
|
<Folios>
|
||||||
|
<UUID>{uuid}</UUID>
|
||||||
|
</Folios>
|
||||||
|
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<SignedInfo>
|
||||||
|
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
|
||||||
|
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
|
||||||
|
<Reference URI="">
|
||||||
|
<Transforms>
|
||||||
|
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
|
||||||
|
</Transforms>
|
||||||
|
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||||
|
<DigestValue />
|
||||||
|
</Reference>
|
||||||
|
</SignedInfo>
|
||||||
|
<SignatureValue />
|
||||||
|
<KeyInfo>
|
||||||
|
<X509Data>
|
||||||
|
<X509SubjectName />
|
||||||
|
<X509IssuerSerial />
|
||||||
|
<X509Certificate />
|
||||||
|
</X509Data>
|
||||||
|
<KeyValue />
|
||||||
|
</KeyInfo>
|
||||||
|
</Signature>
|
||||||
|
</Cancelacion>
|
||||||
|
"""
|
||||||
|
|
Loading…
Reference in New Issue