1 # -*- coding: utf-8 -*-
12 import werkzeug.wrappers
13 _logger = logging.getLogger(__name__)
16 from openerp import http
17 from openerp.http import request
18 from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
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):
28 self.scale_weight = 0.0
32 for driver in drivers:
33 statuses[driver] = drivers[driver].get_status()
36 @http.route('/hw_proxy/hello', type='http', auth='admin')
38 return request.make_response('ping', {
39 'Cache-Control': 'no-cache',
40 'Content-Type': 'text/html; charset=utf-8',
41 'Access-Control-Allow-Origin': '*',
42 'Access-Control-Allow-Methods': 'GET',
45 @http.route('/hw_proxy/handshake', type='json', auth='admin')
49 @http.route('/hw_proxy/status', type='http', auth='admin')
50 def status_http(self):
51 resp = '<html>\n<body>\n<h1>Hardware Proxy Status</h1>\n'
52 statuses = self.get_status()
53 for driver in statuses:
55 status = statuses[driver]
57 if status['status'] == 'connecting':
59 elif status['status'] == 'connected':
64 resp += "<h2 style='color:"+color+";'>"+driver+' : '+status['status']+"</h2>\n"
66 for msg in status['messages']:
67 resp += '<li>'+msg+'</li>\n'
69 resp += "<script>\n\tsetTimeout(function(){window.location.reload();},30000);\n</script>\n</body>\n</html>\n\n"
71 return request.make_response(resp,{
72 'Cache-Control': 'no-cache',
73 'Content-Type': 'text/html; charset=utf-8',
74 'Access-Control-Allow-Origin': '*',
75 'Access-Control-Allow-Methods': 'GET',
78 @http.route('/hw_proxy/status_json', type='json', auth='admin')
79 def status_json(self):
80 return self.get_status()
82 @http.route('/hw_proxy/scan_item_success', type='json', auth='admin')
83 def scan_item_success(self, ean):
85 A product has been scanned with success
87 print 'scan_item_success: ' + str(ean)
89 @http.route('/hw_proxy/scan_item_error_unrecognized', type='json', auth='admin')
90 def scan_item_error_unrecognized(self, ean):
92 A product has been scanned without success
94 print 'scan_item_error_unrecognized: ' + str(ean)
96 @http.route('/hw_proxy/help_needed', type='json', auth='admin')
97 def help_needed(self):
99 The user wants an help (ex: light is on)
103 @http.route('/hw_proxy/help_canceled', type='json', auth='admin')
104 def help_canceled(self):
106 The user stops the help request
108 print "help_canceled"
110 @http.route('/hw_proxy/weighting_start', type='json', auth='admin')
111 def weighting_start(self):
112 if self.scale == 'closed':
113 print "Opening (Fake) Connection to Scale..."
115 self.scale_weight = 0.0
117 print "... Scale Open."
119 print "WARNING: Scale already Connected !!!"
121 @http.route('/hw_proxy/weighting_read_kg', type='json', auth='admin')
122 def weighting_read_kg(self):
123 if self.scale == 'open':
124 print "Reading Scale..."
126 self.scale_weight += 0.01
128 return self.scale_weight
130 print "WARNING: Reading closed scale !!!"
133 @http.route('/hw_proxy/weighting_end', type='json', auth='admin')
134 def weighting_end(self):
135 if self.scale == 'open':
136 print "Closing Connection to Scale ..."
137 self.scale = 'closed'
138 self.scale_weight = 0.0
140 print "... Scale Closed."
142 print "WARNING: Scale already Closed !!!"
144 @http.route('/hw_proxy/payment_request', type='json', auth='admin')
145 def payment_request(self, price):
147 The PoS will activate the method payment
149 print "payment_request: price:"+str(price)
152 @http.route('/hw_proxy/payment_status', type='json', auth='admin')
153 def payment_status(self):
154 print "payment_status"
155 return { 'status':'waiting' }
157 @http.route('/hw_proxy/payment_cancel', type='json', auth='admin')
158 def payment_cancel(self):
159 print "payment_cancel"
161 @http.route('/hw_proxy/transaction_start', type='json', auth='admin')
162 def transaction_start(self):
163 print 'transaction_start'
165 @http.route('/hw_proxy/transaction_end', type='json', auth='admin')
166 def transaction_end(self):
167 print 'transaction_end'
169 @http.route('/hw_proxy/cashier_mode_activated', type='json', auth='admin')
170 def cashier_mode_activated(self):
171 print 'cashier_mode_activated'
173 @http.route('/hw_proxy/cashier_mode_deactivated', type='json', auth='admin')
174 def cashier_mode_deactivated(self):
175 print 'cashier_mode_deactivated'
177 @http.route('/hw_proxy/open_cashbox', type='json', auth='admin')
178 def open_cashbox(self):
181 @http.route('/hw_proxy/print_receipt', type='json', auth='admin')
182 def print_receipt(self, receipt):
183 print 'print_receipt' + str(receipt)
185 @http.route('/hw_proxy/is_scanner_connected', type='json', auth='admin')
186 def print_receipt(self, receipt):
187 print 'is_scanner_connected?'
190 @http.route('/hw_proxy/scanner', type='json', auth='admin')
191 def print_receipt(self, receipt):
196 @http.route('/hw_proxy/log', type='json', auth='admin')
197 def log(self, arguments):
198 _logger.info(' '.join(str(v) for v in arguments))
200 @http.route('/hw_proxy/print_pdf_invoice', type='json', auth='admin')
201 def print_pdf_invoice(self, pdfinvoice):
202 print 'print_pdf_invoice' + str(pdfinvoice)