2012-04-13 04:17:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
2012-08-13 22:16:01 +00:00
|
|
|
import simplejson
|
2012-08-17 15:42:48 +00:00
|
|
|
import os
|
|
|
|
import openerp
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
2012-10-10 20:46:17 +00:00
|
|
|
from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
|
2012-04-13 04:17:59 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
class PointOfSaleController(http.Controller):
|
2012-04-13 04:17:59 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/app', type='http', auth='admin')
|
|
|
|
def app(self):
|
|
|
|
js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js',db=request.db))
|
|
|
|
css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css',db=request.db))
|
2012-08-13 22:16:01 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
cookie = request.httprequest.cookies.get("instance0|session_id")
|
2012-08-13 22:16:01 +00:00
|
|
|
session_id = cookie.replace("%22","")
|
2013-07-12 10:05:16 +00:00
|
|
|
template = html_template.replace('<html','<html manifest="/pos/manifest?session_id=%s"' % request.session_id)
|
2012-08-13 22:16:01 +00:00
|
|
|
|
|
|
|
r = template % {
|
|
|
|
'js': js,
|
|
|
|
'css': css,
|
2013-07-12 09:54:55 +00:00
|
|
|
'modules': simplejson.dumps(module_boot(request)),
|
2012-08-13 22:16:01 +00:00
|
|
|
'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/manifest',type='http', auth='admin')
|
|
|
|
def manifest(self):
|
2012-08-17 15:42:48 +00:00
|
|
|
""" This generates a HTML5 cache manifest files that preloads the categories and products thumbnails
|
|
|
|
and other ressources necessary for the point of sale to work offline """
|
2012-08-17 14:24:15 +00:00
|
|
|
|
2012-08-13 22:16:01 +00:00
|
|
|
ml = ["CACHE MANIFEST"]
|
2012-08-17 15:42:48 +00:00
|
|
|
|
|
|
|
# loading all the images in the static/src/img/* directories
|
|
|
|
def load_css_img(srcdir,dstdir):
|
|
|
|
for f in os.listdir(srcdir):
|
|
|
|
path = os.path.join(srcdir,f)
|
|
|
|
dstpath = os.path.join(dstdir,f)
|
|
|
|
if os.path.isdir(path) :
|
|
|
|
load_css_img(path,dstpath)
|
|
|
|
elif f.endswith(('.png','.PNG','.jpg','.JPG','.jpeg','.JPEG','.gif','.GIF')):
|
|
|
|
ml.append(dstpath)
|
|
|
|
|
|
|
|
imgdir = openerp.modules.get_module_resource('point_of_sale','static/src/img');
|
|
|
|
load_css_img(imgdir,'/point_of_sale/static/src/img')
|
2012-08-17 14:24:15 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
products = request.registry.get('product.product')
|
|
|
|
for p in products.search_read(request.cr, request.uid, [('pos_categ_id','!=',False)], ['name']):
|
2012-08-13 22:16:01 +00:00
|
|
|
product_id = p['id']
|
2013-07-12 09:54:55 +00:00
|
|
|
url = "/web/binary/image?session_id=%s&model=product.product&field=image&id=%s" % (request.session_id, product_id)
|
2012-08-17 14:24:15 +00:00
|
|
|
ml.append(url)
|
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
categories = request.registry.get('pos.category')
|
|
|
|
for c in categories.search_read(request.cr, request.uid, [], ['name']):
|
2012-08-17 14:24:15 +00:00
|
|
|
category_id = c['id']
|
2013-07-12 09:54:55 +00:00
|
|
|
url = "/web/binary/image?session_id=%s&model=pos.category&field=image&id=%s" % (request.session_id, category_id)
|
2012-08-13 22:16:01 +00:00
|
|
|
ml.append(url)
|
2012-08-17 14:24:15 +00:00
|
|
|
|
2012-08-13 22:30:32 +00:00
|
|
|
ml += ["NETWORK:","*"]
|
2012-08-13 22:16:01 +00:00
|
|
|
m = "\n".join(ml)
|
2012-08-17 14:24:15 +00:00
|
|
|
|
2012-08-13 22:16:01 +00:00
|
|
|
return m
|
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/scan_item_success', type='json', auth='admin')
|
|
|
|
def scan_item_success(self, ean):
|
2012-04-23 11:04:03 +00:00
|
|
|
"""
|
|
|
|
A product has been scanned with success
|
|
|
|
"""
|
2012-09-05 09:20:53 +00:00
|
|
|
print 'scan_item_success: ' + str(ean)
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/scan_item_error_unrecognized')
|
|
|
|
def scan_item_error_unrecognized(self, ean):
|
2012-04-23 11:04:03 +00:00
|
|
|
"""
|
|
|
|
A product has been scanned without success
|
|
|
|
"""
|
2012-09-05 09:20:53 +00:00
|
|
|
print 'scan_item_error_unrecognized: ' + str(ean)
|
2012-05-23 12:47:54 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/help_needed', type='json', auth='admin')
|
|
|
|
def help_needed(self):
|
2012-04-23 11:04:03 +00:00
|
|
|
"""
|
|
|
|
The user wants an help (ex: light is on)
|
|
|
|
"""
|
2012-05-23 12:47:54 +00:00
|
|
|
print "help_needed"
|
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/help_canceled', type='json', auth='admin')
|
|
|
|
def help_canceled(self):
|
2012-04-23 11:04:03 +00:00
|
|
|
"""
|
|
|
|
The user stops the help request
|
|
|
|
"""
|
2012-05-23 12:47:54 +00:00
|
|
|
print "help_canceled"
|
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/weighting_start', type='json', auth='admin')
|
|
|
|
def weighting_start(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print "weighting_start"
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/weighting_read_kg', type='json', auth='admin')
|
|
|
|
def weighting_read_kg(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print "weighting_read_kg"
|
2013-07-12 12:34:55 +00:00
|
|
|
return 3.14
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/weighting_end', type='json', auth='admin')
|
|
|
|
def weighting_end(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print "weighting_end"
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/payment_request', type='json', auth='admin')
|
|
|
|
def payment_request(self, price):
|
2012-05-23 12:47:54 +00:00
|
|
|
"""
|
|
|
|
The PoS will activate the method payment
|
|
|
|
"""
|
2012-09-18 13:37:32 +00:00
|
|
|
print "payment_request: price:"+str(price)
|
|
|
|
return 'ok'
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/payment_status', type='json', auth='admin')
|
|
|
|
def payment_status(self):
|
2012-09-18 13:37:32 +00:00
|
|
|
print "payment_status"
|
|
|
|
return { 'status':'waiting' }
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/payment_cancel', type='json', auth='admin')
|
|
|
|
def payment_cancel(self):
|
2012-09-18 13:37:32 +00:00
|
|
|
print "payment_cancel"
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/transaction_start', type='json', auth='admin')
|
|
|
|
def transaction_start(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print 'transaction_start'
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/transaction_end', type='json', auth='admin')
|
|
|
|
def transaction_end(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print 'transaction_end'
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/cashier_mode_activated', type='json', auth='admin')
|
|
|
|
def cashier_mode_activated(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print 'cashier_mode_activated'
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/cashier_mode_deactivated', type='json', auth='admin')
|
|
|
|
def cashier_mode_deactivated(self):
|
2012-05-23 12:47:54 +00:00
|
|
|
print 'cashier_mode_deactivated'
|
2012-05-23 13:00:11 +00:00
|
|
|
return
|
2012-04-23 11:04:03 +00:00
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/open_cashbox', type='json', auth='admin')
|
|
|
|
def open_cashbox(self):
|
2012-05-23 14:01:53 +00:00
|
|
|
print 'open_cashbox'
|
|
|
|
return
|
|
|
|
|
2013-07-12 09:54:55 +00:00
|
|
|
@http.route('/pos/print_receipt', type='json', auth='admin')
|
|
|
|
def print_receipt(self, receipt):
|
2012-05-23 14:01:53 +00:00
|
|
|
print 'print_receipt' + str(receipt)
|
|
|
|
return
|
|
|
|
|
2013-07-12 12:34:55 +00:00
|
|
|
@http.route('/pos/print_pdf_invoice', type='json', auth='admin')
|
2013-07-12 09:54:55 +00:00
|
|
|
def print_pdf_invoice(self, pdfinvoice):
|
2012-09-05 16:42:21 +00:00
|
|
|
print 'print_pdf_invoice' + str(pdfinvoice)
|
|
|
|
return
|
|
|
|
|
2012-08-13 22:16:01 +00:00
|
|
|
|