Пример #1
0
    def __init__(self):
        """Setup printer configuration

        """
        from proxypos.proxypos import config
        # Init printer
        ptype = config.get('printer.type').lower()
        settings = config.get('printer.settings')
        if ptype == 'usb':
            self.printer = printer.Usb(settings['idVendor'],
                                       settings['idProduct'])
        elif ptype == 'serial':
            self.printer = printer.Serial(settings['devfile'])
        elif ptype == 'network':
            self.printer = printer.Network(settings['host'])
        # Assign other default values
        self.printer.pxWidth = settings['pxWidth']
        # Set default widht with normal value
        self.printer.width = self.printer.widthA = settings['WidthA']
        self.printer.widthB = settings['WidthB']
        # Set correct table character
        if 'charSet' in settings:
            self.printer.text(settings['charSet'])
Пример #2
0
    def __init__(self):
        """Setup printer configuration

        """
        from proxypos.proxypos import config
        # Init printer
        ptype = config.get('printer.type').lower()
        settings = config.get('printer.settings')
        if ptype == 'usb':
            self.printer = printer.Usb(settings['idVendor'],
                                       settings['idProduct'])
        elif ptype == 'serial':
            self.printer = printer.Serial(settings['devfile'])
        elif ptype == 'network':
            self.printer = printer.Network(settings['host'])
        # Assign other default values
        self.printer.pxWidth = settings['pxWidth']
        # Set default widht with normal value
        self.printer.width = self.printer.widthA = settings['WidthA']
        self.printer.widthB = settings['WidthB']
        # Set correct table character
        if 'charSet' in settings:
            self.printer.text(settings['charSet'])
Пример #3
0
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)