2012-04-25 11:38:02 +00:00
|
|
|
function openerp_pos_widgets(module, instance){ //module is instance.point_of_sale
|
2012-04-24 16:25:46 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
|
2012-04-24 17:20:47 +00:00
|
|
|
var qweb_template = function(template,pos){
|
2012-04-24 16:25:46 +00:00
|
|
|
return function(ctx){
|
2012-04-24 17:20:47 +00:00
|
|
|
if(!pos){ //this is a huge hack that needs to be removed ... TODO
|
2012-04-24 16:25:46 +00:00
|
|
|
var HackPosModel = Backbone.Model.extend({
|
|
|
|
initialize:function(){
|
|
|
|
this.set({
|
|
|
|
'currency': {symbol: '$', position: 'after'},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2012-04-24 17:20:47 +00:00
|
|
|
pos = new HackPosModel();
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
return QWeb.render(template, _.extend({}, ctx,{
|
2012-04-24 17:20:47 +00:00
|
|
|
'currency': pos.get('currency'),
|
2012-04-24 16:25:46 +00:00
|
|
|
'format_amount': function(amount) {
|
2012-04-24 17:20:47 +00:00
|
|
|
if (pos.get('currency').position == 'after') {
|
2012-05-06 21:34:39 +00:00
|
|
|
return Math.round(amount*100)/100 + ' ' + pos.get('currency').symbol;
|
2012-04-24 16:25:46 +00:00
|
|
|
} else {
|
2012-04-24 17:20:47 +00:00
|
|
|
return pos.get('currency').symbol + ' ' + amount;
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.NumpadWidget = instance.web.OldWidget.extend({
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.state = new module.NumpadState();
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.state.bind('change:mode', this.changedMode, this);
|
|
|
|
this.changedMode();
|
|
|
|
this.$element.find('button#numpad-backspace').click(_.bind(this.clickDeleteLastChar, this));
|
|
|
|
this.$element.find('button#numpad-minus').click(_.bind(this.clickSwitchSign, this));
|
|
|
|
this.$element.find('button.number-char').click(_.bind(this.clickAppendNewChar, this));
|
|
|
|
this.$element.find('button.mode-button').click(_.bind(this.clickChangeMode, this));
|
|
|
|
},
|
|
|
|
clickDeleteLastChar: function() {
|
|
|
|
return this.state.deleteLastChar();
|
|
|
|
},
|
|
|
|
clickSwitchSign: function() {
|
|
|
|
return this.state.switchSign();
|
|
|
|
},
|
|
|
|
clickAppendNewChar: function(event) {
|
|
|
|
var newChar;
|
|
|
|
newChar = event.currentTarget.innerText || event.currentTarget.textContent;
|
|
|
|
return this.state.appendNewChar(newChar);
|
|
|
|
},
|
|
|
|
clickChangeMode: function(event) {
|
|
|
|
var newMode = event.currentTarget.attributes['data-mode'].nodeValue;
|
|
|
|
return this.state.changeMode(newMode);
|
|
|
|
},
|
|
|
|
changedMode: function() {
|
|
|
|
var mode = this.state.get('mode');
|
|
|
|
$('.selected-mode').removeClass('selected-mode');
|
|
|
|
$(_.str.sprintf('.mode-button[data-mode="%s"]', mode), this.$element).addClass('selected-mode');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
Gives access to the payment methods (aka. 'cash registers')
|
|
|
|
*/
|
|
|
|
module.PaypadWidget = instance.web.OldWidget.extend({
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos = options.pos;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.$element.find('button').click(_.bind(this.performPayment, this));
|
|
|
|
},
|
|
|
|
performPayment: function(event) {
|
2012-05-02 15:30:00 +00:00
|
|
|
if (this.pos.get('selectedOrder').get('screen') === 'receipt')
|
2012-04-24 16:25:46 +00:00
|
|
|
return;
|
|
|
|
var cashRegister, cashRegisterCollection, cashRegisterId;
|
|
|
|
/* set correct view */
|
2012-05-02 15:30:00 +00:00
|
|
|
this.pos.screen_selector.set_current_screen('payment');
|
2012-04-24 16:25:46 +00:00
|
|
|
|
|
|
|
cashRegisterId = event.currentTarget.attributes['cash-register-id'].nodeValue;
|
2012-04-24 17:20:47 +00:00
|
|
|
cashRegisterCollection = this.pos.get('cashRegisters');
|
2012-04-24 16:25:46 +00:00
|
|
|
cashRegister = cashRegisterCollection.find(_.bind( function(item) {
|
|
|
|
return (item.get('id')) === parseInt(cashRegisterId, 10);
|
|
|
|
}, this));
|
2012-04-24 17:20:47 +00:00
|
|
|
return (this.pos.get('selectedOrder')).addPaymentLine(cashRegister);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this.$element.empty();
|
2012-04-24 17:20:47 +00:00
|
|
|
return (this.pos.get('cashRegisters')).each(_.bind( function(cashRegister) {
|
2012-04-24 16:25:46 +00:00
|
|
|
var button = new module.PaymentButtonWidget();
|
|
|
|
button.model = cashRegister;
|
|
|
|
button.appendTo(this.$element);
|
|
|
|
}, this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.PaymentButtonWidget = instance.web.OldWidget.extend({
|
|
|
|
template_fct: qweb_template('pos-payment-button-template'),
|
|
|
|
renderElement: function() {
|
|
|
|
this.$element.html(this.template_fct({
|
|
|
|
id: this.model.get('id'),
|
|
|
|
name: (this.model.get('journal_id'))[1]
|
|
|
|
}));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2012-04-25 14:55:55 +00:00
|
|
|
|
|
|
|
// ---------- "Shopping Carts" ----------
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
module.OrderlineWidget = instance.web.OldWidget.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
template_fct: qweb_template('pos-orderline-template'),
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.model = options.model;
|
|
|
|
this.model.bind('change', _.bind( function() {
|
|
|
|
this.refresh();
|
|
|
|
}, this));
|
|
|
|
this.model.bind('remove', _.bind( function() {
|
|
|
|
this.$element.remove();
|
|
|
|
}, this));
|
|
|
|
this.order = options.order;
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.$element.click(_.bind(this.clickHandler, this));
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
clickHandler: function() {
|
|
|
|
this.select();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this.$element.html(this.template_fct(this.model.toJSON()));
|
|
|
|
this.select();
|
|
|
|
},
|
|
|
|
refresh: function() {
|
|
|
|
this.renderElement();
|
|
|
|
var heights = _.map(this.$element.prevAll(), function(el) {return $(el).outerHeight();});
|
|
|
|
heights.push($('#current-order thead').outerHeight());
|
|
|
|
var position = _.reduce(heights, function(memo, num){ return memo + num; }, 0);
|
|
|
|
$('#current-order').scrollTop(position);
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
$('tr.selected').removeClass('selected');
|
|
|
|
this.$element.addClass('selected');
|
|
|
|
this.order.selected = this.model;
|
|
|
|
this.on_selected();
|
|
|
|
},
|
|
|
|
on_selected: function() {},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.OrderWidget = instance.web.OldWidget.extend({
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-07 12:39:32 +00:00
|
|
|
this.pos_widget = options.pos_widget;
|
2012-04-24 16:25:46 +00:00
|
|
|
this.setNumpadState(options.numpadState);
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos.bind('change:selectedOrder', this.changeSelectedOrder, this);
|
2012-04-24 16:25:46 +00:00
|
|
|
this.bindOrderLineEvents();
|
|
|
|
},
|
|
|
|
setNumpadState: function(numpadState) {
|
|
|
|
if (this.numpadState) {
|
|
|
|
this.numpadState.unbind('setValue', this.setValue);
|
|
|
|
}
|
|
|
|
this.numpadState = numpadState;
|
|
|
|
if (this.numpadState) {
|
|
|
|
this.numpadState.bind('setValue', this.setValue, this);
|
|
|
|
this.numpadState.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setValue: function(val) {
|
|
|
|
var param = {};
|
|
|
|
param[this.numpadState.get('mode')] = val;
|
2012-04-24 17:20:47 +00:00
|
|
|
var order = this.pos.get('selectedOrder');
|
2012-04-24 16:25:46 +00:00
|
|
|
if (order.get('orderLines').length !== 0) {
|
|
|
|
order.selected.set(param);
|
|
|
|
} else {
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos.get('selectedOrder').destroy();
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
changeSelectedOrder: function() {
|
|
|
|
this.currentOrderLines.unbind();
|
|
|
|
this.bindOrderLineEvents();
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
bindOrderLineEvents: function() {
|
2012-04-24 17:20:47 +00:00
|
|
|
this.currentOrderLines = (this.pos.get('selectedOrder')).get('orderLines');
|
2012-04-24 16:25:46 +00:00
|
|
|
this.currentOrderLines.bind('add', this.addLine, this);
|
|
|
|
this.currentOrderLines.bind('remove', this.renderElement, this);
|
|
|
|
},
|
|
|
|
addLine: function(newLine) {
|
|
|
|
var line = new module.OrderlineWidget(null, {
|
|
|
|
model: newLine,
|
2012-04-24 17:20:47 +00:00
|
|
|
order: this.pos.get('selectedOrder')
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
line.on_selected.add(_.bind(this.selectedLine, this));
|
|
|
|
this.selectedLine();
|
|
|
|
line.appendTo(this.$element);
|
|
|
|
this.updateSummary();
|
|
|
|
},
|
|
|
|
selectedLine: function() {
|
|
|
|
var reset = false;
|
2012-04-24 17:20:47 +00:00
|
|
|
if (this.currentSelected !== this.pos.get('selectedOrder').selected) {
|
2012-04-24 16:25:46 +00:00
|
|
|
reset = true;
|
|
|
|
}
|
2012-04-24 17:20:47 +00:00
|
|
|
this.currentSelected = this.pos.get('selectedOrder').selected;
|
2012-04-24 16:25:46 +00:00
|
|
|
if (reset && this.numpadState)
|
|
|
|
this.numpadState.reset();
|
|
|
|
this.updateSummary();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this.$element.empty();
|
|
|
|
this.currentOrderLines.each(_.bind( function(orderLine) {
|
|
|
|
var line = new module.OrderlineWidget(null, {
|
|
|
|
model: orderLine,
|
2012-04-24 17:20:47 +00:00
|
|
|
order: this.pos.get('selectedOrder')
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
line.on_selected.add(_.bind(this.selectedLine, this));
|
|
|
|
line.appendTo(this.$element);
|
|
|
|
}, this));
|
|
|
|
this.updateSummary();
|
|
|
|
},
|
|
|
|
updateSummary: function() {
|
|
|
|
var currentOrder, tax, total, totalTaxExcluded;
|
2012-04-24 17:20:47 +00:00
|
|
|
currentOrder = this.pos.get('selectedOrder');
|
2012-04-24 16:25:46 +00:00
|
|
|
total = currentOrder.getTotal();
|
|
|
|
totalTaxExcluded = currentOrder.getTotalTaxExcluded();
|
|
|
|
tax = currentOrder.getTax();
|
2012-05-07 12:39:32 +00:00
|
|
|
this.pos_widget.action_bar.set_total_value(Math.round(total*100)/100);
|
2012-04-24 16:25:46 +00:00
|
|
|
$('#subtotal').html(totalTaxExcluded.toFixed(2)).hide().fadeIn();
|
|
|
|
$('#tax').html(tax.toFixed(2)).hide().fadeIn();
|
|
|
|
$('#total').html(total.toFixed(2)).hide().fadeIn();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
// ---------- Product Screen ----------
|
2012-04-25 14:55:55 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
module.ProductWidget = instance.web.Widget.extend({
|
2012-04-24 16:25:46 +00:00
|
|
|
tagName:'li',
|
2012-05-06 21:34:39 +00:00
|
|
|
template_fct: qweb_template('ProductWidget'),
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.model = options.model;
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-06 21:34:39 +00:00
|
|
|
this.model.attributes.weight = options.weight || undefined;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
addToOrder: function(event) {
|
|
|
|
/* Preserve the category URL */
|
|
|
|
event.preventDefault();
|
2012-04-24 17:20:47 +00:00
|
|
|
return (this.pos.get('selectedOrder')).addProduct(this.model);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-06 21:34:39 +00:00
|
|
|
setWeight: function(weight){
|
|
|
|
this.model.attributes.weight = weight;
|
|
|
|
this.renderElement();
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
|
|
|
this.$element.addClass("product");
|
|
|
|
this.$element.html(this.template_fct(this.model.toJSON()));
|
2012-05-06 21:34:39 +00:00
|
|
|
$("a", this.$element).click(_.bind(this.addToOrder, this));
|
2012-04-24 16:25:46 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-04-25 14:55:55 +00:00
|
|
|
// ---------- "Payment" step. ----------
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
module.PaymentlineWidget = instance.web.OldWidget.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
template_fct: qweb_template('pos-paymentline-template'),
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.model = options.model;
|
|
|
|
this.model.bind('change', this.changedAmount, this);
|
|
|
|
},
|
|
|
|
on_delete: function() {},
|
|
|
|
changeAmount: function(event) {
|
|
|
|
var newAmount;
|
|
|
|
newAmount = event.currentTarget.value;
|
|
|
|
if (newAmount && !isNaN(newAmount)) {
|
|
|
|
this.amount = parseFloat(newAmount);
|
|
|
|
this.model.set({
|
|
|
|
amount: this.amount,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
changedAmount: function() {
|
|
|
|
if (this.amount !== this.model.get('amount'))
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this.amount = this.model.get('amount');
|
|
|
|
this.$element.html(this.template_fct({
|
|
|
|
name: (this.model.get('journal_id'))[1],
|
|
|
|
amount: this.amount,
|
|
|
|
}));
|
|
|
|
this.$element.addClass('paymentline');
|
|
|
|
$('input', this.$element).keyup(_.bind(this.changeAmount, this));
|
|
|
|
$('.delete-payment-line', this.$element).click(this.on_delete);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
module.OrderButtonWidget = instance.web.OldWidget.extend({
|
|
|
|
tagName: 'li',
|
|
|
|
template_fct: qweb_template('pos-order-selector-button-template'),
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.order = options.order;
|
|
|
|
this.pos = options.pos;
|
|
|
|
this.order.bind('destroy', _.bind( function() {
|
|
|
|
this.destroy();
|
|
|
|
}, this));
|
|
|
|
this.pos.bind('change:selectedOrder', _.bind( function(pos) {
|
|
|
|
var selectedOrder;
|
|
|
|
selectedOrder = pos.get('selectedOrder');
|
|
|
|
if (this.order === selectedOrder) {
|
|
|
|
this.setButtonSelected();
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
$('button.select-order', this.$element).click(_.bind(this.selectOrder, this));
|
|
|
|
$('button.close-order', this.$element).click(_.bind(this.closeOrder, this));
|
|
|
|
},
|
|
|
|
selectOrder: function(event) {
|
|
|
|
this.pos.set({
|
|
|
|
selectedOrder: this.order
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setButtonSelected: function() {
|
|
|
|
$('.selected-order').removeClass('selected-order');
|
|
|
|
this.$element.addClass('selected-order');
|
|
|
|
},
|
|
|
|
closeOrder: function(event) {
|
|
|
|
this.order.destroy();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this.$element.html(this.template_fct({widget:this}));
|
|
|
|
this.$element.addClass('order-selector-button');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ActionButtonWidget = instance.web.Widget.extend({
|
|
|
|
template:'pos-action-button',
|
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent, options);
|
|
|
|
this.label = options.label || 'button';
|
|
|
|
this.rightalign = options.rightalign || false;
|
|
|
|
this.click_action = options.click;
|
|
|
|
if(options.icon){
|
|
|
|
this.icon = options.icon;
|
|
|
|
this.template = 'pos-action-button-with-icon';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
if(this.click_action){
|
|
|
|
this.$element.click(_.bind(this.click_action, this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-04 12:24:48 +00:00
|
|
|
module.ActionBarWidget = instance.web.Widget.extend({
|
|
|
|
template:'ActionBarWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent,options);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-05-06 21:34:39 +00:00
|
|
|
this.total_visibility = true;
|
|
|
|
this.help_visibility = true;
|
|
|
|
this.logout_visibility = true;
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
destroy_buttons:function(){
|
|
|
|
for(var i = 0; i < this.button_list.length; i++){
|
|
|
|
this.button_list[i].destroy();
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-05-02 15:30:00 +00:00
|
|
|
return this;
|
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
add_new_button: function(button_options){
|
|
|
|
if(arguments.length == 1){
|
2012-05-02 15:30:00 +00:00
|
|
|
var button = new module.ActionButtonWidget(this,button_options);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list.push(button);
|
2012-05-04 12:24:48 +00:00
|
|
|
button.appendTo($('.pos-actionbar-button-list'));
|
2012-05-02 15:30:00 +00:00
|
|
|
}else{
|
2012-05-03 16:27:46 +00:00
|
|
|
for(var i = 0; i < arguments.length; i++){
|
|
|
|
this.add_new_button(arguments[i]);
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
|
|
|
set_total_visible: function(visible){
|
|
|
|
if(visible !== this.total_visibility){
|
|
|
|
this.total_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.total').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.total').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_help_visible: function(visible,action){
|
|
|
|
if(visible !== this.help_visibility){
|
|
|
|
this.help_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.help-button').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.help-button').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(visible && action){
|
|
|
|
this.$element.find('.help-button').off('click').click(action);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_logout_visible: function(visible,action){
|
|
|
|
if(visible !== this.logout_visibility){
|
|
|
|
this.logout_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.logout-button').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.logout-button').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(visible && action){
|
|
|
|
this.$element.find('.logout-button').off('click').click(action);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_total_value: function(value){
|
2012-05-07 12:39:32 +00:00
|
|
|
this.$element.find('.value').html(value);
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.ProductCategoriesWidget = instance.web.Widget.extend({
|
|
|
|
init: function(parent, options){
|
2012-04-24 16:25:46 +00:00
|
|
|
this._super(parent);
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-02 15:30:00 +00:00
|
|
|
this.on_change_category.add_last(_.bind(this.search_and_categories, this));
|
|
|
|
this.search_and_categories();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2012-05-02 15:30:00 +00:00
|
|
|
this.search_and_categories();
|
|
|
|
this.$element.find(".oe-pos-categories-list a").click(_.bind(this.changeCategory, this));
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
template_fct: qweb_template('ProductCategoriesWidget'),
|
|
|
|
template:'ProductCategoriesWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-02 15:30:00 +00:00
|
|
|
var self = this;
|
|
|
|
var c;
|
|
|
|
this.$element.empty();
|
|
|
|
this.$element.html(QWeb.render(this.template, {
|
|
|
|
breadcrumb: (function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = self.ancestors.length; _i < _len; _i++) {
|
|
|
|
c = self.ancestors[_i];
|
|
|
|
_results.push(self.pos.categories[c]);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})(),
|
|
|
|
categories: (function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = self.children.length; _i < _len; _i++) {
|
|
|
|
c = self.children[_i];
|
|
|
|
_results.push(self.pos.categories[c]);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})()
|
|
|
|
}));
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
changeCategory: function(a) {
|
|
|
|
var id = $(a.target).data("category-id");
|
|
|
|
this.on_change_category(id);
|
2012-04-26 11:26:55 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
search_and_categories: function(id){
|
|
|
|
var self = this,
|
|
|
|
c,
|
|
|
|
product_list,
|
|
|
|
allProducts,
|
|
|
|
allPackages;
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
id = id || 0;
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
c = this.pos.categories[id];
|
|
|
|
this.ancestors = c.ancestors;
|
|
|
|
this.children = c.children;
|
|
|
|
this.renderElement();
|
2012-04-26 14:47:01 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
allProducts = this.pos.get('product_list');
|
2012-04-26 14:47:01 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
this.$element.find('.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;
|
|
|
|
});
|
|
|
|
self.$element.find('.search-clear').fadeIn();
|
|
|
|
}else{
|
|
|
|
results = product_list;
|
|
|
|
self.$element.find('.search-clear').fadeOut();
|
|
|
|
}
|
|
|
|
self.pos.get('products').reset(results);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$element.find('.search-clear').click(function(){
|
|
|
|
self.pos.get('products').reset(product_list);
|
|
|
|
self.$element.find('.searchbox input').val('').focus();
|
|
|
|
self.$element.find('.search-clear').fadeOut();
|
|
|
|
});
|
2012-04-26 14:47:01 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
on_change_category: function(id) {},
|
2012-04-26 14:47:01 +00:00
|
|
|
});
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
module.ProductListWidget = module.ScreenWidget.extend({
|
|
|
|
template:'ProductListWidget',
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.model = options.model;
|
2012-04-26 14:47:01 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-02 15:30:00 +00:00
|
|
|
this.pos.get('products').bind('reset', this.renderElement, this);
|
2012-05-06 21:34:39 +00:00
|
|
|
this.product_list = [];
|
|
|
|
this.weight = options.weight;
|
|
|
|
},
|
|
|
|
setWeight: function(weight){
|
|
|
|
for(var i = 0; i < this.product_list.length; i++){
|
|
|
|
this.product_list[i].setWeight(weight);
|
|
|
|
}
|
2012-04-26 14:47:01 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
renderElement: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
2012-05-06 21:34:39 +00:00
|
|
|
this.product_list = [];
|
2012-05-02 15:30:00 +00:00
|
|
|
this.pos.get('products').chain().map(function(product) {
|
2012-05-06 21:34:39 +00:00
|
|
|
var product = new module.ProductWidget(this, {
|
2012-05-02 15:30:00 +00:00
|
|
|
model: product,
|
2012-05-06 21:34:39 +00:00
|
|
|
pos: self.pos,
|
|
|
|
weight: self.weight,
|
2012-05-02 15:30:00 +00:00
|
|
|
})
|
2012-05-06 21:34:39 +00:00
|
|
|
self.product_list.push(product);
|
|
|
|
return product;
|
2012-05-02 15:30:00 +00:00
|
|
|
}).invoke('appendTo', this.$element);
|
2012-04-26 14:47:01 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- PopUp Widgets ----------
|
|
|
|
|
|
|
|
module.PopUp = instance.web.Widget.extend({
|
|
|
|
close: function(){},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.HelpPopUp = module.PopUp.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ErrorPopUp = module.PopUp.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
module.TicketOrInvoicePopUp = module.PopUp.extend({
|
|
|
|
});
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
// ---------- OnScreen Keyboard Widget ----------
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
// A Widget that displays an onscreen keyboard.
|
|
|
|
// There are two options when creating the widget :
|
|
|
|
//
|
|
|
|
// * 'keyboard_model' : 'simple' | 'full' (default)
|
|
|
|
// The 'full' emulates a PC keyboard, while 'simple' emulates an 'android' one.
|
|
|
|
//
|
|
|
|
// * 'input_selector : (default: '.searchbox input')
|
|
|
|
// defines the dom element that the keyboard will write to.
|
|
|
|
//
|
|
|
|
// The widget is initially hidden. It can be shown with this.show(), and is
|
|
|
|
// automatically shown when the input_selector gets focused.
|
2012-04-26 10:05:48 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
module.OnscreenKeyboardWidget = instance.web.Widget.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
|
|
|
|
init: function(parent, options){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._super(parent,options);
|
|
|
|
|
|
|
|
function get_option(opt,default_value){
|
|
|
|
if(options){
|
|
|
|
return options[opt] || default_value;
|
|
|
|
}else{
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.keyboard_model = get_option('keyboard_model','full');
|
|
|
|
this.template_simple = qweb_template('pos-onscreen-keyboard-simple-template');
|
|
|
|
this.template_full = qweb_template('pos-onscreen-keyboard-full-template');
|
|
|
|
|
|
|
|
this.template_fct = function(){
|
|
|
|
if( this.keyboard_model == 'full' ){
|
|
|
|
return this.template_full.apply(this,arguments);
|
|
|
|
}else{
|
|
|
|
return this.template_simple.apply(this,arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.input_selector = get_option('input_selector','.searchbox input');
|
|
|
|
|
|
|
|
//show the keyboard when the input zone is clicked.
|
|
|
|
$(this.input_selector).focus(function(){self.show();});
|
|
|
|
|
|
|
|
//Keyboard state
|
|
|
|
this.capslock = false;
|
|
|
|
this.shift = false;
|
|
|
|
this.numlock = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Write a character to the input zone
|
|
|
|
writeCharacter: function(character){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
$input[0].value += character;
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sends a 'return' character to the input zone. TODO
|
|
|
|
sendReturn: function(){
|
|
|
|
},
|
|
|
|
|
|
|
|
// Removes the last character from the input zone.
|
|
|
|
deleteCharacter: function(){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
var input_value = $input[0].value;
|
|
|
|
$input[0].value = input_value.substr(0, input_value.length - 1);
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Clears the content of the input zone.
|
|
|
|
deleteAllCharacters: function(){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
$input[0].value = "";
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
|
|
|
renderElement: function(){
|
|
|
|
this.$element.html(this.template_fct());
|
|
|
|
},
|
|
|
|
|
|
|
|
// Makes the keyboard show and slide from the bottom of the screen.
|
|
|
|
show: function(){
|
|
|
|
$('.keyboard_frame').show().animate({'height':'235px'}, 500, 'swing');
|
|
|
|
},
|
|
|
|
|
|
|
|
// Makes the keyboard hide by sliding to the bottom of the screen.
|
|
|
|
hide: function(){
|
|
|
|
var self = this;
|
|
|
|
var frame = $('.keyboard_frame');
|
|
|
|
frame.animate({'height':'0'}, 500, 'swing', function(){ frame.hide(); self.reset(); });
|
|
|
|
},
|
|
|
|
|
|
|
|
//What happens when the shift key is pressed : toggle case, remove capslock
|
|
|
|
toggleShift: function(){
|
|
|
|
$('.letter').toggleClass('uppercase');
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
|
|
|
|
self.shift = (self.shift === true) ? false : true;
|
|
|
|
self.capslock = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
//what happens when capslock is pressed : toggle case, set capslock
|
|
|
|
toggleCapsLock: function(){
|
|
|
|
$('.letter').toggleClass('uppercase');
|
|
|
|
self.capslock = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
//What happens when numlock is pressed : toggle symbols and numlock label
|
|
|
|
toggleNumLock: function(){
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
$('.numlock span').toggle();
|
|
|
|
self.numlock = (self.numlock === true ) ? false : true;
|
|
|
|
},
|
|
|
|
|
|
|
|
//After a key is pressed, shift is disabled.
|
|
|
|
removeShift: function(){
|
|
|
|
if (self.shift === true) {
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
if (this.capslock === false) $('.letter').toggleClass('uppercase');
|
|
|
|
|
|
|
|
self.shift = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Resets the keyboard to its original state; capslock: false, shift: false, numlock: false
|
|
|
|
reset: function(){
|
|
|
|
if(this.shift){
|
|
|
|
this.toggleShift();
|
|
|
|
}
|
|
|
|
if(this.capslock){
|
|
|
|
this.toggleCapsLock();
|
|
|
|
}
|
|
|
|
if(this.numlock){
|
|
|
|
this.toggleNumLock();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//called after the keyboard is in the DOM, sets up the key bindings.
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
//this.show();
|
|
|
|
|
|
|
|
|
|
|
|
$('.close_button').click(function(){
|
|
|
|
self.deleteAllCharacters();
|
|
|
|
self.hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Keyboard key click handling
|
|
|
|
$('.keyboard li').click(function(){
|
|
|
|
|
|
|
|
var $this = $(this),
|
|
|
|
character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
|
|
|
|
|
|
|
|
if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
|
|
|
|
self.toggleShift();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('capslock')) {
|
|
|
|
self.toggleCapsLock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('delete')) {
|
|
|
|
self.deleteCharacter();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('numlock')){
|
|
|
|
self.toggleNumLock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special characters
|
|
|
|
if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
|
|
|
|
if ($this.hasClass('space')) character = ' ';
|
|
|
|
if ($this.hasClass('tab')) character = "\t";
|
|
|
|
if ($this.hasClass('return')) character = "\n";
|
|
|
|
|
|
|
|
// Uppercase letter
|
|
|
|
if ($this.hasClass('uppercase')) character = character.toUpperCase();
|
|
|
|
|
|
|
|
// Remove shift once a key is clicked.
|
|
|
|
self.removeShift();
|
|
|
|
|
|
|
|
self.writeCharacter(character);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
// ---------- Main Point of Sale Widget ----------
|
|
|
|
|
2012-04-26 10:05:48 +00:00
|
|
|
module.SynchNotification = instance.web.OldWidget.extend({
|
|
|
|
template: "pos-synch-notification",
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.nbr_pending = 0;
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
$('.oe_pos_synch-notification-button', this.$element).click(this.on_synch);
|
|
|
|
},
|
|
|
|
on_change_nbr_pending: function(nbr_pending) {
|
|
|
|
this.nbr_pending = nbr_pending;
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
on_synch: function() {}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.PosWidget = instance.web.OldWidget.extend({
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.pos = new module.PosModel(this.session);
|
2012-05-04 10:27:37 +00:00
|
|
|
this.numpad_visible = true;
|
|
|
|
this.leftpane_visible = true;
|
|
|
|
this.leftpane_width = '440px';
|
|
|
|
this.cashier_controls_visible = true;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2012-04-26 10:05:48 +00:00
|
|
|
var self = this;
|
|
|
|
return self.pos.ready.then(_.bind(function() {
|
|
|
|
this.renderElement();
|
|
|
|
this.synch_notification = new module.SynchNotification(this);
|
|
|
|
this.synch_notification.replace($('.oe_pos_synch-notification', this.$element));
|
|
|
|
this.synch_notification.on_synch.add(_.bind(self.pos.flush, self.pos));
|
|
|
|
|
|
|
|
self.pos.bind('change:nbr_pending_operations', this.changed_pending_operations, this);
|
|
|
|
this.changed_pending_operations();
|
|
|
|
|
|
|
|
this.$element.find("#loggedas button").click(function() {
|
|
|
|
self.try_close();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.buildWidgets();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
|
|
|
|
var action = result.result;
|
|
|
|
this.do_action(action);
|
|
|
|
}, this));
|
|
|
|
}, this));
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return qweb_template("POSWidget")();
|
|
|
|
},
|
|
|
|
buildWidgets: function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
$('button#neworder-button', this.$element).click(_.bind(this.createNewOrder, this));
|
|
|
|
|
2012-04-24 17:20:47 +00:00
|
|
|
(this.pos.get('orders')).bind('add', this.orderAdded, this);
|
|
|
|
(this.pos.get('orders')).add(new module.Order({'pos':this.pos}));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
this.search_product_screen = new module.SearchProductScreenWidget(this,{
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.search_product_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
this.scan_product_screen = new module.ScanProductScreenWidget(this,{
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.scan_product_screen.appendTo($('#rightpane'));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
|
|
|
this.receipt_screen = new module.ReceiptScreenWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.receipt_screen.appendTo($('#rightpane'));
|
|
|
|
|
|
|
|
this.payment_screen = new module.PaymentScreenWidget(this, {
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos,
|
2012-05-02 15:30:00 +00:00
|
|
|
pos_widget: this,
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
2012-05-02 15:30:00 +00:00
|
|
|
this.payment_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
this.welcome_screen = new module.WelcomeScreenWidget(this,{
|
|
|
|
pos:this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.welcome_screen.appendTo($('#rightpane'));
|
|
|
|
|
|
|
|
this.client_payment_screen = new module.ClientPaymentScreenWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.client_payment_screen.appendTo($('#rightpane'));
|
|
|
|
|
|
|
|
this.scale_invite_screen = new module.ScaleInviteScreenWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.scale_invite_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-03 16:40:32 +00:00
|
|
|
this.scale_product_screen = new module.ScaleProductScreenWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.scale_product_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-06 21:34:39 +00:00
|
|
|
this.help_popup = new module.HelpPopupWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.help_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-07 12:39:32 +00:00
|
|
|
this.receipt_popup = new module.ReceiptPopupWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.receipt_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
|
|
|
this.error_popup = new module.ErrorPopupWidget(this, {
|
|
|
|
pos: this.pos,
|
|
|
|
pos_widget: this,
|
|
|
|
});
|
|
|
|
this.error_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
this.paypadView = new module.PaypadWidget(null, {
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
this.paypadView.$element = $('#paypad');
|
|
|
|
this.paypadView.renderElement();
|
|
|
|
this.paypadView.start();
|
|
|
|
this.numpadView = new module.NumpadWidget(null);
|
|
|
|
this.numpadView.$element = $('#numpad');
|
|
|
|
this.numpadView.start();
|
|
|
|
this.orderView = new module.OrderWidget(null, {
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos,
|
2012-05-07 12:39:32 +00:00
|
|
|
pos_widget: this,
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
this.orderView.$element = $('#current-order-content');
|
|
|
|
this.orderView.start();
|
2012-05-03 16:27:46 +00:00
|
|
|
|
2012-05-04 12:24:48 +00:00
|
|
|
this.action_bar = new module.ActionBarWidget(null);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.action_bar.appendTo($(".point-of-sale #content"));
|
|
|
|
|
|
|
|
this.onscreen_keyboard = new module.OnscreenKeyboardWidget(null, {
|
|
|
|
'keyboard_model': 'simple'
|
|
|
|
});
|
|
|
|
this.onscreen_keyboard.appendTo($(".point-of-sale #content"));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
|
|
|
this.pos.screen_selector = new module.ScreenSelector({
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos,
|
2012-05-02 15:30:00 +00:00
|
|
|
screen_set:{
|
|
|
|
'products': this.search_product_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'scan': this.scan_product_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'payment' : this.payment_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'client_payment' : this.client_payment_screen,
|
|
|
|
'scale_invite' : this.scale_invite_screen,
|
2012-05-03 16:40:32 +00:00
|
|
|
'scale_product' : this.scale_product_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'receipt' : this.receipt_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'welcome' : this.welcome_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-05-06 21:34:39 +00:00
|
|
|
popup_set:{
|
|
|
|
'help': this.help_popup,
|
2012-05-07 12:39:32 +00:00
|
|
|
'error': this.error_popup,
|
|
|
|
'receipt': this.receipt_popup,
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-04 09:48:25 +00:00
|
|
|
default_client_screen: 'welcome',
|
|
|
|
default_cashier_screen: 'products',
|
|
|
|
default_mode: 'client',
|
2012-04-26 11:26:55 +00:00
|
|
|
});
|
2012-05-04 09:48:25 +00:00
|
|
|
window.screen_selector = this.pos.screen_selector;
|
2012-05-03 12:14:41 +00:00
|
|
|
|
|
|
|
this.pos.barcode_reader.connect();
|
2012-04-26 11:26:55 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
createNewOrder: function() {
|
|
|
|
var newOrder;
|
2012-04-24 17:20:47 +00:00
|
|
|
newOrder = new module.Order({'pos': this.pos});
|
|
|
|
(this.pos.get('orders')).add(newOrder);
|
|
|
|
this.pos.set({
|
2012-04-24 16:25:46 +00:00
|
|
|
selectedOrder: newOrder
|
|
|
|
});
|
|
|
|
},
|
|
|
|
orderAdded: function(newOrder) {
|
|
|
|
var newOrderButton;
|
|
|
|
newOrderButton = new module.OrderButtonWidget(null, {
|
|
|
|
order: newOrder,
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
|
|
|
newOrderButton.appendTo($('#orders'));
|
|
|
|
newOrderButton.selectOrder();
|
|
|
|
},
|
|
|
|
changed_pending_operations: function () {
|
|
|
|
var self = this;
|
2012-04-24 17:20:47 +00:00
|
|
|
this.synch_notification.on_change_nbr_pending(self.pos.get('nbr_pending_operations').length);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-04 10:27:37 +00:00
|
|
|
set_numpad_visible: function(visible){
|
|
|
|
if(visible != this.numpad_visible){
|
|
|
|
this.numpad_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#numpad').show();
|
|
|
|
$('#paypad').show();
|
|
|
|
}else{
|
|
|
|
$('#numpad').hide();
|
|
|
|
$('#paypad').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_leftpane_visible: function(visible){
|
|
|
|
if(visible != this.leftpane_visible){
|
|
|
|
this.leftpane_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#leftpane').show().animate({'width':this.leftpane_width},500,'swing');
|
|
|
|
$('#rightpane').animate({'left':this.leftpane_width},500,'swing');
|
|
|
|
}else{
|
|
|
|
var leftpane = $('#leftpane');
|
|
|
|
$('#leftpane').animate({'width':'0px'},500,'swing', function(){ leftpane.hide(); });
|
|
|
|
$('#rightpane').animate({'left':'0px'},500,'swing');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_cashier_controls_visible: function(visible){
|
|
|
|
if(visible != this.cashier_controls_visible){
|
|
|
|
this.cashier_controls_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#loggedas').show();
|
|
|
|
$('#rightheader').show();
|
|
|
|
}else{
|
|
|
|
$('#loggedas').hide();
|
|
|
|
$('#rightheader').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
try_close: function() {
|
|
|
|
var self = this;
|
2012-04-24 17:20:47 +00:00
|
|
|
self.pos.flush().then(_.bind(function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
var close = _.bind(this.close, this);
|
2012-04-24 17:20:47 +00:00
|
|
|
if (self.pos.get('nbr_pending_operations').length > 0) {
|
2012-04-24 16:25:46 +00:00
|
|
|
var confirm = false;
|
|
|
|
$(QWeb.render('pos-close-warning')).dialog({
|
|
|
|
resizable: false,
|
|
|
|
height:160,
|
|
|
|
modal: true,
|
|
|
|
title: "Warning",
|
|
|
|
buttons: {
|
|
|
|
"Yes": function() {
|
|
|
|
confirm = true;
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
},
|
|
|
|
"No": function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
if (confirm)
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
close: function() {
|
2012-05-03 12:14:41 +00:00
|
|
|
this.pos.barcode_reader.disconnect();
|
2012-04-24 16:25:46 +00:00
|
|
|
|
|
|
|
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_close_statement']], ['res_id']).pipe(
|
|
|
|
_.bind(function(res) {
|
|
|
|
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
|
|
|
|
var action = result.result;
|
|
|
|
action.context = _.extend(action.context || {}, {'cancel_action': {type: 'ir.actions.client', tag: 'default_home'}});
|
|
|
|
this.do_action(action);
|
|
|
|
}, this));
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
destroy: function() {
|
|
|
|
instance.webclient.set_content_full_screen(false);
|
2012-04-24 17:20:47 +00:00
|
|
|
self.pos = undefined;
|
2012-04-24 16:25:46 +00:00
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|