zoukankan      html  css  js  c++  java
  • 让 Odoo POS 支持廉价小票打印机

    为了测试 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 中测试通过。

  • 相关阅读:
    HttpSession
    查看端口被哪个进程占用了
    变体类型 Variant VARIANT
    BDE View not exists
    c++builder 解压缩
    nginx的allow和deny配置
    linux下如何启动nginx?
    java如何发起一次http的post请求?
    mysql如何用sql添加字段如何设置字符集和排序规则
    设置Tomcat的UTF-8编码
  • 原文地址:https://www.cnblogs.com/oldrev/p/odoo-cheap-receipt-printer-workaround.html
Copyright © 2011-2022 走看看