為了測試 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 中測試通過。
