1 # -*- coding: utf-8 -*-
7 from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
9 class PointOfSaleController(openerp.addons.web.http.Controller):
12 @openerp.addons.web.http.httprequest
13 def app(self, req, s_action=None, **kw):
14 js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, None, 'js'))
15 css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, None, 'css'))
17 cookie = req.httprequest.cookies.get("instance0|session_id")
18 session_id = cookie.replace("%22","")
19 template = html_template.replace('<html','<html manifest="/pos/manifest?session_id=%s"'%session_id)
23 'modules': simplejson.dumps(module_boot(req)),
24 'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
28 @openerp.addons.web.http.httprequest
29 def manifest(self, req, **kwargs):
30 """ This generates a HTML5 cache manifest files that preloads the categories and products thumbnails
31 and other ressources necessary for the point of sale to work offline """
33 ml = ["CACHE MANIFEST"]
35 # loading all the images in the static/src/img/* directories
36 def load_css_img(srcdir,dstdir):
37 for f in os.listdir(srcdir):
38 path = os.path.join(srcdir,f)
39 dstpath = os.path.join(dstdir,f)
40 if os.path.isdir(path) :
41 load_css_img(path,dstpath)
42 elif f.endswith(('.png','.PNG','.jpg','.JPG','.jpeg','.JPEG','.gif','.GIF')):
45 imgdir = openerp.modules.get_module_resource('point_of_sale','static/src/img');
46 load_css_img(imgdir,'/point_of_sale/static/src/img')
48 products = req.session.model('product.product')
49 for p in products.search_read([('pos_categ_id','!=',False)], ['name']):
51 url = "/web/binary/image?session_id=%s&model=product.product&field=image&id=%s" % (req.session_id, product_id)
54 categories = req.session.model('pos.category')
55 for c in categories.search_read([],['name']):
57 url = "/web/binary/image?session_id=%s&model=pos.category&field=image&id=%s" % (req.session_id, category_id)
60 ml += ["NETWORK:","*"]
65 @openerp.addons.web.http.jsonrequest
66 def dispatch(self, request, iface, **kwargs):
67 method = 'iface_%s' % iface
68 return getattr(self, method)(request, **kwargs)
70 @openerp.addons.web.http.jsonrequest
71 def scan_item_success(self, request, ean):
73 A product has been scanned with success
75 print 'scan_item_success: ' + str(ean)
78 @openerp.addons.web.http.jsonrequest
79 def scan_item_error_unrecognized(self, request, ean):
81 A product has been scanned without success
83 print 'scan_item_error_unrecognized: ' + str(ean)
86 @openerp.addons.web.http.jsonrequest
87 def help_needed(self, request):
89 The user wants an help (ex: light is on)
94 @openerp.addons.web.http.jsonrequest
95 def help_canceled(self, request):
97 The user stops the help request
102 @openerp.addons.web.http.jsonrequest
103 def weighting_start(self, request):
104 print "weighting_start"
107 @openerp.addons.web.http.jsonrequest
108 def weighting_read_kg(self, request):
109 print "weighting_read_kg"
112 @openerp.addons.web.http.jsonrequest
113 def weighting_end(self, request):
114 print "weighting_end"
117 @openerp.addons.web.http.jsonrequest
118 def payment_request(self, request, price):
120 The PoS will activate the method payment
122 print "payment_request: price:"+str(price)
125 @openerp.addons.web.http.jsonrequest
126 def payment_status(self, request):
127 print "payment_status"
128 return { 'status':'waiting' }
130 @openerp.addons.web.http.jsonrequest
131 def payment_cancel(self, request):
132 print "payment_cancel"
135 @openerp.addons.web.http.jsonrequest
136 def transaction_start(self, request):
137 print 'transaction_start'
140 @openerp.addons.web.http.jsonrequest
141 def transaction_end(self, request):
142 print 'transaction_end'
145 @openerp.addons.web.http.jsonrequest
146 def cashier_mode_activated(self, request):
147 print 'cashier_mode_activated'
150 @openerp.addons.web.http.jsonrequest
151 def cashier_mode_deactivated(self, request):
152 print 'cashier_mode_deactivated'
155 @openerp.addons.web.http.jsonrequest
156 def open_cashbox(self, request):
160 @openerp.addons.web.http.jsonrequest
161 def print_receipt(self, request, receipt):
162 print 'print_receipt' + str(receipt)
165 @openerp.addons.web.http.jsonrequest
166 def print_pdf_invoice(self, request, pdfinvoice):
167 print 'print_pdf_invoice' + str(pdfinvoice)