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='none', cors='*')
40 @http.route('/hw_proxy/handshake', type='json', auth='none', cors='*')
44 @http.route('/hw_proxy/status', type='http', auth='none', cors='*')
45 def status_http(self):
46 resp = '<html>\n<body>\n<h1>Hardware Proxy Status</h1>\n'
47 statuses = self.get_status()
48 for driver in statuses:
50 status = statuses[driver]
52 if status['status'] == 'connecting':
54 elif status['status'] == 'connected':
59 resp += "<h2 style='color:"+color+";'>"+driver+' : '+status['status']+"</h2>\n"
61 for msg in status['messages']:
62 resp += '<li>'+msg+'</li>\n'
64 resp += "<script>\n\tsetTimeout(function(){window.location.reload();},30000);\n</script>\n</body>\n</html>\n\n"
66 return request.make_response(resp,{
67 'Cache-Control': 'no-cache',
68 'Content-Type': 'text/html; charset=utf-8',
69 'Access-Control-Allow-Origin': '*',
70 'Access-Control-Allow-Methods': 'GET',
73 @http.route('/hw_proxy/status_json', type='json', auth='none', cors='*')
74 def status_json(self):
75 return self.get_status()
77 @http.route('/hw_proxy/scan_item_success', type='json', auth='none', cors='*')
78 def scan_item_success(self, ean):
80 A product has been scanned with success
82 print 'scan_item_success: ' + str(ean)
84 @http.route('/hw_proxy/scan_item_error_unrecognized', type='json', auth='none', cors='*')
85 def scan_item_error_unrecognized(self, ean):
87 A product has been scanned without success
89 print 'scan_item_error_unrecognized: ' + str(ean)
91 @http.route('/hw_proxy/help_needed', type='json', auth='none', cors='*')
92 def help_needed(self):
94 The user wants an help (ex: light is on)
98 @http.route('/hw_proxy/help_canceled', type='json', auth='none', cors='*')
99 def help_canceled(self):
101 The user stops the help request
103 print "help_canceled"
105 @http.route('/hw_proxy/weighting_start', type='json', auth='none', cors='*')
106 def weighting_start(self):
107 if self.scale == 'closed':
108 print "Opening (Fake) Connection to Scale..."
110 self.scale_weight = 0.0
112 print "... Scale Open."
114 print "WARNING: Scale already Connected !!!"
116 @http.route('/hw_proxy/weighting_read_kg', type='json', auth='none', cors='*')
117 def weighting_read_kg(self):
118 if self.scale == 'open':
119 print "Reading Scale..."
121 self.scale_weight += 0.01
123 return self.scale_weight
125 print "WARNING: Reading closed scale !!!"
128 @http.route('/hw_proxy/weighting_end', type='json', auth='none', cors='*')
129 def weighting_end(self):
130 if self.scale == 'open':
131 print "Closing Connection to Scale ..."
132 self.scale = 'closed'
133 self.scale_weight = 0.0
135 print "... Scale Closed."
137 print "WARNING: Scale already Closed !!!"
139 @http.route('/hw_proxy/payment_request', type='json', auth='none', cors='*')
140 def payment_request(self, price):
142 The PoS will activate the method payment
144 print "payment_request: price:"+str(price)
147 @http.route('/hw_proxy/payment_status', type='json', auth='none', cors='*')
148 def payment_status(self):
149 print "payment_status"
150 return { 'status':'waiting' }
152 @http.route('/hw_proxy/payment_cancel', type='json', auth='none', cors='*')
153 def payment_cancel(self):
154 print "payment_cancel"
156 @http.route('/hw_proxy/transaction_start', type='json', auth='none', cors='*')
157 def transaction_start(self):
158 print 'transaction_start'
160 @http.route('/hw_proxy/transaction_end', type='json', auth='none', cors='*')
161 def transaction_end(self):
162 print 'transaction_end'
164 @http.route('/hw_proxy/cashier_mode_activated', type='json', auth='none', cors='*')
165 def cashier_mode_activated(self):
166 print 'cashier_mode_activated'
168 @http.route('/hw_proxy/cashier_mode_deactivated', type='json', auth='none', cors='*')
169 def cashier_mode_deactivated(self):
170 print 'cashier_mode_deactivated'
172 @http.route('/hw_proxy/open_cashbox', type='json', auth='none', cors='*')
173 def open_cashbox(self):
176 @http.route('/hw_proxy/print_receipt', type='json', auth='none', cors='*')
177 def print_receipt(self, receipt):
178 print 'print_receipt' + str(receipt)
180 @http.route('/hw_proxy/is_scanner_connected', type='json', auth='none', cors='*')
181 def print_receipt(self, receipt):
182 print 'is_scanner_connected?'
185 @http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
186 def print_receipt(self, receipt):
191 @http.route('/hw_proxy/log', type='json', auth='none', cors='*')
192 def log(self, arguments):
193 _logger.info(' '.join(str(v) for v in arguments))
195 @http.route('/hw_proxy/print_pdf_invoice', type='json', auth='none', cors='*')
196 def print_pdf_invoice(self, pdfinvoice):
197 print 'print_pdf_invoice' + str(pdfinvoice)