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/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..916da8a --- 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"] @@ -221,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 = [ "", @@ -283,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) @@ -310,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 = [ "", @@ -384,8 +367,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,49 +376,141 @@ def getStatus(self,status, printer): ] return status(response, printer) - 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'], []) - if type == 'X': - reply = self._sendCommand(self.commands['CMD_TELLER_EXIT'], []) + 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: - receipt_number = reply[2] + root = etree.XML(bytes(text[0][0].encode('utf8'))) except Exception as e: - receipt_number = "null" + print('Create xml error', e) + + return self.recursiveDict(root)[1] - if receipt_number == "null": + 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 + '(.*))', xml + '