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):
29 self.scale_weight = 0.0
33 for driver in drivers:
34 statuses[driver] = drivers[driver].get_status()
37 @http.route('/hw_proxy/hello', type='http', auth='none', cors='*')
41 @http.route('/hw_proxy/handshake', type='json', auth='none', cors='*')
45 @http.route('/hw_proxy/status', type='http', auth='none', cors='*')
46 def status_http(self):
51 <title>OpenERP's PosBox</title>
56 font-family: sans-serif;
61 border-bottom: solid 1px rgb(216,216,216);
64 .device:nth-child(2n) {
65 background:rgb(240,240,240);
70 <h1>Hardware Status</h1>
71 <p>The list of enabled drivers and their status</p>
73 statuses = self.get_status()
74 for driver in statuses:
76 status = statuses[driver]
78 if status['status'] == 'connecting':
80 elif status['status'] == 'connected':
85 resp += "<h3 style='color:"+color+";'>"+driver+' : '+status['status']+"</h3>\n"
87 for msg in status['messages']:
88 resp += '<li>'+msg+'</li>\n'
91 <h2>Connected Devices</h2>
92 <p>The list of connected USB devices as seen by the posbox</p>
94 devices = commands.getoutput("lsusb").split('\n')
95 resp += "<div class='devices'>\n"
96 for device in devices:
97 device_name = device[device.find('ID')+2:]
98 resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n"
101 <h2>Add New Printer</h2>
103 Copy and paste your printer's device description in the form below. You can find
104 your printer's description in the device list above. If you find that your printer works
105 well, please send your printer's description to <a href='mailto:support@openerp.com'>
106 support@openerp.com</a> so that we can add it to the default list of supported devices.
108 <form action='/hw_proxy/escpos/add_supported_device' method='GET'>
109 <input type='text' style='width:400px' name='device_string' placeholder='123a:b456 Sample Device description' />
110 <input type='submit' value='submit' />
112 <h2>Reset To Defaults</h2>
113 <p>If the added devices cause problems, you can <a href='/hw_proxy/escpos/reset_supported_devices'>Reset the
114 device list to factory default.</a> This operation cannot be undone.</p>
116 resp += "</body>\n</html>\n\n"
118 return request.make_response(resp,{
119 'Cache-Control': 'no-cache',
120 'Content-Type': 'text/html; charset=utf-8',
121 'Access-Control-Allow-Origin': '*',
122 'Access-Control-Allow-Methods': 'GET',
125 @http.route('/hw_proxy/status_json', type='json', auth='none', cors='*')
126 def status_json(self):
127 return self.get_status()
129 @http.route('/hw_proxy/scan_item_success', type='json', auth='none', cors='*')
130 def scan_item_success(self, ean):
132 A product has been scanned with success
134 print 'scan_item_success: ' + str(ean)
136 @http.route('/hw_proxy/scan_item_error_unrecognized', type='json', auth='none', cors='*')
137 def scan_item_error_unrecognized(self, ean):
139 A product has been scanned without success
141 print 'scan_item_error_unrecognized: ' + str(ean)
143 @http.route('/hw_proxy/help_needed', type='json', auth='none', cors='*')
144 def help_needed(self):
146 The user wants an help (ex: light is on)
150 @http.route('/hw_proxy/help_canceled', type='json', auth='none', cors='*')
151 def help_canceled(self):
153 The user stops the help request
155 print "help_canceled"
157 @http.route('/hw_proxy/weighting_start', type='json', auth='none', cors='*')
158 def weighting_start(self):
159 if self.scale == 'closed':
160 print "Opening (Fake) Connection to Scale..."
162 self.scale_weight = 0.0
164 print "... Scale Open."
166 print "WARNING: Scale already Connected !!!"
168 @http.route('/hw_proxy/weighting_read_kg', type='json', auth='none', cors='*')
169 def weighting_read_kg(self):
170 if self.scale == 'open':
171 print "Reading Scale..."
173 self.scale_weight += 0.01
175 return self.scale_weight
177 print "WARNING: Reading closed scale !!!"
180 @http.route('/hw_proxy/weighting_end', type='json', auth='none', cors='*')
181 def weighting_end(self):
182 if self.scale == 'open':
183 print "Closing Connection to Scale ..."
184 self.scale = 'closed'
185 self.scale_weight = 0.0
187 print "... Scale Closed."
189 print "WARNING: Scale already Closed !!!"
191 @http.route('/hw_proxy/payment_request', type='json', auth='none', cors='*')
192 def payment_request(self, price):
194 The PoS will activate the method payment
196 print "payment_request: price:"+str(price)
199 @http.route('/hw_proxy/payment_status', type='json', auth='none', cors='*')
200 def payment_status(self):
201 print "payment_status"
202 return { 'status':'waiting' }
204 @http.route('/hw_proxy/payment_cancel', type='json', auth='none', cors='*')
205 def payment_cancel(self):
206 print "payment_cancel"
208 @http.route('/hw_proxy/transaction_start', type='json', auth='none', cors='*')
209 def transaction_start(self):
210 print 'transaction_start'
212 @http.route('/hw_proxy/transaction_end', type='json', auth='none', cors='*')
213 def transaction_end(self):
214 print 'transaction_end'
216 @http.route('/hw_proxy/cashier_mode_activated', type='json', auth='none', cors='*')
217 def cashier_mode_activated(self):
218 print 'cashier_mode_activated'
220 @http.route('/hw_proxy/cashier_mode_deactivated', type='json', auth='none', cors='*')
221 def cashier_mode_deactivated(self):
222 print 'cashier_mode_deactivated'
224 @http.route('/hw_proxy/open_cashbox', type='json', auth='none', cors='*')
225 def open_cashbox(self):
228 @http.route('/hw_proxy/print_receipt', type='json', auth='none', cors='*')
229 def print_receipt(self, receipt):
230 print 'print_receipt' + str(receipt)
232 @http.route('/hw_proxy/is_scanner_connected', type='json', auth='none', cors='*')
233 def print_receipt(self, receipt):
234 print 'is_scanner_connected?'
237 @http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
238 def print_receipt(self, receipt):
243 @http.route('/hw_proxy/log', type='json', auth='none', cors='*')
244 def log(self, arguments):
245 _logger.info(' '.join(str(v) for v in arguments))
247 @http.route('/hw_proxy/print_pdf_invoice', type='json', auth='none', cors='*')
248 def print_pdf_invoice(self, pdfinvoice):
249 print 'print_pdf_invoice' + str(pdfinvoice)