Merged App and POSWidget

bzr revid: fva@openerp.com-20120425145555-hk48b24efi6f3nti
This commit is contained in:
Frédéric van der Essen 2012-04-25 16:55:55 +02:00
parent 2ae6854f17
commit 4a488a32bb
3 changed files with 89 additions and 123 deletions

View File

@ -1,10 +1,13 @@
function openerp_pos_devices(module, instance){ //module is instance.point_of_sale
module.BarcodeReader = instance.web.Class.extend({
init: function(attributes){
this.pos = attributes.pos;
this.connect();
},
//returns true if the code is a valid EAN codebar number by checking the control digit.
// returns true if the code is a valid EAN codebar number by checking the control digit.
checkEan: function(code){
var st1 = code.slice();
var st2 = st1.slice(0,st1.length-1).reverse();
@ -33,6 +36,7 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
var cd = (10 - (st5%10)) % 10;
return code[code.length-1] === cd;
},
// returns a product that has a packaging with an EAN matching to provided ean string.
// returns undefined if no such product is found.
getProductByEAN: function(ean) {
@ -66,7 +70,8 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
}
return scannedProductModel;
},
//starts catching keyboard events and tries to interpret codebar
// starts catching keyboard events and tries to interpret codebar
connect: function(){
var self = this;
var codeNumbers = [];
@ -135,9 +140,10 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa
}
});
},
// stops catching keyboard events
disconnect: function(){
$('body').undelegate('', 'keyup')
},
});
}

View File

@ -158,7 +158,7 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
if(operations.length === 0){
return $.when();
}
var op = operations[0].data;
var op = operations[0];
// we prevent the default error handler and assume errors
// are a normal use case, except we stop the current iteration
@ -168,8 +168,8 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
event.preventDefault();
})
.pipe(function(){
//console.debug('saved 1 record'); TODO Debug this
self.dao.remove_operation(op.id).pipe(function(){
console.debug('saved 1 record'); //TODO Debug this
self.dao.remove_operation(operations[0].id).pipe(function(){
return self._int_flush();
});
}, function(){
@ -242,36 +242,6 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
return _results;
}
});
/*
module.Shop = Backbone.Model.extend({
initialize: function(attributes) {
var self = this;
this.set({
orders: new module.OrderCollection(),
products: new module.ProductCollection(),
});
this.pos = attributes.pos;
this.set({
cashRegisters: new module.CashRegisterCollection(this.pos.get('bank_statements')),
});
return (this.get('orders')).bind('remove', _.bind( function(removedOrder) {
if ((this.get('orders')).isEmpty()) {
this.addAndSelectOrder(new module.Order({pos: self.pos}));
}
if ((this.get('selectedOrder')) === removedOrder) {
return this.set({
selectedOrder: (this.get('orders')).last()
});
}
}, this));
},
addAndSelectOrder: function(newOrder) {
(this.get('orders')).add(newOrder);
return this.set({
selectedOrder: newOrder
});
},
});*/
module.CashRegister = Backbone.Model.extend({
});
@ -511,7 +481,6 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
model: module.Order,
});
/*
The numpad handles both the choice of the property currently being modified
(quantity, price or discount) and the edition of the corresponding numeric value.
@ -578,78 +547,4 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
}
},
});
module.App = (function() {
function App($element, pos) {
this.initialize($element, pos);
}
App.prototype.initialize = function($element, pos) {
this.pos = pos;
this.shopView = new module.ShopWidget(null, {
'pos': pos,
});
this.shopView.$element = $element;
this.shopView.start();
this.categoryView = new module.CategoryWidget(null, {element_id: 'products-screen-categories', pos: pos} );
this.categoryView.on_change_category.add_last(_.bind(this.category, this));
this.category();
this.onscreenKeyboard = new module.OnscreenKeyboardWidget(null,{keyboard_model:'simple'});
this.onscreenKeyboard.appendTo($(".point-of-sale #content"));
/*
this.actionBar = new module.ActionbarWidget(null);
this.actionBar.appendTo($(".point-of-sale #content"));
this.actionBar.addNewButton('left',{'label':'test'});
*/
this.barcodeReader = new module.BarcodeReader({ 'pos': pos });
this.barcodeReader.connect();
};
App.prototype.category = function(id) {
var c, product_list, self = this;
id = !id ? 0 : id;
c = this.pos.categories[id];
this.categoryView.ancestors = c.ancestors;
this.categoryView.children = c.children;
this.categoryView.renderElement();
this.categoryView.start();
allProducts = this.pos.get('product_list');
allPackages = this.pos.get('product.packaging');
product_list = this.pos.get('product_list').filter( function(p) {
var _ref;
return _ref = p.pos_categ_id[0], _.indexOf(c.subtree, _ref) >= 0;
});
(this.pos.get('products')).reset(product_list);
$('.searchbox input').keyup(function() {
var m, s;
s = $(this).val().toLowerCase();
if (s) {
m = product_list.filter( function(p) {
return p.name.toLowerCase().indexOf(s) != -1;
});
$('.search-clear').fadeIn();
} else {
m = product_list;
$('.search-clear').fadeOut();
}
return (self.pos.get('products')).reset(m);
});
return $('.search-clear').click( function() {
(self.pos.get('products')).reset(product_list);
$('.searchbox input').val('').focus();
return $('.search-clear').fadeOut();
});
};
return App;
})();
}

View File

@ -136,9 +136,9 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
$('#' + new_step + '-screen').show();
},
});
/*
Shopping carts.
*/
// ---------- "Shopping Carts" ----------
module.OrderlineWidget = instance.web.OldWidget.extend({
tagName: 'tr',
template_fct: qweb_template('pos-orderline-template'),
@ -262,9 +262,8 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
},
});
/*
"Products" step.
*/
// ---------- "Products" step. ----------
module.CategoryWidget = instance.web.OldWidget.extend({
init: function(parent, options){
this._super(parent,options.element_id);
@ -347,9 +346,9 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
return this;
},
});
/*
"Payment" step.
*/
// ---------- "Payment" step. ----------
module.PaymentlineWidget = instance.web.OldWidget.extend({
tagName: 'tr',
template_fct: qweb_template('pos-paymentline-template'),
@ -927,7 +926,6 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
module.POSWidget = instance.web.OldWidget.extend({
init: function() {
this._super.apply(this, arguments);
this.pos = new module.PosModel(this.session);
},
@ -946,12 +944,31 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
self.try_close();
});
self.pos.app = new module.App(self.$element, self.pos);
//self.pos.app = new module.App(self.$element, self.pos);
this.shopView = new module.ShopWidget(null, { 'pos': this.pos } );
this.shopView.$element = self.$element;
this.shopView.start();
this.categoryView = new module.CategoryWidget(null, {
'element_id': 'products-screen-categories',
'pos': this.pos,
});
this.categoryView.on_change_category.add_last(_.bind(self.search_and_categories, self));
this.search_and_categories();
this.onscreenKeyboard = new module.OnscreenKeyboardWidget(null, {
'keyboard_model': 'simple'
});
this.onscreenKeyboard.appendTo($(".point-of-sale #content"));
this.barcodeReader = new module.BarcodeReader({'pos': self.pos });
instance.webclient.set_content_full_screen(true);
if (self.pos.get('bank_statements').length === 0)
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_open_statement']], ['res_id']).pipe(
_.bind(function(res) {
_.bind(function(res) {
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
var action = result.result;
this.do_action(action);
@ -959,6 +976,54 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
}, this));
}, this));
},
search_and_categories: function(id){
var self = this,
c,
product_list,
allProducts,
allPackages;
id = id || 0;
c = this.pos.categories[id];
this.categoryView.ancestors = c.ancestors;
this.categoryView.children = c.children;
this.categoryView.renderElement();
this.categoryView.start();
allProducts = this.pos.get('product_list');
allPackages = this.pos.get('product.packaging');
product_list = this.pos.get('product_list').filter( function(p){
var _ref = p.pos_categ_id[0];
return _.indexOf(c.subtree, _ref) >= 0;
});
this.pos.get('products').reset(product_list);
$('.searchbox input').keyup(function(){
var results, search_str;
search_str = $(this).val().toLowerCase();
if(search_str){
results = product_list.filter( function(p){
return p.name.toLowerCase().indexOf(search_str) != -1;
});
$('.search-clear').fadeIn();
}else{
results = product_list;
$('.search-clear').fadeOut();
}
self.pos.get('products').reset(results);
});
$('.search-clear').click(function(){
self.pos.get('products').reset(product_list);
$('.searchbox input').val('').focus();
$('.search-clear').fadeOut();
});
},
render: function() {
return qweb_template("POSWidget")();
},