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 72f43d8 commit 11ebd5f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/common/Configberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ def __new__(cls):
return cls._instance

def __init__(self):
self.logger = logging.getLogger("Configberry")

# read config file and list all sections
self.logger.debug("Config Sections: %s" % self.sections())
# menos el primero que es el de SERVIDOR, mostrar el el resto en consola ya que son las impresoras
for s in self.sections()[1:]:
print("Impresora en Config: %s" % s)


if not hasattr(self, 'initialized'):
self.initialized = True
Expand Down Expand Up @@ -111,6 +104,16 @@ def writeSectionWithKwargs(self, section, kwargs):
return 1

def __create_config_if_not_exists(self):
#show info only once
self.logger = logging.getLogger("Configberry")

# read config file and list all sections
self.logger.debug("Config Sections: %s" % self.sections())
# menos el primero que es el de SERVIDOR, mostrar el el resto en consola ya que son las impresoras
for s in self.sections()[1:]:
print("Impresora en Config: %s" % s)



print(f"User config files stored in {platformdirs.user_config_dir(appname)}")

Expand Down
25 changes: 20 additions & 5 deletions src/common/EscPComandos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ class EscPComandos():
def __init__(self, printer):
self.printer = printer

# Obtener el número de columnas desde el perfil
if printer.profile:
print("-- - -- - - - - - - -")
print(printer.profile.profile_data)
line_width = printer.profile.profile_data['columns']
print(f"Número de caracteres por línea: {line_width}")
else:
print("El perfil no tiene definida la cantidad de columnas por línea.")


self.total_cols = 40
self.price_cols = 12 #12 espacios permiten hasta 9,999,999.99
self.cant_cols = 6 #4 no admitiría decimales, 6 sería mejor
Expand Down Expand Up @@ -373,15 +383,20 @@ def printFacturaElectronica(self, escpos: EscposIO, **kwargs):
printer.text(f'{dsIva}{self.signo}{importeIva}\n')

# 7- TOTAL
printer.set(font='a', bold=True, align='left', double_height=True, double_width=True)
dsTotal = pad("TOTAL:", self.desc_cols_ext - 1, " ", "l")
printer.set(font='a', bold=True, align='left', double_height=False, double_width=False)
# Imprime "TOTAL" alineado a la izquierda
printer.set(align='left')
printer.text("TOTAL:")

# Imprime el monto alineado a la derecha en la misma línea
printer.set(align='right')
importeTotal = pad(f"{round(total,2):,.2f}",self.price_cols, " ", "r")
printer.text(f'{self.signo}{importeTotal}\n\n')

printer.text(f'{dsTotal}{self.signo}{importeTotal}\n\n')

# NC si hay que firmar
printer.set(font='b', bold=False, width=1, height=1, align='left', normal_textsize=True)


if tipoComprobante in tiposNC or tipoCmp in tiposNC:
printer.text(u"Firma.......................................\n\n")
printer.text(u"Aclaración..................................\n")
Expand Down Expand Up @@ -706,7 +721,7 @@ def print_plato(plato):
# printer._raw(chr(0x1D)+chr(0xF9)+chr(0x35)+"0")

# dejar letra chica alineada izquierda

printer.buzzer(1, 1)
return True

def __initPrinter(self, printer):
Expand Down

0 comments on commit 11ebd5f

Please sign in to comment.