[module] ~copyright
[burette/pos_membership.git] / controllers / main.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # POS Membership module for OpenERP, Manage membership payments from POS.
5 # Copyright (C) 2013 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
6 #
7 # This file is a part of POS Membership
8 #
9 # POS Membership is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # POS Membership is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23 import os
24 import openerp
25
26 from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
27 from openerp.addons.point_of_sale.controllers.main import PointOfSaleController
28
29 class PointOfSaleController(PointOfSaleController):
30
31 @openerp.addons.web.http.httprequest
32 def app(self, req, s_action=None, **kw):
33 js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, None, 'js'))
34 css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, None, 'css'))
35
36 cookie = req.httprequest.cookies.get("instance0|session_id")
37 session_id = cookie.replace("%22","")
38 template = html_template.replace('<html','<html manifest="/pos/manifest?session_id=%s"'%session_id)
39 r = template % {
40 'js': js,
41 'css': css,
42 'modules': simplejson.dumps(module_boot(req)),
43 'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
44 }
45 print ("DEV: [pos_membership] [controllers] [main] [app] return=%s" % str(r))
46 return r
47
48 @openerp.addons.web.http.httprequest
49 def manifest(self, req, **kwargs):
50 """ This generates a HTML5 cache manifest files that preloads the categories and products thumbnails
51 and other ressources necessary for the point of sale to work offline """
52 ml = ["CACHE MANIFEST"]
53
54 # loading all the images in the static/src/img/* directories
55 def load_css_img(srcdir,dstdir):
56 for f in os.listdir(srcdir):
57 path = os.path.join(srcdir,f)
58 dstpath = os.path.join(dstdir,f)
59 if os.path.isdir(path) :
60 load_css_img(path,dstpath)
61 elif f.endswith(('.png','.PNG','.jpg','.JPG','.jpeg','.JPEG','.gif','.GIF')):
62 ml.append(dstpath)
63
64 imgdir = openerp.modules.get_module_resource('point_of_sale','static/src/img');
65 load_css_img(imgdir,'/point_of_sale/static/src/img')
66
67 products = req.session.model('product.product')
68 for p in products.search_read([('pos_categ_id','!=',False)], ['name']):
69 product_id = p['id']
70 url = "/web/binary/image?session_id=%s&model=product.product&field=image&id=%s" % (req.session_id, product_id)
71 ml.append(url)
72
73 categories = req.session.model('pos.category')
74 for c in categories.search_read([],['name']):
75 category_id = c['id']
76 url = "/web/binary/image?session_id=%s&model=pos.category&field=image&id=%s" % (req.session_id, category_id)
77 ml.append(url)
78
79 partners = req.session.model('res.partner')
80 for c in partners.search_read([],['name']):
81 partner_id = c['id']
82 url = "/web/binary/image?session_id=%s&model=res.partner&field=image&id=%s" % (req.session_id, partner_id)
83 ml.append(url)
84
85 ml += ["NETWORK:","*"]
86 m = "\n".join(ml)
87
88 print ("DEV: [pos_membership] [controllers] [main] [manifest] return=%s" % m)
89 return m
90
91 PointOfSaleController()
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: