diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 859a409..f8a6e25 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -1718,6 +1718,9 @@ class ImportFacturaLibreGambas(object): sql = "SELECT serie, folio FROM cfdifacturas WHERE id=%s" self._cursor.execute(sql, [invoice]) row = self._cursor.fetchone() + if row is None: + return {} + return dict(row) def _get_details_ticket(self, id): @@ -1776,8 +1779,13 @@ class ImportFacturaLibreGambas(object): def _productos(self): UNIDADES = { - 'KG': 'KGM', - 'PZA': 'H87', + 'kg': 'KGM', + 'pieza': 'H87', + 'pza': 'H87', + 'pz': 'H87', + 'bulto': 'H87', + 'caja': 'XBX', + 'rollo': 'XRO', } sql = "SELECT * FROM productos" self._cursor.execute(sql) @@ -1809,7 +1817,7 @@ class ImportFacturaLibreGambas(object): new['categoria'] = None new['descripcion'] = ' '.join(new['descripcion'].split()) new['clave_sat'] = DEFAULT_SAT_PRODUCTO - new['unidad'] = UNIDADES.get(new['unidad'], new['unidad']) + new['unidad'] = UNIDADES.get(new['unidad'].lower(), new['unidad']) self._cursor.execute(sql, [row['id_impuesto1']]) impuestos = self._cursor.fetchall() new['impuestos'] = tuple(impuestos) @@ -1928,6 +1936,7 @@ class ImportFacturaLibreGambas(object): '-10.6666': 0.106667, '-10.666666': 0.106667, '-10.66660': 0.106667, + '-4': 0.04, } data = [] @@ -1993,7 +2002,7 @@ class ImportFacturaLibreGambas(object): if not new['uuid']: new['uuid'] = None - elif new['uuid'] == 'ok': + elif new['uuid'] in('ok', '123'): new['uuid'] = None new['estatus'] = 'Cancelada' new['cancelada'] = True @@ -2287,6 +2296,7 @@ class ImportFacturaLibre(object): '-10.6666': 0.106667, '-10.666666': 0.106667, '-10.66660': 0.106667, + '-4': 0.04, } data = [] diff --git a/source/app/models/main.py b/source/app/models/main.py index 61adf7c..d416e24 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -4771,10 +4771,17 @@ def _importar_facturas(rows): 'impuesto': imp, 'importe': impuesto['importe'], } - FacturasImpuestos.create(**new) + try: + with database_proxy.atomic() as txn: + FacturasImpuestos.create(**new) + except IntegrityError as e: + pass + except IntegrityError as e: + print (e) msg = '\tFactura: id: {}'.format(row['serie'] + str(row['folio'])) log.error(msg) + break log.info('\tFacturas importadas...') return @@ -4992,10 +4999,13 @@ def _import_tickets(rows): log.info(msg) continue - if not row['factura'] is None: + 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 @@ -5009,7 +5019,7 @@ def _import_tickets(rows): } TicketsImpuestos.create(**new) except IntegrityError as e: - print (e) + # ~ print (e) msg = '\tTicket: id: {}'.format(row['serie'] + str(row['folio'])) log.error(msg) @@ -5044,7 +5054,8 @@ def _importar_productos_gambas(rows): obj = Productos.create(**row) obj.impuestos = taxes except IntegrityError as e: - print (e) + msg = '\tProducto ya existe' + log.info(msg) log.info('ImportaciĆ³n terminada...') return diff --git a/source/db/valores_iniciales.json b/source/db/valores_iniciales.json index acb7ad0..1556317 100644 --- a/source/db/valores_iniciales.json +++ b/source/db/valores_iniciales.json @@ -25,7 +25,9 @@ {"key": "E48", "name": "Servicio", "activo": true}, {"key": "E51", "name": "Trabajo", "activo": false}, {"key": "ACT", "name": "Actividad", "activo": false}, - {"key": "KGM", "name": "Kilogramo", "activo": false} + {"key": "KGM", "name": "Kilogramo", "activo": false}, + {"key": "XBX", "name": "Caja", "activo": false}, + {"key": "XRO", "name": "Rollo", "activo": false} ] }, {