Skip to content

Instantly share code, notes, and snippets.

@yelizariev
Last active April 11, 2018 12:21
Show Gist options
  • Save yelizariev/082bbe57e1ed63045ef28441b6f97147 to your computer and use it in GitHub Desktop.
Save yelizariev/082bbe57e1ed63045ef28441b6f97147 to your computer and use it in GitHub Desktop.
Emulate odoo pos BOX

hw_escpos

  • apply patch

  • install hw_escpos on odoo

  • run odoo with -d DB_WITH_HW_ESCPOS --db-filter=DB_WITH_HW_ESCPOS

  • in new terminal run

    tail -f /tmp/printer

On printing:

  • some binary data is sent to /tmp/printer
  • odoo prints logs with unparsed data (see example.html)

screenticket

Optional.

It seems that it doesn't work and need to be fixed

git clone https://github.com/it-projects-llc/screenticket.git
cd screenticket
sudo apt-get install libqt4-dev qt4-qmake
qmake
make
sudo make install

POS

  • set Receipt printer checkbox in pos.config and set ip equal to 127.0.0.1
  • open POS interface (at any database, including one on runbot)
  • print ticket
<receipt align="center" value-thousands-separator="" width="40">
<img src="CUT"/>
<br/>
<div font="b">
<div>Stock</div>
<div>YourCompany</div>
<div>Tel:+1 555 123 8069</div>
<div>[email protected]</div>
<div>http://www.example.com</div>
<div class="cashier">
<div>--------------------------------</div>
<div>Served by Administrator</div>
at table T1
<div>Guests: 1</div>
</div>
</div>
<br/><br/>
<div line-ratio="0.6">
<line><left>Hotel Accommodation</left></line>
<line indent="1">
<left>
<value value-autoint="on" value-decimals="3">
1
</value>
Day(s)
x
<value value-decimals="2">
400
</value>
</left>
<right>
<value>400</value>
</right>
</line>
<line>
<left>Cow milk</left>
<right><value>8</value></right>
</line>
<line>
<left>Milkshake Chocolate</left>
<right><value>3.6</value></right>
</line>
</div>
<line><right>--------</right></line>
<line size="double-height">
<left><pre> TOTAL</pre></left>
<right><value>411.6</value></right>
</line>
<br/><br/>
<br/>
<div font="b">
<div>Order 00007-001-0001</div>
<div>1/11/2017, 7:13:11 PM</div>
</div>
</receipt>
diff --git a/addons/hw_escpos/controllers/main.py b/addons/hw_escpos/controllers/main.py
index 812e8d7..9ff2f50 100644
--- a/addons/hw_escpos/controllers/main.py
+++ b/addons/hw_escpos/controllers/main.py
@@ -9,11 +9,13 @@ import os.path
import subprocess
import time
import traceback
+import re
try:
from .. escpos import *
from .. escpos.exceptions import *
from .. escpos.printer import Usb
+ from .. escpos.printer import File
except ImportError:
escpos = printer = None
@@ -97,7 +99,8 @@ class EscposDriver(Thread):
self.start()
def get_escpos_printer(self):
-
+ self.set_status('connected','Connected')
+ return File('/tmp/printer')
printers = self.connected_usb_devices()
if len(printers) > 0:
print_dev = Usb(printers[0]['vendor'], printers[0]['product'])
@@ -160,6 +163,10 @@ class EscposDriver(Thread):
elif task == 'xml_receipt':
if timestamp >= time.time() - 1 * 60 * 60:
printer.receipt(data)
+ print 'PRINTER DATA'
+ cut = data
+ cut = re.sub('img src="[^"]*"', 'img src="CUT"', cut)
+ print cut
elif task == 'cashbox':
if timestamp >= time.time() - 12:
self.open_cashbox(printer)
diff --git a/addons/hw_escpos/escpos/printer.py b/addons/hw_escpos/escpos/printer.py
index f994d94..24dbaa8 100644
--- a/addons/hw_escpos/escpos/printer.py
+++ b/addons/hw_escpos/escpos/printer.py
@@ -217,3 +217,30 @@ class Network(Escpos):
""" Close TCP connection """
self.device.close()
+
+class File(Escpos):
+ def __init__(self, file="/tmp/printer"):
+ self.file = file
+ self.open()
+
+ def open(self):
+ self.fd = open(self.file, 'a')
+
+ if self.fd is not None:
+ print "File printer enabled"
+ else:
+ print "Unable to open file printer : %s" % self.file
+
+ def _raw(self, msg):
+ """ Print any command sent in raw format """
+ self.fd.write(msg)
+
+ def __del__(self):
+ """ Close Serial interface """
+ if self.device is not None:
+ self.device.close()
+
+ def close(self):
+ """ Close Serial interface """
+ if self.device is not None:
+ self.device.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment