[imp] partially nivified the pos

bzr revid: nicolas.vanhoren@openerp.com-20111122061617-yk74cqmd61wrb8uw
This commit is contained in:
niv-openerp 2011-11-22 11:46:17 +05:30
commit 8301ca9e47
2 changed files with 337 additions and 376 deletions

View File

@ -162,11 +162,11 @@ openerp.point_of_sale = function(db) {
/* global variable */ /* global variable */
var pos; var pos;
var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryView, var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryWidget,
NumpadState, NumpadView, Order, OrderButtonView, OrderCollection, OrderView, Orderline, NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderWidget, Orderline,
OrderlineCollection, OrderlineView, PaymentButtonView, PaymentView, Paymentline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentWidget, Paymentline,
PaymentlineCollection, PaymentlineView, PaypadView, Product, ProductCollection, PaymentlineCollection, PaymentlineWidget, PaypadWidget, Product, ProductCollection,
ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsView; ProductListWidget, ProductWidget, ReceiptLineWidget, ReceiptWidget, Shop, ShopView, StepsWidget;
/* /*
--- ---
@ -530,57 +530,48 @@ openerp.point_of_sale = function(db) {
Views Views
--- ---
*/ */
NumpadView = (function() { NumpadWidget = db.web.Widget.extend({
__extends(NumpadView, Backbone.View); init: function(parent, element_id, options) {
function NumpadView() { this._super(parent, element_id);
NumpadView.__super__.constructor.apply(this, arguments); this.state = options.state;
} },
start: function() {
NumpadView.prototype.initialize = function(options) { this.$element.find('button#numpad-backspace').click(_.bind(this.clickDeleteLastChar, this));
return this.state = options.state; this.$element.find('button#numpad-minus').click(_.bind(this.clickSwitchSign, this));
}; this.$element.find('button.number-char').click(_.bind(this.clickAppendNewChar, this));
NumpadView.prototype.events = { this.$element.find('button.mode-button').click(_.bind(this.clickChangeMode, this));
'click button#numpad-backspace': 'clickDeleteLastChar', },
'click button#numpad-minus': 'clickSwitchSign', clickDeleteLastChar: function() {
'click button.number-char': 'clickAppendNewChar',
'click button.mode-button': 'clickChangeMode'
};
NumpadView.prototype.clickDeleteLastChar = function() {
return this.state.deleteLastChar(); return this.state.deleteLastChar();
}; },
NumpadView.prototype.clickSwitchSign = function() { clickSwitchSign: function() {
return this.state.switchSign(); return this.state.switchSign();
}; },
NumpadView.prototype.clickAppendNewChar = function(event) { clickAppendNewChar: function(event) {
var newChar; var newChar;
newChar = event.currentTarget.innerText; newChar = event.currentTarget.innerText;
return this.state.appendNewChar(newChar); return this.state.appendNewChar(newChar);
}; },
NumpadView.prototype.clickChangeMode = function(event) { clickChangeMode: function(event) {
var newMode; var newMode;
$('.selected-mode').removeClass('selected-mode'); $('.selected-mode').removeClass('selected-mode');
$(event.currentTarget).addClass('selected-mode'); $(event.currentTarget).addClass('selected-mode');
newMode = event.currentTarget.attributes['data-mode'].nodeValue; newMode = event.currentTarget.attributes['data-mode'].nodeValue;
return this.state.changeMode(newMode); return this.state.changeMode(newMode);
}; }
return NumpadView; });
})();
/* /*
Gives access to the payment methods (aka. 'cash registers') Gives access to the payment methods (aka. 'cash registers')
*/ */
PaypadView = (function() { PaypadWidget = db.web.Widget.extend({
__extends(PaypadView, Backbone.View); init: function(parent, element_id, options) {
function PaypadView() { this._super(parent, element_id);
PaypadView.__super__.constructor.apply(this, arguments); this.shop = options.shop;
} },
start: function() {
PaypadView.prototype.initialize = function(options) { this.$element.find('button').click(_.bind(this.performPayment, this));
return this.shop = options.shop; },
}; performPayment: function(event) {
PaypadView.prototype.events = {
'click button': 'performPayment'
};
PaypadView.prototype.performPayment = function(event) {
var cashRegister, cashRegisterCollection, cashRegisterId; var cashRegister, cashRegisterCollection, cashRegisterId;
/* set correct view */ /* set correct view */
$('.step-screen').hide(); $('.step-screen').hide();
@ -592,32 +583,26 @@ openerp.point_of_sale = function(db) {
return (item.get('id')) === parseInt(cashRegisterId, 10); return (item.get('id')) === parseInt(cashRegisterId, 10);
}, this)); }, this));
return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister); return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister);
}; },
PaypadView.prototype.render = function() { render_element: function() {
$(this.el).empty(); this.$element.empty();
return (this.shop.get('cashRegisters')).each(__bind( function(cashRegister) { return (this.shop.get('cashRegisters')).each(__bind( function(cashRegister) {
return $(this.el).append((new PaymentButtonView({ var button = new PaymentButtonWidget();
model: cashRegister button.model = cashRegister;
})).render()); button.appendTo(this.$element);
}, this)); }, this));
};
return PaypadView;
})();
PaymentButtonView = (function() {
__extends(PaymentButtonView, Backbone.View);
function PaymentButtonView() {
PaymentButtonView.__super__.constructor.apply(this, arguments);
} }
});
PaymentButtonView.prototype.template = qweb_template('pos-payment-button-template'); PaymentButtonWidget = db.web.Widget.extend({
PaymentButtonView.prototype.render = function() { template_fct: qweb_template('pos-payment-button-template'),
return $(this.el).html(this.template({ render_element: function() {
this.$element.html(this.template_fct({
id: this.model.get('id'), id: this.model.get('id'),
name: (this.model.get('journal_id'))[1] name: (this.model.get('journal_id'))[1]
})); }));
}; return this;
return PaymentButtonView; }
})(); });
/* /*
There are 3 steps in a POS workflow: There are 3 steps in a POS workflow:
1. prepare the order (i.e. chose products, quantities etc.) 1. prepare the order (i.e. chose products, quantities etc.)
@ -626,112 +611,101 @@ openerp.point_of_sale = function(db) {
It should be possible to go back to any step as long as step 3 hasn't been completed. It should be possible to go back to any step as long as step 3 hasn't been completed.
Modifying an order after validation shouldn't be allowed. Modifying an order after validation shouldn't be allowed.
*/ */
StepsView = (function() { StepsWidget = db.web.Widget.extend({
__extends(StepsView, Backbone.View); init: function(parent, element_id) {
function StepsView() { this._super(parent, element_id);
StepsView.__super__.constructor.apply(this, arguments); this.step = "products";
} },
start: function() {
StepsView.prototype.initialize = function(options) { this.$element.find('input.step-button').click(_.bind(this.clickChangeStep, this));
return this.step = "products"; },
}; clickChangeStep: function(event) {
StepsView.prototype.events = {
'click input.step-button': 'clickChangeStep'
};
StepsView.prototype.clickChangeStep = function(event) {
var newStep; var newStep;
newStep = event.currentTarget.attributes['data-step'].nodeValue; newStep = event.currentTarget.attributes['data-step'].nodeValue;
$('.step-screen').hide(); $('.step-screen').hide();
$('#' + newStep + '-screen').show(); $('#' + newStep + '-screen').show();
return this.step = newStep; return this.step = newStep;
}; }
return StepsView; });
})();
/* /*
Shopping carts. Shopping carts.
*/ */
OrderlineView = (function() { OrderlineWidget = db.web.Widget.extend({
__extends(OrderlineView, Backbone.View); tagName: 'tr',
function OrderlineView() { template_fct: qweb_template('pos-orderline-template'),
OrderlineView.__super__.constructor.apply(this, arguments); init: function(parent, element_id, options) {
} this._super(parent, element_id);
this.model = options.model;
OrderlineView.prototype.tagName = 'tr';
OrderlineView.prototype.template = qweb_template('pos-orderline-template');
OrderlineView.prototype.initialize = function(options) {
this.model.bind('change', __bind( function() { this.model.bind('change', __bind( function() {
$(this.el).hide(); this.$element.hide();
return this.render(); this.render_element();
}, this)); }, this));
this.model.bind('remove', __bind( function() { this.model.bind('remove', __bind( function() {
return $(this.el).remove(); return this.$element.remove();
}, this)); }, this));
this.order = options.order; this.order = options.order;
return this.numpadState = options.numpadState; this.numpadState = options.numpadState;
}; },
OrderlineView.prototype.events = { start: function() {
'click': 'clickHandler' this.$element.click(_.bind(this.clickHandler, this));
}; },
OrderlineView.prototype.clickHandler = function() { clickHandler: function() {
this.numpadState.reset(); this.numpadState.reset();
return this.select(); return this.select();
}; },
OrderlineView.prototype.render = function() { render_element: function() {
this.select(); this.select();
return $(this.el).html(this.template(this.model.toJSON())).fadeIn(400, function() { return this.$element.html(this.template_fct(this.model.toJSON())).fadeIn(400, function() {
return $('#current-order').scrollTop($(this).offset().top); return $('#current-order').scrollTop($(this).offset().top);
}); });
}; },
OrderlineView.prototype.select = function() { select: function() {
$('tr.selected').removeClass('selected'); $('tr.selected').removeClass('selected');
$(this.el).addClass('selected'); this.$element.addClass('selected');
return this.order.selected = this.model; return this.order.selected = this.model;
}; },
return OrderlineView; });
})(); OrderWidget = db.web.Widget.extend({
OrderView = (function() { init: function(parent, element_id, options) {
__extends(OrderView, Backbone.View); this._super(parent, element_id);
function OrderView() {
OrderView.__super__.constructor.apply(this, arguments);
}
OrderView.prototype.initialize = function(options) {
this.shop = options.shop; this.shop = options.shop;
this.numpadState = options.numpadState; this.numpadState = options.numpadState;
this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this);
return this.bindOrderLineEvents(); this.bindOrderLineEvents();
}; },
OrderView.prototype.changeSelectedOrder = function() { changeSelectedOrder: function() {
this.currentOrderLines.unbind(); this.currentOrderLines.unbind();
this.bindOrderLineEvents(); this.bindOrderLineEvents();
return this.render(); return this.render_element();
}; },
OrderView.prototype.bindOrderLineEvents = function() { bindOrderLineEvents: function() {
this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines');
this.currentOrderLines.bind('add', this.addLine, this); this.currentOrderLines.bind('add', this.addLine, this);
this.currentOrderLines.bind('change', this.render, this); this.currentOrderLines.bind('change', this.render_element, this);
return this.currentOrderLines.bind('remove', this.render, this); return this.currentOrderLines.bind('remove', this.render, this);
}; },
OrderView.prototype.addLine = function(newLine) { addLine: function(newLine) {
$(this.el).append((new OrderlineView({ var line = new OrderlineWidget(null, null, {
model: newLine, model: newLine,
order: this.shop.get('selectedOrder'), order: this.shop.get('selectedOrder'),
numpadState: this.numpadState numpadState: this.numpadState
})).render()); });
line.appendTo(this.$element);
return this.updateSummary(); return this.updateSummary();
}; },
OrderView.prototype.render = function() { render_element: function() {
$(this.el).empty(); this.$element.empty();
this.currentOrderLines.each(__bind( function(orderLine) { this.currentOrderLines.each(__bind( function(orderLine) {
return $(this.el).append((new OrderlineView({ var line = new OrderlineWidget(null, null, {
model: orderLine, model: orderLine,
order: this.shop.get('selectedOrder'), order: this.shop.get('selectedOrder'),
numpadState: this.numpadState numpadState: this.numpadState
})).render()); });
line.appendTo(this.$element);
}, this)); }, this));
return this.updateSummary(); return this.updateSummary();
}; },
OrderView.prototype.updateSummary = function() { updateSummary: function() {
var currentOrder, tax, total, totalTaxExcluded; var currentOrder, tax, total, totalTaxExcluded;
currentOrder = this.shop.get('selectedOrder'); currentOrder = this.shop.get('selectedOrder');
total = currentOrder.getTotal(); total = currentOrder.getTotal();
@ -740,31 +714,25 @@ openerp.point_of_sale = function(db) {
$('#subtotal').html(totalTaxExcluded.toFixed(2)).hide().fadeIn(); $('#subtotal').html(totalTaxExcluded.toFixed(2)).hide().fadeIn();
$('#tax').html(tax.toFixed(2)).hide().fadeIn(); $('#tax').html(tax.toFixed(2)).hide().fadeIn();
return $('#total').html(total.toFixed(2)).hide().fadeIn(); return $('#total').html(total.toFixed(2)).hide().fadeIn();
}; },
return OrderView; });
})();
/* /*
"Products" step. "Products" step.
*/ */
CategoryView = (function() { CategoryWidget = db.web.Widget.extend({
__extends(CategoryView, Backbone.View); start: function() {
function CategoryView() { this.$element.find(".oe-pos-categories-list a").click(_.bind(this.changeCategory, this));
CategoryView.__super__.constructor.apply(this, arguments); },
} template_fct: qweb_template('pos-category-template'),
render_element: function() {
CategoryView.prototype.events = { var self = this;
'click .oe-pos-categories-list a': 'changeCategory'
};
CategoryView.prototype.template = qweb_template('pos-category-template');
CategoryView.prototype.render = function(ancestors, children) {
var c; var c;
return $(this.el).html(this.template({ this.$element.html(this.template_fct({
breadcrumb: (function() { breadcrumb: (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = ancestors.length; _i < _len; _i++) { for (_i = 0, _len = self.ancestors.length; _i < _len; _i++) {
c = ancestors[_i]; c = self.ancestors[_i];
_results.push(pos.categories[c]); _results.push(pos.categories[c]);
} }
return _results; return _results;
@ -772,88 +740,77 @@ openerp.point_of_sale = function(db) {
categories: (function() { categories: (function() {
var _i, _len, _results; var _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = children.length; _i < _len; _i++) { for (_i = 0, _len = self.children.length; _i < _len; _i++) {
c = children[_i]; c = self.children[_i];
_results.push(pos.categories[c]); _results.push(pos.categories[c]);
} }
return _results; return _results;
})() })()
})); }));
}; },
CategoryView.prototype.changeCategory = function(a) { changeCategory: function(a) {
var id = $(a.target).data("category-id"); var id = $(a.target).data("category-id");
this.trigger("changeCategory", id); this.on_change_category(id);
}; },
return CategoryView; on_change_category: function(id) {},
})(); });
ProductView = (function() { ProductWidget = db.web.Widget.extend({
__extends(ProductView, Backbone.View); tag_name:'li',
function ProductView() { template_fct: qweb_template('pos-product-template'),
ProductView.__super__.constructor.apply(this, arguments); init: function(parent, element_id, options) {
} this._super(parent, element_id);
this.model = options.model;
ProductView.prototype.tagName = 'li'; this.shop = options.shop;
ProductView.prototype.className = 'product'; },
ProductView.prototype.template = qweb_template('pos-product-template'); start: function(options) {
ProductView.prototype.events = { $("a", this.$element).click(_.bind(this.addToOrder, this));
'click a': 'addToOrder' },
}; addToOrder: function(event) {
ProductView.prototype.initialize = function(options) {
return this.shop = options.shop;
};
ProductView.prototype.addToOrder = function(event) {
/* Preserve the category URL */ /* Preserve the category URL */
event.preventDefault(); event.preventDefault();
return (this.shop.get('selectedOrder')).addProduct(this.model); return (this.shop.get('selectedOrder')).addProduct(this.model);
}; },
ProductView.prototype.render = function() { render_element: function() {
return $(this.el).html(this.template(this.model.toJSON())); this.$element.addClass("product");
}; this.$element.html(this.template_fct(this.model.toJSON()));
return ProductView; return this;
})(); },
ProductListView = (function() { });
__extends(ProductListView, Backbone.View); ProductListWidget = db.web.Widget.extend({
function ProductListView() { init: function(parent, element_id, options) {
ProductListView.__super__.constructor.apply(this, arguments); this._super(parent, element_id);
} this.model = options.model;
ProductListView.prototype.tagName = 'ol';
ProductListView.prototype.className = 'product-list';
ProductListView.prototype.initialize = function(options) {
this.shop = options.shop; this.shop = options.shop;
return (this.shop.get('products')).bind('reset', this.render, this); this.shop.get('products').bind('reset', this.render_element, this);
}; },
ProductListView.prototype.render = function() { render_element: function() {
$(this.el).empty(); this.$element.empty();
(this.shop.get('products')).each(__bind( function(product) { (this.shop.get('products')).each(__bind( function(product) {
return $(this.el).append((new ProductView({ var p = new ProductWidget(null, null, {
model: product, model: product,
shop: this.shop shop: this.shop
})).render()); });
p.appendTo(this.$element);
}, this)); }, this));
return $('#products-screen').append(this.el); return this;
}; },
return ProductListView; });
})();
/* /*
"Payment" step. "Payment" step.
*/ */
PaymentlineView = (function() { PaymentlineWidget = db.web.Widget.extend({
__extends(PaymentlineView, Backbone.View); tag_name: 'tr',
function PaymentlineView() { template_fct: qweb_template('pos-paymentline-template'),
PaymentlineView.__super__.constructor.apply(this, arguments); init: function(parent, element_id, options) {
} this._super(parent, element_id);
this.model = options.model;
PaymentlineView.prototype.tagName = 'tr'; this.model.bind('change', this.render_element, this);
PaymentlineView.prototype.className = 'paymentline'; },
PaymentlineView.prototype.template = qweb_template('pos-paymentline-template'); start: function () {
PaymentlineView.prototype.initialize = function() { this.$element.addClass('paymentline');
return this.model.bind('change', this.render, this); $('input', this.$element).keyup(_.bind(this.changeAmount, this));
}; },
PaymentlineView.prototype.events = { changeAmount: function(event) {
'keyup input': 'changeAmount'
};
PaymentlineView.prototype.changeAmount = function(event) {
var newAmount; var newAmount;
newAmount = event.currentTarget.value; newAmount = event.currentTarget.value;
if (newAmount && !isNaN(newAmount)) { if (newAmount && !isNaN(newAmount)) {
@ -861,164 +818,155 @@ openerp.point_of_sale = function(db) {
amount: parseFloat(newAmount) amount: parseFloat(newAmount)
}); });
} }
}; },
PaymentlineView.prototype.render = function() { render_element: function() {
return $(this.el).html(this.template({ this.$element.html(this.template_fct({
name: (this.model.get('journal_id'))[1], name: (this.model.get('journal_id'))[1],
amount: this.model.get('amount') amount: this.model.get('amount')
})); }));
}; return this;
return PaymentlineView; },
})(); });
PaymentView = (function() { PaymentWidget = db.web.Widget.extend({
__extends(PaymentView, Backbone.View); init: function(parent, element_id, options) {
function PaymentView() { this._super(parent, element_id);
PaymentView.__super__.constructor.apply(this, arguments); this.model = options.model;
}
PaymentView.prototype.initialize = function(options) {
this.shop = options.shop; this.shop = options.shop;
this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this);
this.bindPaymentLineEvents(); this.bindPaymentLineEvents();
return this.bindOrderLineEvents(); this.bindOrderLineEvents();
}; },
PaymentView.prototype.paymentLineList = function() { paymentLineList: function() {
return $(this.el).find('#paymentlines'); return this.$element.find('#paymentlines');
}; },
PaymentView.prototype.events = { start: function() {
'click button#validate-order': 'validateCurrentOrder' $('button#validate-order', this.$element).click(_.bind(this.validateCurrentOrder, this));
}; },
PaymentView.prototype.validateCurrentOrder = function() { validateCurrentOrder: function() {
var callback, currentOrder; var callback, currentOrder;
currentOrder = this.shop.get('selectedOrder'); currentOrder = this.shop.get('selectedOrder');
callback = __bind( function() { callback = __bind(function() {
return currentOrder.set({ return currentOrder.set({
validated: true validated: true
}); });
}, this); }, this);
return pos.push('pos.order', currentOrder.exportAsJSON(), callback); pos.push('pos.order', currentOrder.exportAsJSON(), callback);
}; },
PaymentView.prototype.bindPaymentLineEvents = function() { bindPaymentLineEvents: function() {
this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines');
this.currentPaymentLines.bind('add', this.addPaymentLine, this); this.currentPaymentLines.bind('add', this.addPaymentLine, this);
this.currentPaymentLines.bind('change', this.render, this); this.currentPaymentLines.bind('all', this.updatePaymentSummary, this);
this.currentPaymentLines.bind('remove', this.render, this); },
return this.currentPaymentLines.bind('all', this.updatePaymentSummary, this); bindOrderLineEvents: function() {
};
PaymentView.prototype.bindOrderLineEvents = function() {
this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines');
return this.currentOrderLines.bind('all', this.updatePaymentSummary, this); this.currentOrderLines.bind('all', this.updatePaymentSummary, this);
}; },
PaymentView.prototype.changeSelectedOrder = function() { changeSelectedOrder: function() {
this.currentPaymentLines.unbind(); this.currentPaymentLines.unbind();
this.bindPaymentLineEvents(); this.bindPaymentLineEvents();
this.currentOrderLines.unbind(); this.currentOrderLines.unbind();
this.bindOrderLineEvents(); this.bindOrderLineEvents();
return this.render(); this.render_element();
}; },
PaymentView.prototype.addPaymentLine = function(newPaymentLine) { addPaymentLine: function(newPaymentLine) {
return this.paymentLineList().append((new PaymentlineView({ var x = new PaymentlineWidget(null, null, {
model: newPaymentLine model: newPaymentLine
})).render()); });
}; x.appendTo(this.paymentLineList());
PaymentView.prototype.render = function() { },
render_element: function() {
this.paymentLineList().empty(); this.paymentLineList().empty();
this.currentPaymentLines.each(__bind( function(paymentLine) { this.currentPaymentLines.each(__bind( function(paymentLine) {
return this.paymentLineList().append((new PaymentlineView({ var x = new PaymentlineWidget(null, null, {
model: paymentLine model: paymentLine
})).render()); });
this.paymentLineList().append(x);
}, this)); }, this));
return this.updatePaymentSummary(); this.updatePaymentSummary();
}; },
PaymentView.prototype.updatePaymentSummary = function() { updatePaymentSummary: function() {
var currentOrder, dueTotal, paidTotal, remaining, remainingAmount; var currentOrder, dueTotal, paidTotal, remaining, remainingAmount;
currentOrder = this.shop.get('selectedOrder'); currentOrder = this.shop.get('selectedOrder');
paidTotal = currentOrder.getPaidTotal(); paidTotal = currentOrder.getPaidTotal();
dueTotal = currentOrder.getTotal(); dueTotal = currentOrder.getTotal();
$(this.el).find('#payment-due-total').html(dueTotal.toFixed(2)); this.$element.find('#payment-due-total').html(dueTotal.toFixed(2));
$(this.el).find('#payment-paid-total').html(paidTotal.toFixed(2)); this.$element.find('#payment-paid-total').html(paidTotal.toFixed(2));
remainingAmount = dueTotal - paidTotal; remainingAmount = dueTotal - paidTotal;
remaining = remainingAmount > 0 ? 0 : (-remainingAmount).toFixed(2); remaining = remainingAmount > 0 ? 0 : (-remainingAmount).toFixed(2);
return $('#payment-remaining').html(remaining); $('#payment-remaining').html(remaining);
}; },
return PaymentView; });
})();
/* /*
"Receipt" step. "Receipt" step.
*/ */
ReceiptLineView = (function() { ReceiptLineWidget = db.web.Widget.extend({
__extends(ReceiptLineView, Backbone.View); tag_name: 'tr',
function ReceiptLineView() { template_fct: qweb_template('pos-receiptline-template'),
ReceiptLineView.__super__.constructor.apply(this, arguments); init: function(parent, options) {
} this._super(parent);
this.model = options.model;
ReceiptLineView.prototype.tagName = 'tr'; this.model.bind('change', this.render_element, this);
ReceiptLineView.prototype.className = 'receiptline'; },
ReceiptLineView.prototype.template = qweb_template('pos-receiptline-template'); render_element: function() {
ReceiptLineView.prototype.initialize = function() { this.$element.addClass('receiptline');
return this.model.bind('change', this.render, this); this.$element.html(this.template_fct(this.model.toJSON()));
}; },
ReceiptLineView.prototype.render = function() { });
return $(this.el).html(this.template(this.model.toJSON())); ReceiptWidget = db.web.Widget.extend({
}; init: function(parent, options) {
return ReceiptLineView; this._super(parent);
})(); this.model = options.model;
ReceiptView = (function() {
__extends(ReceiptView, Backbone.View);
function ReceiptView() {
ReceiptView.__super__.constructor.apply(this, arguments);
}
ReceiptView.prototype.initialize = function(options) {
this.shop = options.shop; this.shop = options.shop;
this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this);
this.bindOrderLineEvents(); this.bindOrderLineEvents();
return this.bindPaymentLineEvents(); this.bindPaymentLineEvents();
}; },
ReceiptView.prototype.events = { start: function () {
"click button#pos-finish-order": "finishOrder" $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this));
}; },
ReceiptView.prototype.finishOrder = function() { finishOrder: function() {
$('.step-screen').hide(); $('.step-screen').hide();
$('#products-screen').show(); $('#products-screen').show();
this.shop.get('selectedOrder').destroy(); this.shop.get('selectedOrder').destroy();
}; },
ReceiptView.prototype.receiptLineList = function() { receiptLineList: function() {
return $(this.el).find('#receiptlines'); return this.$element.find('#receiptlines');
}; },
ReceiptView.prototype.bindOrderLineEvents = function() { bindOrderLineEvents: function() {
this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines');
this.currentOrderLines.bind('add', this.addReceiptLine, this); this.currentOrderLines.bind('add', this.addReceiptLine, this);
this.currentOrderLines.bind('change', this.render, this); this.currentOrderLines.bind('change', this.render_element, this);
return this.currentOrderLines.bind('remove', this.render, this); this.currentOrderLines.bind('remove', this.render_element, this);
}; },
ReceiptView.prototype.bindPaymentLineEvents = function() { bindPaymentLineEvents: function() {
this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines');
return this.currentPaymentLines.bind('all', this.updateReceiptSummary, this); this.currentPaymentLines.bind('all', this.updateReceiptSummary, this);
}; },
ReceiptView.prototype.changeSelectedOrder = function() { changeSelectedOrder: function() {
this.currentOrderLines.unbind(); this.currentOrderLines.unbind();
this.bindOrderLineEvents(); this.bindOrderLineEvents();
this.currentPaymentLines.unbind(); this.currentPaymentLines.unbind();
this.bindPaymentLineEvents(); this.bindPaymentLineEvents();
return this.render(); this.render_element();
}; },
ReceiptView.prototype.addReceiptLine = function(newOrderItem) { addReceiptLine: function(newOrderItem) {
this.receiptLineList().append((new ReceiptLineView({ var x = new ReceiptLineWidget(null, {
model: newOrderItem model: newOrderItem
})).render()); });
return this.updateReceiptSummary(); x.appendTo(this.receiptLineList());
}; this.updateReceiptSummary();
ReceiptView.prototype.render = function() { },
this.receiptLineList().empty(); render_element: function() {
this.$element.html(qweb_template('pos-receipt-view'));
this.currentOrderLines.each(__bind( function(orderItem) { this.currentOrderLines.each(__bind( function(orderItem) {
return this.receiptLineList().append((new ReceiptLineView({ var x = new ReceiptLineWidget(null, {
model: orderItem model: orderItem
})).render()); });
x.appendTo(this.receiptLineList());
}, this)); }, this));
return this.updateReceiptSummary(); this.updateReceiptSummary();
}; },
ReceiptView.prototype.updateReceiptSummary = function() { updateReceiptSummary: function() {
var change, currentOrder, tax, total; var change, currentOrder, tax, total;
currentOrder = this.shop.get('selectedOrder'); currentOrder = this.shop.get('selectedOrder');
total = currentOrder.getTotal(); total = currentOrder.getTotal();
@ -1026,10 +974,9 @@ openerp.point_of_sale = function(db) {
change = currentOrder.getPaidTotal() - total; change = currentOrder.getPaidTotal() - total;
$('#receipt-summary-tax').html(tax.toFixed(2)); $('#receipt-summary-tax').html(tax.toFixed(2));
$('#receipt-summary-total').html(total.toFixed(2)); $('#receipt-summary-total').html(total.toFixed(2));
return $('#receipt-summary-change').html(change.toFixed(2)); $('#receipt-summary-change').html(change.toFixed(2));
}; },
return ReceiptView; });
})();
OrderButtonView = (function() { OrderButtonView = (function() {
__extends(OrderButtonView, Backbone.View); __extends(OrderButtonView, Backbone.View);
function OrderButtonView() { function OrderButtonView() {
@ -1087,38 +1034,45 @@ openerp.point_of_sale = function(db) {
this.numpadState = new NumpadState({ this.numpadState = new NumpadState({
shop: this.shop shop: this.shop
}); });
this.productListView = new ProductListView({ this.productListView = new ProductListWidget(null, "products-screen-ol", {
shop: this.shop shop: this.shop
}); });
this.paypadView = new PaypadView({ this.productListView.render_element();
this.productListView.start();
this.paypadView = new PaypadWidget(null, 'paypad', {
shop: this.shop
});
this.paypadView.render_element();
this.paypadView.start();
this.orderView = new OrderWidget(null, 'current-order-content', {
shop: this.shop, shop: this.shop,
el: $('#paypad') numpadState: this.numpadState
}); });
this.paypadView.render(); this.orderView.start();
this.orderView = new OrderView({ this.paymentView = new PaymentWidget(null, 'payment-screen', {
shop: this.shop
});
this.paymentView.render_element();
this.paymentView.start();
this.receiptView = new ReceiptWidget(null, {
shop: this.shop, shop: this.shop,
numpadState: this.numpadState,
el: $('#current-order-content')
}); });
this.paymentView = new PaymentView({ debugger;
shop: this.shop, this.receiptView.replace($('#receipt-screen'));
el: $('#payment-screen') this.numpadView = new NumpadWidget(null, 'numpad', {
}); state: this.numpadState
this.receiptView = new ReceiptView({
shop: this.shop,
el: $('#receipt-screen')
});
this.numpadView = new NumpadView({
state: this.numpadState,
el: $('#numpad')
});
return this.stepsView = new StepsView({
el: $('#steps')
}); });
this.numpadView.start();
this.stepsView = new StepsWidget(null, 'steps');
this.stepsView.start();
this.start();
}; };
ShopView.prototype.events = { ShopView.prototype.events = {
'click button#neworder-button': 'createNewOrder' 'click button#neworder-button': 'createNewOrder'
}; };
ShopView.prototype.start = function() {
this.productListView.start();
};
ShopView.prototype.createNewOrder = function() { ShopView.prototype.createNewOrder = function() {
var newOrder; var newOrder;
newOrder = new Order; newOrder = new Order;
@ -1149,10 +1103,9 @@ openerp.point_of_sale = function(db) {
shop: this.shop, shop: this.shop,
el: $element el: $element
}); });
this.categoryView = new CategoryView; this.categoryView = new CategoryWidget(null, 'products-screen-categories');
this.categoryView.bind("changeCategory", this.category, this); this.categoryView.on_change_category.add_last(_.bind(this.category, this));
this.category(); this.category();
return this.categoryView;
}; };
App.prototype.category = function(id) { App.prototype.category = function(id) {
var c, products; var c, products;
@ -1160,8 +1113,10 @@ openerp.point_of_sale = function(db) {
id = 0; id = 0;
} }
c = pos.categories[id]; c = pos.categories[id];
$('#products-screen').html(this.categoryView.render(c.ancestors, c.children)); this.categoryView.ancestors = c.ancestors;
this.categoryView.delegateEvents(); this.categoryView.children = c.children;
this.categoryView.render_element();
this.categoryView.start();
products = pos.store.get('product.product').filter( function(p) { products = pos.store.get('product.product').filter( function(p) {
var _ref; var _ref;
return _ref = p.pos_categ_id[0], __indexOf.call(c.subtree, _ref) >= 0; return _ref = p.pos_categ_id[0], __indexOf.call(c.subtree, _ref) >= 0;

View File

@ -88,7 +88,10 @@
</footer> </footer>
</div> </div>
<div id="rightpane"> <div id="rightpane">
<div id="products-screen" class="step-screen selected-step"></div> <div id="products-screen" class="step-screen selected-step">
<div id="products-screen-categories"/>
<ol id="products-screen-ol" class="product-list"></ol>
</div>
<div id="payment-screen" class="step-screen" style="display:none"> <div id="payment-screen" class="step-screen" style="display:none">
<header><h2>Payment</h2></header> <header><h2>Payment</h2></header>
<div class="pos-step-container"> <div class="pos-step-container">
@ -114,28 +117,7 @@
</div> </div>
</div> </div>
</div> </div>
<div id="receipt-screen" class="step-screen" style="display:none"> <span id="receipt-screen"></span>
<header><h2>Receipt</h2></header>
<div class="pos-step-container">
<div class="pos-receipt-container">
<div class="pos-sale-ticket">
OpenERP Point of Sale<br />
<br />
<div class="pos-rigth-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +
Date.CultureInfo.formatPatterns.longTime)"/></div>
<br />
<table id="receiptlines"></table>
<br />
<table>
<tr><td>Total:</td><td class="pos-rigth-align"><span id="receipt-summary-total"></span></td></tr>
<tr><td>Tax:</td><td class="pos-rigth-align"><span id="receipt-summary-tax"></span></td></tr>
<tr><td>Change:</td><td class="pos-rigth-align"><span id="receipt-summary-change"></span></td></tr>
</table>
</div>
</div>
<button id="pos-finish-order">Next Order</button>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -237,4 +219,28 @@
<button class="select-order">Order</button> <button class="select-order">Order</button>
<button class="close-order">X</button> <button class="close-order">X</button>
</t> </t>
<t t-name="pos-receipt-view">
<div id="receipt-screen" class="step-screen" style="display:none">
<header><h2>Receipt</h2></header>
<div class="pos-step-container">
<div class="pos-receipt-container">
<div class="pos-sale-ticket">
OpenERP Point of Sale<br />
<br />
<div class="pos-rigth-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +
Date.CultureInfo.formatPatterns.longTime)"/></div>
<br />
<table id="receiptlines"></table>
<br />
<table>
<tr><td>Total:</td><td class="pos-rigth-align"><span id="receipt-summary-total"></span></td></tr>
<tr><td>Tax:</td><td class="pos-rigth-align"><span id="receipt-summary-tax"></span></td></tr>
<tr><td>Change:</td><td class="pos-rigth-align"><span id="receipt-summary-change"></span></td></tr>
</table>
</div>
</div>
<button id="pos-finish-order">Next Order</button>
</div>
</div>
</t>
</templates> </templates>