From 7e241a1e4ae3ea006897cd65ac8d731ec0b4abd6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 15 Dec 2011 16:14:42 +0100 Subject: [PATCH 01/14] [imp] refactored ticket bzr revid: nicolas.vanhoren@openerp.com-20111215151442-qwej1sb8kiokbfov --- addons/point_of_sale/static/src/js/pos.js | 86 ++++++--------------- addons/point_of_sale/static/src/xml/pos.xml | 71 ++++++++--------- 2 files changed, 56 insertions(+), 101 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 173793c3251..24daf465696 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -940,81 +940,39 @@ openerp.point_of_sale = function(db) { $('#payment-remaining').html(remaining); }, }); - /* - "Receipt" step. - */ - var ReceiptLineWidget = db.web.Widget.extend({ - tag_name: 'tr', - template_fct: qweb_template('pos-receiptline-template'), - init: function(parent, options) { - this._super(parent); - this.model = options.model; - this.model.bind('change', this.render_element, this); - }, - render_element: function() { - this.$element.addClass('receiptline'); - this.$element.html(this.template_fct(this.model.toJSON())); - }, - }); var ReceiptWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.model = options.model; this.shop = options.shop; + }, + start: function() { this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); - this.bindOrderLineEvents(); - this.bindPaymentLineEvents(); - }, - finishOrder: function() { - this.shop.get('selectedOrder').destroy(); - }, - receiptLineList: function() { - return this.$element.find('#receiptlines'); - }, - bindOrderLineEvents: function() { - this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); - this.currentOrderLines.bind('add', this.addReceiptLine, this); - this.currentOrderLines.bind('change', this.render_element, this); - this.currentOrderLines.bind('remove', this.render_element, this); - }, - bindPaymentLineEvents: function() { - this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); - this.currentPaymentLines.bind('all', this.updateReceiptSummary, this); - }, - changeSelectedOrder: function() { - this.currentOrderLines.unbind(); - this.bindOrderLineEvents(); - this.currentPaymentLines.unbind(); - this.bindPaymentLineEvents(); - this.render_element(); - }, - addReceiptLine: function(newOrderItem) { - var x = new ReceiptLineWidget(null, { - model: newOrderItem - }); - x.appendTo(this.receiptLineList()); - this.updateReceiptSummary(); + this.changeSelectedOrder(); }, render_element: function() { this.$element.html(qweb_template('pos-receipt-view')); $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); - this.currentOrderLines.each(_.bind( function(orderItem) { - var x = new ReceiptLineWidget(null, { - model: orderItem - }); - x.appendTo(this.receiptLineList()); - }, this)); - this.updateReceiptSummary(); }, - updateReceiptSummary: function() { - var change, currentOrder, tax, total; - currentOrder = this.shop.get('selectedOrder'); - total = currentOrder.getTotal(); - tax = currentOrder.getTax(); - change = currentOrder.getPaidTotal() - total; - $('#receipt-summary-tax').html(tax.toFixed(2)); - $('#receipt-summary-total').html(total.toFixed(2)); - $('#receipt-summary-change').html(change.toFixed(2)); + finishOrder: function() { + this.shop.get('selectedOrder').destroy(); + }, + changeSelectedOrder: function() { + if (this.currentOrderLines) + this.currentOrderLines.unbind(); + this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); + this.currentOrderLines.bind('add', this.refresh, this); + this.currentOrderLines.bind('change', this.refresh, this); + this.currentOrderLines.bind('remove', this.refresh, this); + if (this.currentPaymentLines) + this.currentPaymentLines.unbind(); + this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); + this.currentPaymentLines.bind('all', this.refresh, this); + this.refresh(); + }, + refresh: function() { + this.currentOrder = this.shop.get('selectedOrder'); + $('.pos-receipt-container', this.$element).html(qweb_template('pos-ticket')({widget:this})); }, }); var OrderButtonWidget = db.web.Widget.extend({ diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 662217ff485..b19bfbd306d 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -206,17 +206,6 @@ - - - - - - - - - - - + +
+ OpenERP Point of Sale
+
+
+
+ + + + + + +
+ + + + + +
+
+ + + + +
Total: + +
Tax: + +
Change: + +
+
+
\ No newline at end of file From c3c6ae8771168c0f89a9245dbb6586a3c69204fa Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 15 Dec 2011 16:44:04 +0100 Subject: [PATCH 02/14] [imp] improved ticket bzr revid: nicolas.vanhoren@openerp.com-20111215154404-jnbeoswdwjkr3tk2 --- addons/point_of_sale/static/src/css/pos.css | 3 -- addons/point_of_sale/static/src/xml/pos.xml | 39 +++++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index afb6d19898f..3d34ff8f795 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -472,9 +472,6 @@ .point-of-sale .pos-sale-ticket table td { border: 0; } -.point-of-sale .pos-sale-ticket table td.receiptline-amount { - text-align: right; -} .point-of-sale .pos-receipt-container { font-size: 0.75em; } diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index b19bfbd306d..2fe2f229fa4 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -228,32 +228,49 @@
- OpenERP Point of Sale
+ Your missing company
+ Phone: Your missing phone
+ User: Your missing user
+ Shop: The missing shop


- - - -
- - + + + - +
+ + +

- + +
Total: - -
Tax:
Total: + +
+
+ + + + + +
+ + + +
+
+ From 64496f511eca0df6ed81f40663d2957e51efb6fd Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 15 Dec 2011 17:49:12 +0100 Subject: [PATCH 03/14] [imp] improved the marvelous ticket bzr revid: nicolas.vanhoren@openerp.com-20111215164912-cokw45ity9wm9b2s --- addons/point_of_sale/static/src/js/pos.js | 46 ++++++++++++++------- addons/point_of_sale/static/src/xml/pos.xml | 10 ++--- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 24daf465696..3f0303533c0 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -70,20 +70,27 @@ openerp.point_of_sale = function(db) { this.flush_mutex = new $.Mutex(); this.build_tree = _.bind(this.build_tree, this); this.session = session; - this.set({'pending_operations': this.store.get('pending_operations', [])}); - this.bind('change:pending_operations', _.bind(function(unused, val) { - this.store.set('pending_operations', val); - }, this)); - this.set({'currency': this.store.get('currency', {symbol: '$', position: 'after'})}); - this.bind('change:currency', _.bind(function(unused, val) { - this.store.set('currency', val); + var attributes = { + 'pending_operations': [], + 'currency': {symbol: '$', position: 'after'}, + 'shop': {}, + 'company': {}, + 'user': {}, + }; + _.each(attributes, _.bind(function(def, attr) { + var to_set = {}; + to_set[attr] = this.store.get(attr, def); + this.set(to_set); + this.bind('change:' + attr, _.bind(function(unused, val) { + this.store.set(attr, val); + }, this)); }, this)); $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'img'], [['pos_categ_id', '!=', 'false']]), this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'], [['state', '=', 'open']]), this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type']), - this.get_currency()) - .then(this.build_tree); + this.get_app_data()) + .pipe(_.bind(this.build_tree, this)); }, fetch: function(osvModel, fields, domain) { var dataSetSearch; @@ -93,19 +100,23 @@ openerp.point_of_sale = function(db) { return self.store.set(osvModel, result); }); }, - get_currency: function() { - return new db.web.Model("sale.shop").get_func("search_read")([]).pipe(function(result) { + get_app_data: function() { + var self = this; + return $.when(new db.web.Model("sale.shop").get_func("search_read")([]).pipe(function(result) { + self.set({'shop': result[0]}); var company_id = result[0]['company_id'][0]; - return new db.web.Model("res.company").get_func("read")(company_id, ['currency_id']).pipe(function(result) { + return new db.web.Model("res.company").get_func("read")(company_id, ['currency_id', 'name', 'phone']).pipe(function(result) { + self.set({'company': result}); var currency_id = result['currency_id'][0] return new db.web.Model("res.currency").get_func("read")([currency_id], ['symbol', 'position']).pipe(function(result) { - return result[0]; + self.set({'currency': result[0]}); + }); }); - }).then(_.bind(function(currency) { - this.set({'currency': currency}); - }, this)); + }), new db.web.Model("res.users").get_func("read")(this.session.uid, ['name']).pipe(function(result) { + self.set({'user': result}); + })); }, push: function(osvModel, record) { var ops = _.clone(this.get('pending_operations')); @@ -945,6 +956,9 @@ openerp.point_of_sale = function(db) { this._super(parent); this.model = options.model; this.shop = options.shop; + this.user = pos.get('user'); + this.company = pos.get('company'); + this.shop_obj = pos.get('shop'); }, start: function() { this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 2fe2f229fa4..781e847fe7e 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -228,14 +228,14 @@
- Your missing company
- Phone: Your missing phone
- User: Your missing user
- Shop: The missing shop
-

+
+ Phone:
+ User:
+ Shop:
+
Change:
From 7619349d9ac5526599a292e0de0e23e4f9a4771c Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 14:22:44 +0100 Subject: [PATCH 14/14] [fix] problem when changing amount of payment line bzr revid: nicolas.vanhoren@openerp.com-20111219132244-719sqadq7hb0t2sp --- addons/point_of_sale/static/src/js/pos.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index bb859ad816f..90a6b03f330 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -877,29 +877,32 @@ openerp.point_of_sale = function(db) { init: function(parent, options) { this._super(parent); this.model = options.model; - this.model.bind('change', this.render_element, this); - }, - start: function () { - this.$element.addClass('paymentline'); - $('input', this.$element).keyup(_.bind(this.changeAmount, this)); - $('.delete-payment-line', this.$element).click(this.on_delete); + this.model.bind('change', this.changedAmount, this); }, on_delete: function() {}, changeAmount: function(event) { var newAmount; newAmount = event.currentTarget.value; if (newAmount && !isNaN(newAmount)) { - return this.model.set({ - amount: parseFloat(newAmount) + this.amount = parseFloat(newAmount); + this.model.set({ + amount: this.amount, }); } }, + changedAmount: function() { + if (this.amount !== this.model.get('amount')) + this.render_element(); + }, render_element: function() { + this.amount = this.model.get('amount'); this.$element.html(this.template_fct({ name: (this.model.get('journal_id'))[1], - amount: this.model.get('amount') + amount: this.amount, })); - return this; + this.$element.addClass('paymentline'); + $('input', this.$element).keyup(_.bind(this.changeAmount, this)); + $('.delete-payment-line', this.$element).click(this.on_delete); }, }); var PaymentWidget = db.web.Widget.extend({
From fe721330c35785e22bb1307d4b61b8a80c8f9180 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 16 Dec 2011 13:44:19 +0100 Subject: [PATCH 04/14] [imp] added stuff bzr revid: nicolas.vanhoren@openerp.com-20111216124419-hviz2o5f0ujyl5bu --- addons/point_of_sale/static/src/js/pos.js | 3 ++- addons/point_of_sale/static/src/xml/pos.xml | 24 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 3f0303533c0..3146ba4af44 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -87,7 +87,8 @@ openerp.point_of_sale = function(db) { }, this)); $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'img'], [['pos_categ_id', '!=', 'false']]), - this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'], [['state', '=', 'open']]), + this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'], + [['state', '=', 'open'], ['user_id', '=', this.session.uid]]), this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type']), this.get_app_data()) .pipe(_.bind(this.build_tree, this)); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 781e847fe7e..aa47a38d3cb 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -97,17 +97,35 @@

Payment

- +
+ + + + + +
Total: + + + +
- + - +
Paid: + + + +
Change: + + + +
From a26df4085ce656a33bd35168cb2bb905646755b7 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 16 Dec 2011 14:47:38 +0100 Subject: [PATCH 05/14] [imp] refactored numpad state bzr revid: nicolas.vanhoren@openerp.com-20111216134738-ogaf88ua4looi93r --- addons/point_of_sale/static/src/js/pos.js | 42 ++++++++++------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 3146ba4af44..e48be7669a8 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -502,21 +502,16 @@ openerp.point_of_sale = function(db) { The numpad handles both the choice of the property currently being modified (quantity, price or discount) and the edition of the corresponding numeric value. */ - var NumpadState = (function() { - __extends(NumpadState, Backbone.Model); - function NumpadState() { - NumpadState.__super__.constructor.apply(this, arguments); - } - - NumpadState.prototype.defaults = { + var NumpadState = Backbone.Model.extend({ + defaults: { buffer: "0", mode: "quantity" - }; - NumpadState.prototype.initialize = function(options) { + }, + initialize: function(options) { this.shop = options.shop; return this.shop.bind('change:selectedOrder', this.reset, this); - }; - NumpadState.prototype.appendNewChar = function(newChar) { + }, + appendNewChar: function(newChar) { var oldBuffer; oldBuffer = this.get('buffer'); if (oldBuffer === '0') { @@ -533,8 +528,8 @@ openerp.point_of_sale = function(db) { }); } return this.updateTarget(); - }; - NumpadState.prototype.deleteLastChar = function() { + }, + deleteLastChar: function() { var tempNewBuffer; tempNewBuffer = (this.get('buffer')).slice(0, -1) || "0"; if (isNaN(tempNewBuffer)) { @@ -544,27 +539,27 @@ openerp.point_of_sale = function(db) { buffer: tempNewBuffer }); return this.updateTarget(); - }; - NumpadState.prototype.switchSign = function() { + }, + switchSign: function() { var oldBuffer; oldBuffer = this.get('buffer'); this.set({ buffer: oldBuffer[0] === '-' ? oldBuffer.substr(1) : "-" + oldBuffer }); return this.updateTarget(); - }; - NumpadState.prototype.changeMode = function(newMode) { + }, + changeMode: function(newMode) { return this.set({ buffer: "0", mode: newMode }); - }; - NumpadState.prototype.reset = function() { + }, + reset: function() { return this.set({ buffer: "0" }); - }; - NumpadState.prototype.updateTarget = function() { + }, + updateTarget: function() { var bufferContent, params; bufferContent = this.get('buffer'); if (bufferContent && !isNaN(bufferContent)) { @@ -572,9 +567,8 @@ openerp.point_of_sale = function(db) { params[this.get('mode')] = parseFloat(bufferContent); return (this.shop.get('selectedOrder')).selected.set(params); } - }; - return NumpadState; - })(); + }, + }); /* --- Views From 7fe71893651f1d7daa4b7209556357abd795cd8e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 16 Dec 2011 17:08:58 +0100 Subject: [PATCH 06/14] [imp] improved numpad bzr revid: nicolas.vanhoren@openerp.com-20111216160858-f9ruclwhdmebjoqc --- addons/point_of_sale/static/src/js/pos.js | 17 +++++++++++------ addons/point_of_sale/static/src/xml/pos.xml | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index e48be7669a8..3893e57bad9 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -556,7 +556,8 @@ openerp.point_of_sale = function(db) { }, reset: function() { return this.set({ - buffer: "0" + buffer: "0", + mode: "quantity" }); }, updateTarget: function() { @@ -580,6 +581,8 @@ openerp.point_of_sale = function(db) { this.state = options.state; }, 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)); @@ -597,12 +600,14 @@ openerp.point_of_sale = function(db) { return this.state.appendNewChar(newChar); }, clickChangeMode: function(event) { - var newMode; - $('.selected-mode').removeClass('selected-mode'); - $(event.currentTarget).addClass('selected-mode'); - newMode = event.currentTarget.attributes['data-mode'].nodeValue; + 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') diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index aa47a38d3cb..7879bf32c5e 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -66,7 +66,7 @@ - +
From f807f2d692fe1c8bdeba4a0af352dcb6e7cdfae4 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 16 Dec 2011 17:21:02 +0100 Subject: [PATCH 07/14] [fix] problem with numpad bzr revid: nicolas.vanhoren@openerp.com-20111216162102-q1ic92it7hegcrvt --- addons/point_of_sale/static/src/js/pos.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 3893e57bad9..de15377fe2a 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -509,7 +509,8 @@ openerp.point_of_sale = function(db) { }, initialize: function(options) { this.shop = options.shop; - return this.shop.bind('change:selectedOrder', this.reset, this); + this.shop.bind('change:selectedOrder', this.changedSelectedOrder, this); + this.changedSelectedOrder(); }, appendNewChar: function(newChar) { var oldBuffer; @@ -527,7 +528,7 @@ openerp.point_of_sale = function(db) { buffer: (this.get('buffer')) + newChar }); } - return this.updateTarget(); + this.updateTarget(); }, deleteLastChar: function() { var tempNewBuffer; @@ -538,7 +539,7 @@ openerp.point_of_sale = function(db) { this.set({ buffer: tempNewBuffer }); - return this.updateTarget(); + this.updateTarget(); }, switchSign: function() { var oldBuffer; @@ -546,16 +547,25 @@ openerp.point_of_sale = function(db) { this.set({ buffer: oldBuffer[0] === '-' ? oldBuffer.substr(1) : "-" + oldBuffer }); - return this.updateTarget(); + this.updateTarget(); }, changeMode: function(newMode) { - return this.set({ + this.set({ buffer: "0", mode: newMode }); }, + changedSelectedOrder: function() { + if (this.currentSaleOrder) { + this.currentSaleOrder.unbind(); + this.currentSaleOrder.get('orderLines').unbind(); + } + this.currentSaleOrder = this.shop.get('selectedOrder'); + this.currentSaleOrder.get('orderLines').bind('add', this.reset, this); + this.reset(); + }, reset: function() { - return this.set({ + this.set({ buffer: "0", mode: "quantity" }); From 454f74e398da52b7385417e57edea7c860ca53c4 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 11:27:13 +0100 Subject: [PATCH 08/14] [imp] refactored numpad state to be useful bzr revid: nicolas.vanhoren@openerp.com-20111219102713-13jrvfqtmxonom4p --- addons/point_of_sale/static/src/js/pos.js | 54 +++++++++++------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index de15377fe2a..a3dc97c8fd5 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -507,11 +507,6 @@ openerp.point_of_sale = function(db) { buffer: "0", mode: "quantity" }, - initialize: function(options) { - this.shop = options.shop; - this.shop.bind('change:selectedOrder', this.changedSelectedOrder, this); - this.changedSelectedOrder(); - }, appendNewChar: function(newChar) { var oldBuffer; oldBuffer = this.get('buffer'); @@ -555,15 +550,6 @@ openerp.point_of_sale = function(db) { mode: newMode }); }, - changedSelectedOrder: function() { - if (this.currentSaleOrder) { - this.currentSaleOrder.unbind(); - this.currentSaleOrder.get('orderLines').unbind(); - } - this.currentSaleOrder = this.shop.get('selectedOrder'); - this.currentSaleOrder.get('orderLines').bind('add', this.reset, this); - this.reset(); - }, reset: function() { this.set({ buffer: "0", @@ -574,9 +560,7 @@ openerp.point_of_sale = function(db) { var bufferContent, params; bufferContent = this.get('buffer'); if (bufferContent && !isNaN(bufferContent)) { - params = {}; - params[this.get('mode')] = parseFloat(bufferContent); - return (this.shop.get('selectedOrder')).selected.set(params); + this.trigger('setValue', parseFloat(bufferContent)); } }, }); @@ -709,14 +693,12 @@ openerp.point_of_sale = function(db) { return this.$element.remove(); }, this)); this.order = options.order; - this.numpadState = options.numpadState; }, start: function() { this.$element.click(_.bind(this.clickHandler, this)); }, clickHandler: function() { - this.numpadState.reset(); - return this.select(); + this.select(); }, render_element: function() { this.select(); @@ -727,17 +709,25 @@ openerp.point_of_sale = function(db) { select: function() { $('tr.selected').removeClass('selected'); this.$element.addClass('selected'); - return this.order.selected = this.model; + this.order.selected = this.model; + this.on_selected(); }, + on_selected: function() {}, }); var OrderWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.shop = options.shop; this.numpadState = options.numpadState; + this.numpadState.bind('setValue', this.setValue, this); this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); this.bindOrderLineEvents(); }, + setValue: function(val) { + var param = {}; + param[this.numpadState.get('mode')] = val; + this.shop.get('selectedOrder').selected.set(param); + }, changeSelectedOrder: function() { this.currentOrderLines.unbind(); this.bindOrderLineEvents(); @@ -751,20 +741,30 @@ openerp.point_of_sale = function(db) { addLine: function(newLine) { var line = new OrderlineWidget(null, { model: newLine, - order: this.shop.get('selectedOrder'), - numpadState: this.numpadState + order: this.shop.get('selectedOrder') }); + line.on_selected.add(_.bind(this.selectedLine, this)); + this.selectedLine(); line.appendTo(this.$element); this.updateSummary(); }, + selectedLine: function() { + var reset = false; + if (this.currentSelected !== this.shop.get('selectedOrder').selected) { + reset = true; + } + this.currentSelected = this.shop.get('selectedOrder').selected; + if (reset) + this.numpadState.reset(); + }, render_element: function() { this.$element.empty(); this.currentOrderLines.each(_.bind( function(orderLine) { var line = new OrderlineWidget(null, { model: orderLine, - order: this.shop.get('selectedOrder'), - numpadState: this.numpadState + order: this.shop.get('selectedOrder') }); + line.on_selected.add(_.bind(this.selectedLine, this)); line.appendTo(this.$element); }, this)); this.updateSummary(); @@ -1048,9 +1048,7 @@ openerp.point_of_sale = function(db) { (this.shop.get('orders')).bind('add', this.orderAdded, this); (this.shop.get('orders')).add(new Order); - this.numpadState = new NumpadState({ - shop: this.shop - }); + this.numpadState = new NumpadState({}); this.productListView = new ProductListWidget(null, { shop: this.shop }); From 24e2160a4b395bff83b6845584fc048d2f1b4801 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 12:00:27 +0100 Subject: [PATCH 09/14] [imp] more improvements to numpad state bzr revid: nicolas.vanhoren@openerp.com-20111219110027-vpm4otytft9gu3bg --- addons/point_of_sale/static/src/js/pos.js | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index a3dc97c8fd5..2d36c55cf34 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -572,7 +572,7 @@ openerp.point_of_sale = function(db) { var NumpadWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); - this.state = options.state; + this.state = new NumpadState(); }, start: function() { this.state.bind('change:mode', this.changedMode, this); @@ -718,11 +718,19 @@ openerp.point_of_sale = function(db) { init: function(parent, options) { this._super(parent); this.shop = options.shop; - this.numpadState = options.numpadState; - this.numpadState.bind('setValue', this.setValue, this); + this.setNumpadState(options.numpadState); this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); 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); + } + }, setValue: function(val) { var param = {}; param[this.numpadState.get('mode')] = val; @@ -754,7 +762,7 @@ openerp.point_of_sale = function(db) { reset = true; } this.currentSelected = this.shop.get('selectedOrder').selected; - if (reset) + if (reset && this.numpadState) this.numpadState.reset(); }, render_element: function() { @@ -1048,7 +1056,6 @@ openerp.point_of_sale = function(db) { (this.shop.get('orders')).bind('add', this.orderAdded, this); (this.shop.get('orders')).add(new Order); - this.numpadState = new NumpadState({}); this.productListView = new ProductListWidget(null, { shop: this.shop }); @@ -1061,9 +1068,12 @@ openerp.point_of_sale = function(db) { this.paypadView.$element = $('#paypad'); this.paypadView.render_element(); this.paypadView.start(); + this.numpadView = new NumpadWidget(null); + this.numpadView.$element = $('#numpad'); + this.numpadView.start(); this.orderView = new OrderWidget(null, { shop: this.shop, - numpadState: this.numpadState + numpadState: this.numpadView.state, }); this.orderView.$element = $('#current-order-content'); this.orderView.start(); @@ -1077,11 +1087,6 @@ openerp.point_of_sale = function(db) { shop: this.shop, }); this.receiptView.replace($('#receipt-screen')); - this.numpadView = new NumpadWidget(null, { - state: this.numpadState - }); - this.numpadView.$element = $('#numpad'); - this.numpadView.start(); this.stepsView = new StepsWidget(null, {shop: this.shop}); this.stepsView.$element = $('#steps'); this.stepsView.start(); From d46657ce267abaf903ca91f39f2948d309616534 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 12:21:45 +0100 Subject: [PATCH 10/14] [imp] more improvements to numpad bzr revid: nicolas.vanhoren@openerp.com-20111219112145-eoptwtwe3l4t8hwq --- addons/point_of_sale/static/src/js/pos.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 2d36c55cf34..ae3d09ec3db 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -729,6 +729,7 @@ openerp.point_of_sale = function(db) { this.numpadState = numpadState; if (this.numpadState) { this.numpadState.bind('setValue', this.setValue, this); + this.numpadState.reset(); } }, setValue: function(val) { @@ -1073,7 +1074,6 @@ openerp.point_of_sale = function(db) { this.numpadView.start(); this.orderView = new OrderWidget(null, { shop: this.shop, - numpadState: this.numpadView.state, }); this.orderView.$element = $('#current-order-content'); this.orderView.start(); @@ -1090,6 +1090,8 @@ openerp.point_of_sale = function(db) { this.stepsView = new StepsWidget(null, {shop: this.shop}); this.stepsView.$element = $('#steps'); this.stepsView.start(); + this.shop.bind('change:selectedOrder', this.changedSelectedOrder, this); + this.changedSelectedOrder(); }, createNewOrder: function() { var newOrder; @@ -1108,6 +1110,23 @@ openerp.point_of_sale = function(db) { newOrderButton.appendTo($('#orders')); newOrderButton.selectOrder(); }, + changedSelectedOrder: function() { + if (this.currentOrder) { + this.currentOrder.unbind('change:step', this.changedStep); + } + this.currentOrder = this.shop.get('selectedOrder'); + this.currentOrder.bind('change:step', this.changedStep, this); + this.changedStep(); + }, + changedStep: function() { + var step = this.currentOrder.get('step'); + this.orderView.setNumpadState(null); + if (step === 'products') { + this.orderView.setNumpadState(this.numpadView.state); + } else if (step === 'payment') { + //todo + } + }, }); var App = (function() { function App($element) { From 410bff7fb050c7f36a0ea0d39e73bf876d85e58c Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 13:24:19 +0100 Subject: [PATCH 11/14] [imp] binded numpad to payment view bzr revid: nicolas.vanhoren@openerp.com-20111219122419-sayukaurr0raygo1 --- addons/point_of_sale/static/src/js/pos.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index ae3d09ec3db..553d7a59715 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -969,6 +969,25 @@ openerp.point_of_sale = function(db) { remaining = remainingAmount > 0 ? 0 : (-remainingAmount).toFixed(2); $('#payment-remaining').html(remaining); }, + setNumpadState: function(numpadState) { + if (this.numpadState) { + this.numpadState.unbind('setValue', this.setValue); + this.numpadState.unbind('change:mode', this.setNumpadMode); + } + this.numpadState = numpadState; + if (this.numpadState) { + this.numpadState.bind('setValue', this.setValue, this); + this.numpadState.bind('change:mode', this.setNumpadMode, this); + this.numpadState.reset(); + this.setNumpadMode(); + } + }, + setNumpadMode: function() { + this.numpadState.set({mode: 'payment'}); + }, + setValue: function(val) { + this.currentPaymentLines.last().set({amount: val}); + }, }); var ReceiptWidget = db.web.Widget.extend({ init: function(parent, options) { @@ -1121,10 +1140,11 @@ openerp.point_of_sale = function(db) { changedStep: function() { var step = this.currentOrder.get('step'); this.orderView.setNumpadState(null); + this.paymentView.setNumpadState(null); if (step === 'products') { this.orderView.setNumpadState(this.numpadView.state); } else if (step === 'payment') { - //todo + this.paymentView.setNumpadState(this.numpadView.state); } }, }); From 8d2f66410043dcdd8b875efe51d9e91eadb7ed3e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 13:45:47 +0100 Subject: [PATCH 12/14] [imp] added print button bzr revid: nicolas.vanhoren@openerp.com-20111219124547-1vjs6oftrp3zv3ry --- addons/point_of_sale/static/src/css/pos.css | 4 ++++ addons/point_of_sale/static/src/js/pos.js | 1 + addons/point_of_sale/static/src/xml/pos.xml | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index 3d34ff8f795..4b2ecf5e991 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -484,6 +484,10 @@ background-color: #D92A2A; } +.receipt-buttons { + white-space: nowrap; +} + @media print { #oe_header, #oe_menu, .point-of-sale #topheader, .point-of-sale #leftpane { display: none; diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 553d7a59715..32924cee65a 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1005,6 +1005,7 @@ openerp.point_of_sale = function(db) { render_element: function() { this.$element.html(qweb_template('pos-receipt-view')); $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); + $('button#print-the-ticket', this.$element).click(function(){window.print();}); }, finishOrder: function() { this.shop.get('selectedOrder').destroy(); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 7879bf32c5e..424506f8bfb 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -240,7 +240,11 @@
- +
+ + +
From e9350239b0be0e3c3c83c443be99972ef56ffb8c Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 14:17:50 +0100 Subject: [PATCH 13/14] [imp] added delete payment line bzr revid: nicolas.vanhoren@openerp.com-20111219131750-ts70x8ng44grf63g --- addons/point_of_sale/static/src/css/pos.css | 2 +- addons/point_of_sale/static/src/js/pos.js | 12 ++++++++---- addons/point_of_sale/static/src/xml/pos.xml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index 4b2ecf5e991..56f0e446394 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -16,7 +16,7 @@ border-spacing: 0; border-collapse: collapse; } -.point-of-sale td { +.point-of-sale td { border: 1px solid #e9eaec; } .point-of-sale input { diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 32924cee65a..bb859ad816f 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -882,7 +882,9 @@ openerp.point_of_sale = function(db) { start: function () { this.$element.addClass('paymentline'); $('input', this.$element).keyup(_.bind(this.changeAmount, this)); + $('.delete-payment-line', this.$element).click(this.on_delete); }, + on_delete: function() {}, changeAmount: function(event) { var newAmount; newAmount = event.currentTarget.value; @@ -929,6 +931,7 @@ openerp.point_of_sale = function(db) { bindPaymentLineEvents: function() { this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); this.currentPaymentLines.bind('add', this.addPaymentLine, this); + this.currentPaymentLines.bind('remove', this.render_element, this); this.currentPaymentLines.bind('all', this.updatePaymentSummary, this); }, bindOrderLineEvents: function() { @@ -946,18 +949,19 @@ openerp.point_of_sale = function(db) { var x = new PaymentlineWidget(null, { model: newPaymentLine }); + x.on_delete.add(_.bind(this.deleteLine, this, x)); x.appendTo(this.paymentLineList()); }, render_element: function() { this.paymentLineList().empty(); this.currentPaymentLines.each(_.bind( function(paymentLine) { - var x = new PaymentlineWidget(null, { - model: paymentLine - }); - this.paymentLineList().append(x); + this.addPaymentLine(paymentLine); }, this)); this.updatePaymentSummary(); }, + deleteLine: function(lineWidget) { + this.currentPaymentLines.remove([lineWidget.model]); + }, updatePaymentSummary: function() { var currentOrder, dueTotal, paidTotal, remaining, remainingAmount; currentOrder = this.shop.get('selectedOrder'); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 424506f8bfb..c040855f4b9 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -222,6 +222,7 @@
+