1 # -*- coding: utf-8 -*-
13 import werkzeug.wrappers
14 _logger = logging.getLogger(__name__)
17 from openerp import http
18 from openerp.http import request
19 from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
22 # drivers modules must add to drivers an object with a get_status() method
23 # so that 'status' can return the status of all active drivers
26 class Proxy(http.Controller):
30 for driver in drivers:
31 statuses[driver] = drivers[driver].get_status()
34 @http.route('/hw_proxy/hello', type='http', auth='none', cors='*')
38 @http.route('/hw_proxy/handshake', type='json', auth='none', cors='*')
42 @http.route('/hw_proxy/status', type='http', auth='none', cors='*')
43 def status_http(self):
48 <title>OpenERP's PosBox</title>
53 font-family: sans-serif;
58 border-bottom: solid 1px rgb(216,216,216);
61 .device:nth-child(2n) {
62 background:rgb(240,240,240);
67 <h1>Hardware Status</h1>
68 <p>The list of enabled drivers and their status</p>
70 statuses = self.get_status()
71 for driver in statuses:
73 status = statuses[driver]
75 if status['status'] == 'connecting':
77 elif status['status'] == 'connected':
82 resp += "<h3 style='color:"+color+";'>"+driver+' : '+status['status']+"</h3>\n"
84 for msg in status['messages']:
85 resp += '<li>'+msg+'</li>\n'
88 <h2>Connected Devices</h2>
89 <p>The list of connected USB devices as seen by the posbox</p>
91 devices = commands.getoutput("lsusb").split('\n')
92 resp += "<div class='devices'>\n"
93 for device in devices:
94 device_name = device[device.find('ID')+2:]
95 resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n"
98 <h2>Add New Printer</h2>
100 Copy and paste your printer's device description in the form below. You can find
101 your printer's description in the device list above. If you find that your printer works
102 well, please send your printer's description to <a href='mailto:support@openerp.com'>
103 support@openerp.com</a> so that we can add it to the default list of supported devices.
105 <form action='/hw_proxy/escpos/add_supported_device' method='GET'>
106 <input type='text' style='width:400px' name='device_string' placeholder='123a:b456 Sample Device description' />
107 <input type='submit' value='submit' />
109 <h2>Reset To Defaults</h2>
110 <p>If the added devices cause problems, you can <a href='/hw_proxy/escpos/reset_supported_devices'>Reset the
111 device list to factory default.</a> This operation cannot be undone.</p>
113 resp += "</body>\n</html>\n\n"
115 return request.make_response(resp,{
116 'Cache-Control': 'no-cache',
117 'Content-Type': 'text/html; charset=utf-8',
118 'Access-Control-Allow-Origin': '*',
119 'Access-Control-Allow-Methods': 'GET',
122 @http.route('/hw_proxy/status_json', type='json', auth='none', cors='*')
123 def status_json(self):
124 return self.get_status()
126 @http.route('/hw_proxy/scan_item_success', type='json', auth='none', cors='*')
127 def scan_item_success(self, ean):
129 A product has been scanned with success
131 print 'scan_item_success: ' + str(ean)
133 @http.route('/hw_proxy/scan_item_error_unrecognized', type='json', auth='none', cors='*')
134 def scan_item_error_unrecognized(self, ean):
136 A product has been scanned without success
138 print 'scan_item_error_unrecognized: ' + str(ean)
140 @http.route('/hw_proxy/help_needed', type='json', auth='none', cors='*')
141 def help_needed(self):
143 The user wants an help (ex: light is on)
147 @http.route('/hw_proxy/help_canceled', type='json', auth='none', cors='*')
148 def help_canceled(self):
150 The user stops the help request
152 print "help_canceled"
154 @http.route('/hw_proxy/payment_request', type='json', auth='none', cors='*')
155 def payment_request(self, price):
157 The PoS will activate the method payment
159 print "payment_request: price:"+str(price)
162 @http.route('/hw_proxy/payment_status', type='json', auth='none', cors='*')
163 def payment_status(self):
164 print "payment_status"
165 return { 'status':'waiting' }
167 @http.route('/hw_proxy/payment_cancel', type='json', auth='none', cors='*')
168 def payment_cancel(self):
169 print "payment_cancel"
171 @http.route('/hw_proxy/transaction_start', type='json', auth='none', cors='*')
172 def transaction_start(self):
173 print 'transaction_start'
175 @http.route('/hw_proxy/transaction_end', type='json', auth='none', cors='*')
176 def transaction_end(self):
177 print 'transaction_end'
179 @http.route('/hw_proxy/cashier_mode_activated', type='json', auth='none', cors='*')
180 def cashier_mode_activated(self):
181 print 'cashier_mode_activated'
183 @http.route('/hw_proxy/cashier_mode_deactivated', type='json', auth='none', cors='*')
184 def cashier_mode_deactivated(self):
185 print 'cashier_mode_deactivated'
187 @http.route('/hw_proxy/open_cashbox', type='json', auth='none', cors='*')
188 def open_cashbox(self):
191 @http.route('/hw_proxy/print_receipt', type='json', auth='none', cors='*')
192 def print_receipt(self, receipt):
193 print 'print_receipt' + str(receipt)
195 @http.route('/hw_proxy/is_scanner_connected', type='json', auth='none', cors='*')
196 def print_receipt(self, receipt):
197 print 'is_scanner_connected?'
200 @http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
201 def print_receipt(self, receipt):
206 @http.route('/hw_proxy/log', type='json', auth='none', cors='*')
207 def log(self, arguments):
208 _logger.info(' '.join(str(v) for v in arguments))
210 @http.route('/hw_proxy/print_pdf_invoice', type='json', auth='none', cors='*')
211 def print_pdf_invoice(self, pdfinvoice):
212 print 'print_pdf_invoice' + str(pdfinvoice)