From 463c0ff3a2d8e1f2f9b1953eaff77a53f18482d4 Mon Sep 17 00:00:00 2001 From: Antoine Prieels Date: Thu, 4 Jul 2019 08:25:10 +0000 Subject: [PATCH] [IMP] hw_drivers: Print Star printers notice We communicate with receipt printers using the ESCPOS drivers. By default, Star printers use the Star mode. This can be changed by modifying the position of the DIP-Switches at the bottom of the printer. We provide a link to the documentation to the user if its printer is not correctly configured. --- addons/hw_drivers/drivers/PrinterDriver.py | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/addons/hw_drivers/drivers/PrinterDriver.py b/addons/hw_drivers/drivers/PrinterDriver.py index 029ef1ee7c2..99edad4e6bc 100644 --- a/addons/hw_drivers/drivers/PrinterDriver.py +++ b/addons/hw_drivers/drivers/PrinterDriver.py @@ -21,6 +21,32 @@ from odoo.addons.hw_proxy.controllers.main import drivers as old_drivers _logger = logging.getLogger(__name__) +def print_star_error(deviceId): + """We communicate with receipt printers using the ESCPOS protocol. + By default, Star printers use the Star mode. This can be changed by + modifying the position of the DIP-Switches at the bottom of the printer. + """ + error_page = ( + "\x1B\x1D\x61\x01" # Centering start + "\x1B\x69\x01\x01Bad configuration\x1B\x69\x00\x00" # Title, double size + "\n\n--------------------\n\n" + "\x1B\x1D\x61\x00" # Centering Stop + "Your printer is in Star line mode, but should\n" + "use ESC/POS mode. You will not be able to print\n" + "receipts without changing your configuration.\n\n" + "For more details and instructions on how to\n" + "configure your printer, please refer to:\n\n" + "\x1B\x1D\x61\x01" # Centering start + "\x1B\x2D\x01" # Underline start + "http://www.odoo.com" # TODO: Replace URL + "\x0A\x0A" + "\x1B\x2D\x00" # Underline stop + "\x1B\x1D\x61\x00" # Centering stop + "\x1B\x64\x02" # Full Cut + ) + process = subprocess.Popen(["lp", "-d", deviceId], stdin=subprocess.PIPE) + process.communicate(error_page.encode("utf-8")) + def cups_notification_handler(message, uri, device_id, state, reason, accepting_jobs): if device_id in iot_devices: reason = reason if reason != 'none' else None @@ -89,7 +115,11 @@ class PrinterDriver(Driver): conn.addPrinterOptionDefault(device['identifier'], "usb-unidir", "true") else: device['device-make-and-model'] = printers[device['identifier']]['printer-info'] - return True + if 'STR_T' in device['device-id']: + # Star printers have either STR_T or ESP in their name depending on the protocol used. + print_star_error(device['identifier']) + else: + return True return False @classmethod