[IMP] point_of_sale: log pushed orders to the backend + disable proxy rpcs when the proxy is disconnected

bzr revid: fva@openerp.com-20130912135044-93c6va8e8yttkir1
This commit is contained in:
Frédéric van der Essen 2013-09-12 15:50:44 +02:00
parent 2f86c5ab5a
commit 651f76e274
3 changed files with 26 additions and 15 deletions

View File

@ -10,6 +10,8 @@ from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.web.controllers.main import manifest_list, module_boot, html_template
_logger = logging.getLogger(__name__)
class PointOfSaleController(http.Controller):
def __init__(self):
self.scale = 'closed'
@ -71,7 +73,7 @@ class PointOfSaleController(http.Controller):
@http.route('/pos/test_connection', type='json', auth='admin')
def test_connection(self):
return
_logger.info('Received Connection Test from the Point of Sale');
@http.route('/pos/scan_item_success', type='json', auth='admin')
def scan_item_success(self, ean):
@ -79,7 +81,6 @@ class PointOfSaleController(http.Controller):
A product has been scanned with success
"""
print 'scan_item_success: ' + str(ean)
return
@http.route('/pos/scan_item_error_unrecognized')
def scan_item_error_unrecognized(self, ean):
@ -87,7 +88,6 @@ class PointOfSaleController(http.Controller):
A product has been scanned without success
"""
print 'scan_item_error_unrecognized: ' + str(ean)
return
@http.route('/pos/help_needed', type='json', auth='admin')
def help_needed(self):
@ -95,7 +95,6 @@ class PointOfSaleController(http.Controller):
The user wants an help (ex: light is on)
"""
print "help_needed"
return
@http.route('/pos/help_canceled', type='json', auth='admin')
def help_canceled(self):
@ -103,7 +102,6 @@ class PointOfSaleController(http.Controller):
The user stops the help request
"""
print "help_canceled"
return
@http.route('/pos/weighting_start', type='json', auth='admin')
def weighting_start(self):
@ -115,7 +113,6 @@ class PointOfSaleController(http.Controller):
print "... Scale Open."
else:
print "WARNING: Scale already Connected !!!"
return
@http.route('/pos/weighting_read_kg', type='json', auth='admin')
def weighting_read_kg(self):
@ -156,41 +153,37 @@ class PointOfSaleController(http.Controller):
@http.route('/pos/payment_cancel', type='json', auth='admin')
def payment_cancel(self):
print "payment_cancel"
return
@http.route('/pos/transaction_start', type='json', auth='admin')
def transaction_start(self):
print 'transaction_start'
return
@http.route('/pos/transaction_end', type='json', auth='admin')
def transaction_end(self):
print 'transaction_end'
return
@http.route('/pos/cashier_mode_activated', type='json', auth='admin')
def cashier_mode_activated(self):
print 'cashier_mode_activated'
return
@http.route('/pos/cashier_mode_deactivated', type='json', auth='admin')
def cashier_mode_deactivated(self):
print 'cashier_mode_deactivated'
return
@http.route('/pos/open_cashbox', type='json', auth='admin')
def open_cashbox(self):
print 'open_cashbox'
return
@http.route('/pos/print_receipt', type='json', auth='admin')
def print_receipt(self, receipt):
print 'print_receipt' + str(receipt)
return
@http.route('/pos/log', type='json', auth='admin')
def log(self, arguments):
_logger.info(' '.join(str(v) for v in arguments))
@http.route('/pos/print_pdf_invoice', type='json', auth='admin')
def print_pdf_invoice(self, pdfinvoice):
print 'print_pdf_invoice' + str(pdfinvoice)
return

View File

@ -82,6 +82,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
module.ProxyDevice = instance.web.Class.extend({
init: function(options){
var self = this;
options = options || {};
url = options.url || 'http://localhost:8069';
@ -101,8 +102,13 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
this.connection = new instance.web.Session(undefined,url);
this.connection.session_id = _.uniqueId('posproxy');
this.connected = true;
this.bypass_proxy = false;
this.notifications = {};
this.message('test_connection').fail(function(){
self.connected = false;
console.error('Could not connect to the OpenERP Device Proxy Server');
});
},
close: function(){
@ -113,7 +119,11 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
for(var i = 0; i < callbacks.length; i++){
callbacks[i](params);
}
return this.connection.rpc('/pos/' + name, params || {});
if(this.connected){
return this.connection.rpc('/pos/' + name, params || {});
}else{
return (new $.Deferred()).reject();
}
},
// this allows the client to be notified when a proxy call is made. The notification
@ -124,6 +134,8 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
}
this.notifications[name].push(callback);
},
//a product has been scanned and recognized with success
// ean is a parsed ean object
@ -316,6 +328,11 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
return this.message('print_receipt',{receipt: receipt});
},
// asks the proxy to log some information, as with the debug.log you can provide several arguments.
log: function(){
return this.message('log',{'arguments': _.toArray(arguments)});
},
// asks the proxy to print an invoice in pdf form ( used to print invoices generated by the server )
print_pdf_invoice: function(pdfinvoice){
return this.message('print_pdf_invoice',{pdfinvoice: pdfinvoice});

View File

@ -270,6 +270,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
// it returns a deferred that succeeds after having tried to send the order and all the other pending orders.
push_order: function(order) {
var self = this;
this.proxy.log('push_order',order.export_as_JSON());
var order_id = this.db.add_order(order.export_as_JSON());
var pushed = new $.Deferred();