Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for issue #90 #137

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions entrada.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
020210802210007000000281S203Joao Da Silva Rua 76 km 34.5 Alagoas PJ54482221-l 000000000025000DOL0019800000Observaciones comerciales Sin observaciones 30 dias FOBFlete a Bordo 1 988888888888345
1PRO1 000002000000010001500000000000000025000000050000000Producto Tipo 1 Exportacion MERCOSUR ISO 9001
299999AAXX999999A225
301900020000123420111111111
102 changes: 102 additions & 0 deletions facturas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
{
"cae": "61233038185853",
"cbt_numero": "7",
"cbte_nro": "7",
"concepto": "1",
"condicion_frente_iva": "Exento",
"cuit": "20205766",
"datos": [
{
"campo": "domicilio",
"pagina": "",
"valor": null
},
{
"campo": "nombre",
"pagina": "",
"valor": null
},
{
"campo": "telefono",
"pagina": "",
"valor": null
},
{
"campo": "categoria",
"pagina": "",
"valor": null
},
{
"campo": "localidad",
"pagina": "",
"valor": null
}
],
"detalles": [
{
"codigo": "P1675G",
"ds": "PRUEBA ART",
"imp_iva": "0.00",
"importe": "1076.68",
"iva_id": "0",
"numero_despacho": "110170P",
"precio": "1076.68",
"qty": "1.0",
"umed": "07"
}
],
"domicilio_cliente": "Patricia 1 - Cdad de Buenos Aires - 1405 - Capital Federal - Argentina",
"email": "mariano@sistemasagiles.com.ar",
"fecha_cbte": "20110609",
"fecha_serv_desde": "",
"fecha_serv_hasta": "",
"fecha_venc_pago": "",
"fecha_vto": "20110619",
"forma_pago": "30 Dias",
"id": "1",
"id_impositivo": null,
"idioma": "1",
"imp_iva": "186.86",
"imp_neto": "889.82",
"imp_op_ex": "0.00",
"imp_tot_conc": "0.00",
"imp_total": "1085.57",
"imp_trib": "8.89",
"ivas": [
{
"base_imp": "889.82",
"importe": "186.86",
"iva_id": "5"
}
],
"localidad_cliente": null,
"moneda_ctz": "1.000000",
"moneda_id": "PES",
"motivo": "",
"nombre_cliente": "Cliente XXX",
"nro_doc": "30500010912",
"numero_cliente": "21601192",
"numero_cotizacion": "82016336",
"numero_orden_compra": "6443",
"numero_remito": "00008001",
"obs_comerciales": null,
"obs_generales": null,
"provincia_cliente": null,
"punto_vta": "5",
"reproceso": "S",
"resultado": "A",
"telefono_cliente": null,
"tipo_cbte": "6",
"tipo_doc": "80",
"tributos": [
{
"alic": "1.00",
"base_imp": "889.82",
"desc": "Impuesto municipal matanza",
"importe": "8.89",
"tributo_id": "99"
}
]
}
]
12 changes: 6 additions & 6 deletions formatos/formato_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def leer(fn="entrada.csv", delimiter=";"):
ext = os.path.splitext(fn)[1].lower()
items = []
if ext == ".csv":
csvfile = open(fn, "rb")
csvfile = open(fn, "r")
# deducir dialecto y delimitador
try:
dialect = csv.Sniffer().sniff(csvfile.read(256), delimiters=[";", ","])
Expand All @@ -52,7 +52,7 @@ def leer(fn="entrada.csv", delimiter=";"):
from openpyxl import load_workbook

wb = load_workbook(filename=fn)
ws1 = wb.get_active_sheet()
ws1 = wb.active
for row in ws1.rows:
fila = []
for cell in row:
Expand All @@ -65,7 +65,7 @@ def leer(fn="entrada.csv", delimiter=";"):
def aplanar(regs):
"Convierte una estructura python en planilla CSV (PyRece)"

from formato_xml import MAP_ENC
from pyafipws.formatos.formato_xml import MAP_ENC

filas = []
for reg in regs:
Expand Down Expand Up @@ -205,7 +205,7 @@ def aplanar(regs):
def desaplanar(filas):
"Dado una planilla, conviertir en estructura python"

from formato_xml import MAP_ENC
from pyafipws.formatos.formato_xml import MAP_ENC

def max_li(colname):
l = [int(k[len(colname) :]) + 1 for k in filas[0] if k.startswith(colname)]
Expand Down Expand Up @@ -339,7 +339,7 @@ def escribir(filas, fn="salida.csv", delimiter=";"):
"Dado una lista de comprobantes (diccionarios), aplana y escribe"
ext = os.path.splitext(fn)[1].lower()
if ext == ".csv":
f = open(fn, "wb")
f = open(fn, "w")
csv_writer = csv.writer(f, dialect="excel", delimiter=";")
# TODO: filas = aplanar(regs)
for fila in filas:
Expand All @@ -354,7 +354,7 @@ def escribir(filas, fn="salida.csv", delimiter=";"):
from openpyxl import Workbook

wb = Workbook()
ws1 = wb.get_active_sheet()
ws1 = wb.active
for fila in filas:
ws1.append(fila)
wb.save(filename=fn)
Expand Down
2 changes: 1 addition & 1 deletion formatos/formato_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def escribir(regs, archivos=None, carpeta=None):
if DEBUG:
print("leyendo tabla", nombre, filename)
tabla = dbf.Table(filename, campos)

tabla.open(dbf.READ_WRITE)
for d in l:
r = {}
for fmt in formato:
Expand Down
1 change: 0 additions & 1 deletion formatos/formato_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

def leer(fn="entrada.json"):
"Analiza un archivo JSON y devuelve un diccionario (confia en que el json este ok)"
items = []
jsonfile = open(fn, "rb")
regs = json.load(jsonfile)
return regs
Expand Down
12 changes: 6 additions & 6 deletions formatos/formato_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


def esquema_sql(tipos_registro, conf={}):
from formato_txt import A, N, I
from pyafipws.formatos.formato_txt import A, N, I

for tabla, formato in tipos_registro:
sql = []
Expand Down Expand Up @@ -128,7 +128,7 @@ def max_id(db, schema={}):


def redondear(formato, clave, valor):
from formato_txt import A, N, I
from pyafipws.formatos.formato_txt import A, N, I

# corregir redondeo (aparentemente sqlite no guarda correctamente los decimal)
import decimal
Expand Down Expand Up @@ -166,7 +166,7 @@ def redondear(formato, clave, valor):


def escribir(facts, db, schema={}, commit=True):
from formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO
from pyafipws.formatos.formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO

tablas, campos, campos_rev = configurar(schema)
cur = db.cursor()
Expand Down Expand Up @@ -326,7 +326,7 @@ def escribir(facts, db, schema={}, commit=True):


def modificar(fact, db, schema={}, webservice="wsfev1", ids=None, conf_db={}):
from formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO
from pyafipws.formatos.formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO

update = [
"cae",
Expand Down Expand Up @@ -372,7 +372,7 @@ def modificar(fact, db, schema={}, webservice="wsfev1", ids=None, conf_db={}):


def leer(db, schema={}, webservice="wsfev1", ids=None, **kwargs):
from formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO
from pyafipws.formatos.formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, PERMISO, DATO

tablas, campos, campos_rev = configurar(schema)
cur = db.cursor()
Expand Down Expand Up @@ -533,7 +533,7 @@ def leer(db, schema={}, webservice="wsfev1", ids=None, **kwargs):

def ayuda():
print("-- Formato:")
from formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, DATO, PERMISO
from pyafipws.formatos.formato_txt import ENCABEZADO, DETALLE, TRIBUTO, IVA, CMP_ASOC, DATO, PERMISO

tipos_registro = [
("encabezado", ENCABEZADO),
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Pillow>=2.0.0; platform_machine=='x86_64'
tabulate==0.8.5
certifi>=2020.4.5.1
qrcode==6.1
future==0.18.3
future==0.18.3
openpyxl>=3.1.2
4 changes: 4 additions & 0 deletions test_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name,Age,City
John,30,New York
Jane,25,Los Angeles
Bob,40,Chicago
Binary file added test_data.xlsx
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/test_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name,Age,City
John,30,New York
Jane,25,Los Angeles
Bob,40,Chicago
Binary file added tests/test_data.xlsx
Binary file not shown.
Loading
Loading