diff --git a/src/common/EscPComandos.py b/src/common/EscPComandos.py index 373391c68e..290c258204 100644 --- a/src/common/EscPComandos.py +++ b/src/common/EscPComandos.py @@ -47,18 +47,21 @@ def run(self, jsonTicket): actions = jsonTicket.keys() rta = [] for action in actions: - fnAction = getattr(self, action) + fnAction = getattr(self, action, None) - if isinstance(jsonTicket[action], list): - res = fnAction(escpos, *jsonTicket[action]) - rta.append({"action": action, "rta": res}) + if fnAction: + params = jsonTicket[action] + + if isinstance(params, list): + res = fnAction(escpos, *params) + elif isinstance(params, dict): + res = fnAction(escpos, **params) + else: + res = fnAction(escpos, params) - elif isinstance(jsonTicket[action], dict): - res = fnAction(escpos, **jsonTicket[action]) rta.append({"action": action, "rta": res}) else: - res = fnAction(escpos) - rta.append({"action": action, "rta": res}) + rta.append({"action": action, "rta": "Function not found"}) return rta @@ -81,8 +84,16 @@ def getStatus(self): else: return False - def printTexto(self, printer, texto): - printer.text(texto) + def printTexto(self, escpos: EscposIO, texto=None, **kwargs): + printer = escpos.printer + self.__initPrinter(printer) + + if texto: + printer.text(texto) + elif 'texto' in kwargs: + printer.text(kwargs['texto']) + else: + raise ValueError("No text provided to print") def openDrawer(self, escpos: EscposIO, **kwargs):