def is_alive(): """ Test if printer is connected """ params = dict(request.params) logger.debug('Testing printer connection....') result = 'ok' try: printer.device() except: result = 'no' logger.debug('params: %s' % str(params)) # Getting jquery id jquery = params['jsonp'] answer = '%s({"result": "%s"});' % (jquery, result) # Set response as json response.headers['Content-type'] = 'application/json' return answer
def open_cashbox(): """ Open the cash box """ logger.info('open_cashbox') try: device = printer.device() device.open_cashbox() except (SystemExit, KeyboardInterrupt): raise except Exception: logger.error('Failed to open the cashbox', exc_info=True) return
def do_print(receipt): # Import configuration from proxypos.proxypos import config import copy # Process receipt and split content if needed logger.debug('Max Lines configuration: %s', str(config.get('receipt.maxLines'))) receipts = [] if (config.get('receipt.maxLines') > 0 and len(receipt['orderlines']) > config.get('receipt.maxLines')): logger.debug('Spliting %s', receipt['orderlines']) # Split orderlines in chunks chunks = _chunks(receipt['orderlines'], config.get('receipt.maxLines')) # Process each chunk and create new receipts for chunk in chunks: tmpreceipt = copy.deepcopy(receipt) # Replacer orderlines with current chunk tmpreceipt['orderlines'] = chunk # Recalculate total for this chunk tmpreceipt['discount'] = _total(chunk, 'discount') tmpreceipt['total_without_tax'] = _total(chunk, 'price_without_tax') tmpreceipt['total_with_tax'] = _total(chunk, 'price_with_tax') receipts.append(tmpreceipt) else: receipts.append(receipt) # Here the receipts are actually printed for receipt in receipts: try: logger.info('Printing receipt %s', str(receipt)) device = printer.device() device.print_receipt(receipt) if config.get('receipt.cutPaper'): device.lineFeedCut(1, True) except Exception: logger.error('Failed to print receipt', exc_info=True)