Skip to content

Commit

Permalink
Refactor EscPComandos.py to separate method for initializing printer …
Browse files Browse the repository at this point in the history
…settings
  • Loading branch information
alevilar committed Sep 2, 2024
1 parent 48119d9 commit fd0e21f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
9 changes: 0 additions & 9 deletions src/common/ComandosHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,14 @@ def runTraductor(jsonTicket, queue):

# get idProduct and idVendor from config as variables and extract them from driverOps
idProduct = driverOps.pop('idProduct', None)

idVendor = driverOps.pop('idVendor', None)

if idProduct:
logger.info(f"El idProduct es {idProduct}")
idProduct = int(idProduct, 16)

if idVendor:
logger.info(f"El idVendor es {idVendor}")
idVendor = int(idVendor, 16)


idVendorMInuscula = driverOps.pop('idvendor', None)
logger.error(f"El idVendor vino en minuscula {idVendorMInuscula}")

logger.info("Los parametros a enviar driver USB son")
logger.info(driverOps)
driver = printer.Usb(idVendor, idProduct, **driverOps)
elif driverName == "Network":
# classprinter.Network(host='', port=9100, timeout=60, *args, **kwargs)[source]
Expand Down
22 changes: 7 additions & 15 deletions src/common/EscPComandos.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ def run(self, jsonTicket):
fnAction = getattr(self, action)

if isinstance(jsonTicket[action], list):
logger.debug("es instancia list")
res = fnAction(escpos, *jsonTicket[action])
rta.append({"action": action, "rta": res})

elif isinstance(jsonTicket[action], dict):
logger.debug("es instancia dict")
res = fnAction(escpos, **jsonTicket[action])
rta.append({"action": action, "rta": res})
else:
logger.debug("es instancia simple")
res = fnAction(escpos)
rta.append({"action": action, "rta": res})

Expand Down Expand Up @@ -203,6 +200,7 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
# Secciones de la Factura
encabezado = kwargs.get("encabezado", None)
items = kwargs.get("items", [])
ivas = kwargs.get("ivas", [])
pagos = kwargs.get("pagos", [])
addAdditional = kwargs.get("addAdditional", False)
setTrailer = kwargs.get("setTrailer", False)
Expand Down Expand Up @@ -306,7 +304,6 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
printer.set(font='a', height=1, align='left', normal_textsize=True)

# 4.2- TABLA ITEMS
itemIvas = {}
for item in items:

if item.get('alic_iva'):
Expand All @@ -317,10 +314,6 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
qty = float(item.get('qty'))
importe = float(item.get('importe'))
ds = item.get('ds')[0:self.desc_cols-2]

itemIvasTot = float(itemIvas.get(alicIva, 0) )
importeiva = (importe * (alicIva/100))/(1+alicIva/100)
itemIvas[alicIva] = itemIvasTot + ( importeiva * qty )

itemCant = floatToString( qty )
importeUnitario = floatToString( importe )
Expand All @@ -336,13 +329,11 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
cantTxt = pad(itemCant, self.cant_cols, " ", "l")
dsTxt = pad(ds, self.desc_cols, " ", "l")
totalTxt = pad(totalProducto, self.price_cols, " ", "r")

printer.text(f'{cantTxt}{dsTxt}{totalTxt}\n')

printer.text("-" * self.total_cols + "\n")

totalNeto = float( encabezado.get("importe_neto") )
tot_iva = float( encabezado.get("importe_iva") ) # Descontinuado en favor de detalle por c/alícuota
total = float( encabezado.get("importe_total") )

# 5- DESCUENTOS / RECARGOS
Expand All @@ -366,16 +357,17 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
printer.text(f'{dsDescuento}{self.signo}{importeDescuento}\n\n')

# 6- DETALLE IVAS (INSCRIPTO)
if tipoComprobante in tiposInscriptoString or tipoCmp in tiposInscriptoCod:
# si tiene el array de ivas tiene items, se detallan los IVAs
if ivas:
dsSinIva = pad("Total sin IVA:", self.desc_cols_ext - 1, " ", "l")
importeSinIva = pad(f"{round(totalNeto, 2):,.2f}",self.price_cols, " ", "r")
printer.set(font='a', height=1, align='left', normal_textsize=True)

printer.text(f'{dsSinIva}{self.signo}{importeSinIva}\n')

for nameiva, importeiva in itemIvas.items():
dsIva = pad(f"IVA {str(nameiva)}%:", self.desc_cols_ext - 1, " ", "l")
importeIva = pad(f"{round(importeiva * descuentoRatio, 2):,.2f}",self.price_cols, " ", "r")
for iva in ivas:
dsIva = pad(f"IVA {str(iva["alic_iva"])}%:", self.desc_cols_ext - 1, " ", "l")
importeIva = pad(f"{round(iva["importe"], 2):,.2f}",self.price_cols, " ", "r")
printer.set(font='a', height=1, align='left', normal_textsize=True)

printer.text(f'{dsIva}{self.signo}{importeIva}\n')
Expand Down Expand Up @@ -455,7 +447,7 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):

printer.set(font='a', height=1, align='center')
caeTxt = f"CAE: {cae}"
caeVtoTxt = f" CAE VTO: {caeVto}"
caeVtoTxt = f"CAE VTO: {caeVto}"
printer.text("\n")
printer.text(f"{caeTxt} {caeVtoTxt}")
printer.text("\n")
Expand Down
2 changes: 1 addition & 1 deletion src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ComandosEnum:

#si no se especifica la comandera, se envia a la comandera Dummy, si se especifica
#se envia a la comandera especificada
if len(sys.argv) > 2 and comandera != "":
if len(sys.argv) > 2:
comandera = sys.argv[2]
else:
comandera = 'Dummy'
Expand Down

0 comments on commit fd0e21f

Please sign in to comment.