为了测试 Odoo 在实际业务中的实施,我们开了一家(马上要开第二家分店)猪肉店。由于预算有限,在实施 Odoo PoS 的时候采购了一台价格为 85 元的爱宝热敏打印机,结果连上 Odoo Posbox 以后发现无法识别。

由于该打印机是支持标准 ESC/POS 指令集的,所以肯定具备 Odoo 所需的软硬件要求。唯一的问题是 Odoo 无法识别该打印机,经过多番搜索,在 Github 上找到了解决方案:

https://github.com/odoo/odoo/issues/12485

故障的原因是因为这种国产打印机为了方便在打印机里内置了一个存储着 Windows 驱动程序的优盘,造成了其 USB 接口与标准的 EPSON TM-120 打印机不一致。

所以我们需要在 Odoo 的小票打印机驱动模块 hw_escpos 里做一些 workaround。

具体来说,就是修改 Odoo 的 hw_escpos 模块中的 printer.py 文件,将 Usb 类的 open() 方法修改为以下代码:

 

    def open(self):
        """ Search device on USB tree and set is as escpos device """
        
        self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
        if self.device is None:
            raise NoDeviceError()
        try:
            try:
                cfg = self.device.get_active_configuration()
                for intf in cfg:
                    if intf.bInterfaceNumber == self.interface:
                        for ep in intf:
                            if ep.bEndpointAddress < 0x80:
                                self.out_ep = ep.bEndpointAddress   # change out_ep, calling sequence to be improved....
                    if self.device.is_kernel_driver_active(intf.bInterfaceNumber):
                        self.device.detach_kernel_driver(intf.bInterfaceNumber)
            except Error as e:
                print e
                self.device.detach_kernel_driver(self.interface)


            self.device.set_configuration()
            usb.util.claim_interface(self.device, self.interface)
        except usb.core.USBError as e:
            raise HandleDeviceError(e)

代码修改完毕,通过 SSH scp 之类的方式上传到 Posbox 里覆盖源文件再重启即可。

* 以上代码在 Odoo 9.0 和 Odoo 10.0 中测试通过。