Skip to content

Commit

Permalink
Merge pull request reingart#71 from chazuttu/coverage_pyfepdf
Browse files Browse the repository at this point in the history
Coverage pyfepdf
  • Loading branch information
reingart authored Aug 11, 2021
2 parents 7f556d5 + 19feedb commit bf0fbf6
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ omit =
*nsis*
*/padron.py
*pyemail*
*pyfepdf*
*formatos*
*pyi25*
*pyqr*
*rece1*
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Fix OpenSSL "dh key too small"
run: |
sudo cp .github/openssl.cnf /etc/ssl/openssl.cnf
- name: Copy rece.ini file
run: |
sudo cp conf/rece.ini rece.ini
- name: Test with pytest
run: |
pytest --html=report.html --self-contained-html
Expand Down
10 changes: 5 additions & 5 deletions conf/rece.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# EJEMPLO de archivo de configuración de la interfaz PyAfipWs
# EJEMPLO de archivo de configuración de la interfaz PyAfipWs
# DEBE CAMBIAR Certificado (CERT) y Clave Privada (PRIVATEKEY)
# Para producción debe descomentar las URL (sacar ##)
# Más información:
# http://www.sistemasagiles.com.ar/trac/wiki/ManualPyAfipWs#Configuración
# Para producción debe descomentar las URL (sacar ##)
# Más información:
# http://www.sistemasagiles.com.ar/trac/wiki/ManualPyAfipWs#Configuración

[WSAA]
CERT=reingart.crt
Expand Down Expand Up @@ -78,7 +78,7 @@ LOCALE=Spanish_Argentina.1252
FMT_CANTIDAD=0.4
FMT_PRECIO=0.3
CANT_POS=izq
ENTRADA=factura.txt
ENTRADA=facturas.txt
SALIDA=factura.pdf

[PDF]
Expand Down
17 changes: 17 additions & 0 deletions formatos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.

"""Módulo para acceder a web services de la afip
"""
__author__ = "Mariano Reingart ([email protected])"
__copyright__ = "Copyright (C) 2008-2021 Mariano Reingart"
__license__ = "LGPL-3.0-or-later"
4 changes: 2 additions & 2 deletions formatos/formato_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def leer(fn="entrada.json"):
return regs


def escribir(filas, fn="salida.json"):
def escribir(filas, fn="salida.json", **kwargs):
"Dado una lista de comprobantes (diccionarios), escribe JSON"
import codecs

Expand All @@ -46,6 +46,6 @@ def escribir(filas, fn="salida.json"):
jsonfile,
sort_keys=True,
indent=4,
encoding="utf-8",
**kwargs
)
jsonfile.close()
10 changes: 6 additions & 4 deletions formatos/formato_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
__license__ = "LGPL-3.0-or-later"

from decimal import Decimal
import sys

CHARSET = "latin1"

Expand Down Expand Up @@ -117,7 +118,7 @@
("imp_iva", 15, I),
("despacho", 20, A),
("u_mtx", 10, N),
("cod_mtx", 30, A),
("cod_mtx", 30, N),
("dato_a", 15, A),
("dato_b", 15, A),
("dato_c", 15, A),
Expand Down Expand Up @@ -229,8 +230,9 @@ def escribir_linea_txt(dic, formato):
valor = dic.get(clave, "")
if not isinstance(valor, basestring):
valor = str(valor)
if isinstance(valor, str):
valor = valor.encode(CHARSET, "replace")
if sys.version_info[0] < 3 :
if isinstance(valor, str):
valor = valor.encode(CHARSET, "replace")
if valor == "None":
valor = ""
if tipo == N and valor and valor != "NULL":
Expand All @@ -257,7 +259,7 @@ def escribir_linea_txt(dic, formato):

def leer(fn="entrada.txt"):
"Analiza un archivo TXT y devuelve un diccionario"
f_entrada = open(fn, "r")
f_entrada = open(fn, "rb")
try:
regs = []
reg = None
Expand Down
9 changes: 7 additions & 2 deletions pyfepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ def GenerarPDF(self, archivo=""):

@utils.inicializar_y_capturar_excepciones_simple
def MostrarPDF(self, archivo, imprimir=False):
if sys.platform.startswith(("linux2", "java")):
if sys.platform.startswith(("linux2", "java", "linux")):
os.system("evince " "%s" "" % archivo)
else:
operation = imprimir and "print" or ""
Expand Down Expand Up @@ -2040,7 +2040,10 @@ def main():
archivo = conf_fact.get("entrada", "entrada.txt")
if DEBUG:
print("Escribiendo", archivo)
regs = formato_json.escribir([reg], archivo)
if sys.version_info[0] < 3:
regs = formato_json.escribir([reg], archivo, encoding='utf-8')
else:
regs = formato_json.escribir([reg], archivo)
else:
from .formatos import formato_txt

Expand Down Expand Up @@ -2096,5 +2099,7 @@ def main():
if "--mostrar" in sys.argv:
fepdf.MostrarPDF(archivo=salida, imprimir="--imprimir" in sys.argv)

return fepdf

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion pyqr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def GenerarImagen(

# convertir a representación json y codificar en base64:
datos_cmp_json = json.dumps(datos_cmp)
url = self.URL % (base64.b64encode(datos_cmp_json))
url = self.URL % (base64.b64encode(datos_cmp_json.encode('ascii')).decode('ascii'))

qr = qrcode.QRCode(
version=self.qr_ver,
Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ pytest-html==1.22.1; python_version <= '2.7'
pytest-html==3.1.1; python_version > '3'
pytest-vcr==1.0.2
pytest-cov==2.12.1
pytest-freezegun==0.4.2
pytest-freezegun==0.4.2
pytest-mock==2.0.0; python_version <= '2.7'
pytest-mock==3.6.1; python_version > '2.7'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"(soap, com/dll, pdf, dbf, xml, etc.)"
)
kwargs["package_dir"] = {"pyafipws": "."}
kwargs["packages"] = ["pyafipws"]
kwargs["packages"] = ["pyafipws", "pyafipws.formatos"]
opts = {}
data_files = [("pyafipws/plantillas", glob.glob("plantillas/*"))]

Expand Down
102 changes: 102 additions & 0 deletions tests/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": "[email protected]",
"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"
}
]
}
]
Loading

0 comments on commit bf0fbf6

Please sign in to comment.