1 # -*- coding: utf-8 -*-
13 import werkzeug.wrappers
14 _logger = logging.getLogger(__name__)
17 from openerp import http
18 from openerp.http import request
21 # drivers modules must add to drivers an object with a get_status() method
22 # so that 'status' can return the status of all active drivers
25 class Proxy(http.Controller):
29 for driver in drivers:
30 statuses[driver] = drivers[driver].get_status()
33 @http.route('/hw_proxy/hello', type='http', auth='none', cors='*')
37 @http.route('/hw_proxy/handshake', type='json', auth='none', cors='*')
41 @http.route('/hw_proxy/status', type='http', auth='none', cors='*')
42 def status_http(self):
47 <title>Odoo's PosBox</title>
52 font-family: sans-serif;
57 border-bottom: solid 1px rgb(216,216,216);
60 .device:nth-child(2n) {
61 background:rgb(240,240,240);
66 <h1>Hardware Status</h1>
67 <p>The list of enabled drivers and their status</p>
69 statuses = self.get_status()
70 for driver in statuses:
72 status = statuses[driver]
74 if status['status'] == 'connecting':
76 elif status['status'] == 'connected':
81 resp += "<h3 style='color:"+color+";'>"+driver+' : '+status['status']+"</h3>\n"
83 for msg in status['messages']:
84 resp += '<li>'+msg+'</li>\n'
87 <h2>Connected Devices</h2>
88 <p>The list of connected USB devices as seen by the posbox</p>
90 devices = commands.getoutput("lsusb").split('\n')
91 resp += "<div class='devices'>\n"
92 for device in devices:
93 device_name = device[device.find('ID')+2:]
94 resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n"
97 <h2>Add New Printer</h2>
99 Copy and paste your printer's device description in the form below. You can find
100 your printer's description in the device list above. If you find that your printer works
101 well, please send your printer's description to <a href='mailto:support@openerp.com'>
102 support@openerp.com</a> so that we can add it to the default list of supported devices.
104 <form action='/hw_proxy/escpos/add_supported_device' method='GET'>
105 <input type='text' style='width:400px' name='device_string' placeholder='123a:b456 Sample Device description' />
106 <input type='submit' value='submit' />
108 <h2>Reset To Defaults</h2>
109 <p>If the added devices cause problems, you can <a href='/hw_proxy/escpos/reset_supported_devices'>Reset the
110 device list to factory default.</a> This operation cannot be undone.</p>
112 resp += "</body>\n</html>\n\n"
114 return request.make_response(resp,{
115 'Cache-Control': 'no-cache',
116 'Content-Type': 'text/html; charset=utf-8',
117 'Access-Control-Allow-Origin': '*',
118 'Access-Control-Allow-Methods': 'GET',
121 @http.route('/hw_proxy/status_json', type='json', auth='none', cors='*')
122 def status_json(self):
123 return self.get_status()
125 @http.route('/hw_proxy/scan_item_success', type='json', auth='none', cors='*')
126 def scan_item_success(self, ean):
128 A product has been scanned with success
130 print 'scan_item_success: ' + str(ean)
132 @http.route('/hw_proxy/scan_item_error_unrecognized', type='json', auth='none', cors='*')
133 def scan_item_error_unrecognized(self, ean):
135 A product has been scanned without success
137 print 'scan_item_error_unrecognized: ' + str(ean)
139 @http.route('/hw_proxy/help_needed', type='json', auth='none', cors='*')
140 def help_needed(self):
142 The user wants an help (ex: light is on)
146 @http.route('/hw_proxy/help_canceled', type='json', auth='none', cors='*')
147 def help_canceled(self):
149 The user stops the help request
151 print "help_canceled"
153 @http.route('/hw_proxy/payment_request', type='json', auth='none', cors='*')
154 def payment_request(self, price):
156 The PoS will activate the method payment
158 print "payment_request: price:"+str(price)
161 @http.route('/hw_proxy/payment_status', type='json', auth='none', cors='*')
162 def payment_status(self):
163 print "payment_status"
164 return { 'status':'waiting' }
166 @http.route('/hw_proxy/payment_cancel', type='json', auth='none', cors='*')
167 def payment_cancel(self):
168 print "payment_cancel"
170 @http.route('/hw_proxy/transaction_start', type='json', auth='none', cors='*')
171 def transaction_start(self):
172 print 'transaction_start'
174 @http.route('/hw_proxy/transaction_end', type='json', auth='none', cors='*')
175 def transaction_end(self):
176 print 'transaction_end'
178 @http.route('/hw_proxy/cashier_mode_activated', type='json', auth='none', cors='*')
179 def cashier_mode_activated(self):
180 print 'cashier_mode_activated'
182 @http.route('/hw_proxy/cashier_mode_deactivated', type='json', auth='none', cors='*')
183 def cashier_mode_deactivated(self):
184 print 'cashier_mode_deactivated'
186 @http.route('/hw_proxy/open_cashbox', type='json', auth='none', cors='*')
187 def open_cashbox(self):
190 @http.route('/hw_proxy/print_receipt', type='json', auth='none', cors='*')
191 def print_receipt(self, receipt):
192 print 'print_receipt' + str(receipt)
194 @http.route('/hw_proxy/is_scanner_connected', type='json', auth='none', cors='*')
195 def print_receipt(self, receipt):
196 print 'is_scanner_connected?'
199 @http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
200 def print_receipt(self, receipt):
205 @http.route('/hw_proxy/log', type='json', auth='none', cors='*')
206 def log(self, arguments):
207 _logger.info(' '.join(str(v) for v in arguments))
209 @http.route('/hw_proxy/print_pdf_invoice', type='json', auth='none', cors='*')
210 def print_pdf_invoice(self, pdfinvoice):
211 print 'print_pdf_invoice' + str(pdfinvoice)