From bed57a6905878b5d1a501a59d0ab7255345fb94b Mon Sep 17 00:00:00 2001 From: Matias Ahumada Date: Sat, 19 Nov 2022 13:16:39 -0300 Subject: [PATCH 1/5] added/audit-when-close-daily auto-commit --- pyfiscalprinter/__init__.py | 0 pyfiscalprinter/command_repository.py | 1 - pyfiscalprinter/controller.py | 1 + pyfiscalprinter/driver.py | 0 pyfiscalprinter/epson.py | 0 pyfiscalprinter/epson_ext.py | 204 ++++++++++++++++++++++---- pyfiscalprinter/epson_ext_driver.py | 15 +- pyfiscalprinter/fiscal.ini | 0 pyfiscalprinter/generic.py | 0 pyfiscalprinter/hasar.py | 0 pyfiscalprinter/service.py | 0 pyfiscalprinter/test.py | 0 12 files changed, 185 insertions(+), 36 deletions(-) mode change 100644 => 100755 pyfiscalprinter/__init__.py mode change 100644 => 100755 pyfiscalprinter/command_repository.py mode change 100644 => 100755 pyfiscalprinter/driver.py mode change 100644 => 100755 pyfiscalprinter/epson.py mode change 100644 => 100755 pyfiscalprinter/epson_ext.py mode change 100644 => 100755 pyfiscalprinter/epson_ext_driver.py mode change 100644 => 100755 pyfiscalprinter/fiscal.ini mode change 100644 => 100755 pyfiscalprinter/generic.py mode change 100644 => 100755 pyfiscalprinter/hasar.py mode change 100644 => 100755 pyfiscalprinter/service.py mode change 100644 => 100755 pyfiscalprinter/test.py diff --git a/pyfiscalprinter/__init__.py b/pyfiscalprinter/__init__.py old mode 100644 new mode 100755 diff --git a/pyfiscalprinter/command_repository.py b/pyfiscalprinter/command_repository.py old mode 100644 new mode 100755 index 2080061..1593e05 --- a/pyfiscalprinter/command_repository.py +++ b/pyfiscalprinter/command_repository.py @@ -35,7 +35,6 @@ def getCmd(self, model): dictionary = { 'epson_ext': self.CMD_EPSON_EXT, - 'epson': self.CMD_EPSON } diff --git a/pyfiscalprinter/controller.py b/pyfiscalprinter/controller.py index 287de87..72311a2 100755 --- a/pyfiscalprinter/controller.py +++ b/pyfiscalprinter/controller.py @@ -220,6 +220,7 @@ def AbrirComprobante(self, else: ret = printer.openTicket() elif cbte_fiscal.startswith("F"): + print('aca') ret = printer.openBillTicket(letra_cbte, nombre_cliente, domicilio_cliente, nro_doc, doc_fiscal, pos_fiscal) elif cbte_fiscal.startswith("ND"): diff --git a/pyfiscalprinter/driver.py b/pyfiscalprinter/driver.py old mode 100644 new mode 100755 diff --git a/pyfiscalprinter/epson.py b/pyfiscalprinter/epson.py old mode 100644 new mode 100755 diff --git a/pyfiscalprinter/epson_ext.py b/pyfiscalprinter/epson_ext.py old mode 100644 new mode 100755 index 757495a..7788938 --- a/pyfiscalprinter/epson_ext.py +++ b/pyfiscalprinter/epson_ext.py @@ -3,6 +3,7 @@ import string import types import unicodedata +import re import driver from epson_ext_driver import EpsonFiscalExtDriver @@ -10,6 +11,7 @@ from math import ceil from math import floor from command_repository import CommandRepository +from lxml import etree class FiscalPrinterError(Exception): pass @@ -57,6 +59,7 @@ class EpsonExtPrinter(PrinterInterface): command_repository = CommandRepository() commands = {} + i = 0 models = ["tickeadoras", "epsonlx300+", "tm-220-af"] @@ -384,8 +387,8 @@ def subtotal(self, print_text=True, display=False, text="Subtotal"): def getStatus(self,status, printer): reply = self._sendCommand('020A|0000', []) response = [ + reply[2], reply[1], - reply[0], "0", "0", "0", @@ -393,6 +396,105 @@ def getStatus(self,status, printer): ] return status(response, printer) + + def recursiveDict(self, element): + tag = element.tag + if element.tag == 'conjuntoComprobantesFiscales': + self.i = self.i + 1 + tag = element.tag + str(self.i) + + return tag, dict(map(self.recursiveDict,element)) or element.text + + def changeKeyToDictForDocumentId(self, key, dictionary): + new_key = dictionary[key]['codigoTipoComprobante'] + dictionary[new_key] = dictionary.pop(key) + + return dictionary + + def extractInfoToXml(self, xml): + self.i = 0 + text = re.findall(r'((.*))', xml) + try: + root = etree.XML(bytes(text[0][0].encode('utf8'))) + except Exception as e: + print('Create xml error', e) + + return self.recursiveDict(root)[1] + + def getDailyCloseData(self, receipt_number): + self._sendCommand('0813|0000', [str(receipt_number), str(receipt_number)]) + reply_xml = self._sendCommand('0814|0000', []) + try: + xml = reply_xml[2] + info_close_daily = self.extractInfoToXml(xml + ' Date: Sat, 19 Nov 2022 13:32:58 -0300 Subject: [PATCH 2/5] added/audit-when-close-daily auto-commit --- pyfiscalprinter/controller.py | 1 - pyfiscalprinter/epson_ext.py | 178 ++++++++++++++-------------- pyfiscalprinter/epson_ext_driver.py | 5 +- 3 files changed, 88 insertions(+), 96 deletions(-) diff --git a/pyfiscalprinter/controller.py b/pyfiscalprinter/controller.py index 72311a2..287de87 100755 --- a/pyfiscalprinter/controller.py +++ b/pyfiscalprinter/controller.py @@ -220,7 +220,6 @@ def AbrirComprobante(self, else: ret = printer.openTicket() elif cbte_fiscal.startswith("F"): - print('aca') ret = printer.openBillTicket(letra_cbte, nombre_cliente, domicilio_cliente, nro_doc, doc_fiscal, pos_fiscal) elif cbte_fiscal.startswith("ND"): diff --git a/pyfiscalprinter/epson_ext.py b/pyfiscalprinter/epson_ext.py index 7788938..5259950 100755 --- a/pyfiscalprinter/epson_ext.py +++ b/pyfiscalprinter/epson_ext.py @@ -398,28 +398,28 @@ def getStatus(self,status, printer): def recursiveDict(self, element): - tag = element.tag - if element.tag == 'conjuntoComprobantesFiscales': - self.i = self.i + 1 - tag = element.tag + str(self.i) + tag = element.tag + if element.tag == 'conjuntoComprobantesFiscales': + self.i = self.i + 1 + tag = element.tag + str(self.i) - return tag, dict(map(self.recursiveDict,element)) or element.text + return tag, dict(map(self.recursiveDict,element)) or element.text def changeKeyToDictForDocumentId(self, key, dictionary): - new_key = dictionary[key]['codigoTipoComprobante'] - dictionary[new_key] = dictionary.pop(key) + new_key = dictionary[key]['codigoTipoComprobante'] + dictionary[new_key] = dictionary.pop(key) - return dictionary + return dictionary def extractInfoToXml(self, xml): - self.i = 0 - text = re.findall(r'((.*))', xml) - try: - root = etree.XML(bytes(text[0][0].encode('utf8'))) - except Exception as e: - print('Create xml error', e) + self.i = 0 + text = re.findall(r'((.*))', xml) + try: + root = etree.XML(bytes(text[0][0].encode('utf8'))) + except Exception as e: + print('Create xml error', e) - return self.recursiveDict(root)[1] + return self.recursiveDict(root)[1] def getDailyCloseData(self, receipt_number): self._sendCommand('0813|0000', [str(receipt_number), str(receipt_number)]) @@ -496,26 +496,20 @@ def getDailyCloseData(self, receipt_number): return response def dailyClose(self, type): - tique_a = self._sendCommand('080A|0000', ["82"]) - tique = self._sendCommand('080A|0000', ["83"]) - tique_b = self._sendCommand('080A|0000', ["81"]) - nota_credito_a = self._sendCommand('080A|0000', ["112"]) - nota_credito_b = self._sendCommand('080A|0000', ["113"]) - nota_credito_c = self._sendCommand('080A|0000', ["114"]) if type == 'Z': - reply = self._sendCommand(self.commands['CMD_DAILY_CLOSE'], []) - try: - receipt_number = reply[2] - self._sendCommand('0813|0000', [str(receipt_number), str(receipt_number)]) - reply_xml = self._sendCommand('0814|0000', []) - try: - xml = reply_xml[2] - info_close_daily = self.extractInfoToXml(xml + ' Date: Tue, 28 Feb 2023 11:37:45 -0300 Subject: [PATCH 3/5] added/audit-when-close-daily auto-commit --- pyfiscalprinter/epson_ext.py | 94 +++++++----------------------------- 1 file changed, 18 insertions(+), 76 deletions(-) diff --git a/pyfiscalprinter/epson_ext.py b/pyfiscalprinter/epson_ext.py index 5259950..3b19442 100755 --- a/pyfiscalprinter/epson_ext.py +++ b/pyfiscalprinter/epson_ext.py @@ -450,25 +450,33 @@ def getDailyCloseData(self, receipt_number): credit_documents_b = 0 credit_total_b = 0.00 credit_tax_b = 0.00 + sales_first_a = '0000000' + sales_first_b = '0000000' + credit_first_a = '00000000' + credit_first_b = '00000000' if '081' in info_close_daily['arrayConjuntosComprobantesFiscales']: sales_documents_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['cantidadComprobantes'] sales_last_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['ultimoNumeroComprobante'] + sales_first_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['primerNumeroComprobante'] sales_total_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['081']['importeTotalComprobantes']) sales_tax_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['081']['arraySubtotalesIVA']['subtotalIVA']['importe']) if '082' in info_close_daily['arrayConjuntosComprobantesFiscales']: sales_documents_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['cantidadComprobantes'] sales_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['ultimoNumeroComprobante'] + sales_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['primerNumeroComprobante'] sales_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['082']['importeTotalComprobantes']) sales_tax_b = 0.00 if '112' in info_close_daily['arrayConjuntosComprobantesFiscales']: credit_documents_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['cantidadComprobantes'] credit_last_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['ultimoNumeroComprobante'] + credit_first_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['primerNumeroComprobante'] credit_total_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['112']['importeTotalComprobantes']) credit_tax_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['112']['arraySubtotalesIVA']['subtotalIVA']['importe']) if '113' in info_close_daily['arrayConjuntosComprobantesFiscales']: credit_documents_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['cantidadComprobantes'] credit_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['ultimoNumeroComprobante'] + credit_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['primerNumeroComprobante'] credit_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['113']['importeTotalComprobantes']) credit_tax_b = 0.00 if xml == 'empty': @@ -491,6 +499,10 @@ def getDailyCloseData(self, receipt_number): int(credit_documents_a) + int(credit_documents_b), credit_total_a + credit_total_b, credit_tax_a + credit_tax_b, + sales_first_a, + sales_first_b, + credit_first_a, + credit_first_b, ] return response @@ -498,85 +510,15 @@ def getDailyCloseData(self, receipt_number): def dailyClose(self, type): if type == 'Z': reply = self._sendCommand(self.commands['CMD_DAILY_CLOSE'], []) - try: - receipt_number = reply[2] - self._sendCommand('0813|0000', [str(receipt_number), str(receipt_number)]) - reply_xml = self._sendCommand('0814|0000', []) - try: - xml = reply_xml[2] - info_close_daily = self.extractInfoToXml(xml + ' Date: Tue, 7 Mar 2023 15:12:08 -0300 Subject: [PATCH 4/5] added/audit-when-close-daily auto-commit --- pyfiscalprinter/epson_ext.py | 151 ++++++++++++++++------------------- 1 file changed, 68 insertions(+), 83 deletions(-) diff --git a/pyfiscalprinter/epson_ext.py b/pyfiscalprinter/epson_ext.py index 3b19442..10a6d7d 100755 --- a/pyfiscalprinter/epson_ext.py +++ b/pyfiscalprinter/epson_ext.py @@ -224,25 +224,15 @@ def addItem(self, description, quantity, price, iva, discount, discountDescripti quantityStr = str(int(quantity * 10000)) ivaStr = str(int(iva * 100)) codigo_frente_iva = "7" - if self._currentDocumentType != 'A': - ivaStr = '0000' - codigo_frente_iva = "1" - # enviar con el iva incluido - if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: - # nota de crédito? - priceUnitStr = str(int(floor(price * 10000))) - else: - priceUnitStr = str(int(round(price * 10000, 0))) + net = price / ((100.0 + iva) / 100.0) + if round_up: + net = self.float_round_up(net, 2) + # enviar sin el iva (factura A) + if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: + # nota de crédito? + priceUnitStr = str(int(floor(net * 10000))) else: - net = price / ((100.0 + iva) / 100.0) - if round_up: - net = self.float_round_up(net, 2) - # enviar sin el iva (factura A) - if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: - # nota de crédito? - priceUnitStr = str(int(floor(net * 10000))) - else: - priceUnitStr = str(int(round(net * 10000, 0))) + priceUnitStr = str(int(round(net * 10000, 0))) parameters = [ "", @@ -286,14 +276,14 @@ def addItem(self, description, quantity, price, iva, discount, discountDescripti return reply def addPayment(self, description, payment): - paymentStr = str(int(payment * 10000)) + paymentStr = str(int(payment * 100)) parameters = [ formatText(description)[:20], "", "", "", "", - "1", + "8", paymentStr ] status = self._sendCommand(self.commands['CMD_ADD_PAYMENT'][self._getCommandIndex()], parameters) @@ -313,21 +303,11 @@ def addAdditional(self, description, amount, iva, negative=False): if negative: command = self.commands['CMD_PRINT_DISCOUNT'] - - if self._currentDocumentType != 'A': - ivaStr = '0000' - codigo_frente_iva = "1" - # enviar con el iva incluido - if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: - priceUnitStr = str(int(ceil(priceUnit * 10000))) - else: - priceUnitStr = str(int(round(priceUnit * 10000, 0))) + # enviar sin el iva (factura A) + if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: + priceUnitStr = str(int(ceil((priceUnit / ((100.0 + iva) / 100)) * 10000))) else: - # enviar sin el iva (factura A) - if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']: - priceUnitStr = str(int(ceil((priceUnit / ((100.0 + iva) / 100)) * 10000))) - else: - priceUnitStr = str(int(round((priceUnit / ((100.0 + iva) / 100)) * 10000, 0))) + priceUnitStr = str(int(round((priceUnit / ((100.0 + iva) / 100)) * 10000, 0))) parameters = [ "", @@ -427,61 +407,65 @@ def getDailyCloseData(self, receipt_number): try: xml = reply_xml[2] info_close_daily = self.extractInfoToXml(xml + '(.*))', xml + ' Date: Tue, 7 Mar 2023 15:29:23 -0300 Subject: [PATCH 5/5] added/audit-when-close-daily auto-commit --- pyfiscalprinter/epson_ext.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyfiscalprinter/epson_ext.py b/pyfiscalprinter/epson_ext.py index 10a6d7d..916da8a 100755 --- a/pyfiscalprinter/epson_ext.py +++ b/pyfiscalprinter/epson_ext.py @@ -452,7 +452,10 @@ def getDailyCloseData(self, receipt_number): sales_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['ultimoNumeroComprobante'] sales_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['primerNumeroComprobante'] sales_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['082']['importeTotalComprobantes']) - sales_tax_b = 0.00 + try: + sales_tax_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['082']['arraySubtotalesIVA']['subtotalIVA']['importe']) + except: + sales_tax_b = 0.00 if '112' in info_close_daily['arrayConjuntosComprobantesFiscales']: credit_documents_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['cantidadComprobantes'] credit_last_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['ultimoNumeroComprobante'] @@ -464,7 +467,10 @@ def getDailyCloseData(self, receipt_number): credit_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['ultimoNumeroComprobante'] credit_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['primerNumeroComprobante'] credit_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['113']['importeTotalComprobantes']) - credit_tax_b = 0.00 + try: + credit_tax_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['113']['arraySubtotalesIVA']['subtotalIVA']['importe']) + except: + credit_tax_b = 0.00 response = [ str(receipt_number).zfill(8),