From dcdee5b4293e44d2d77690cdadb5b669af2bc9ec Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 7 Dec 2011 11:01:21 +0100 Subject: [PATCH 01/23] [fix] search problem bzr revid: nicolas.vanhoren@openerp.com-20111207100121-xsybjs8bw2p66c48 --- addons/point_of_sale/static/src/js/pos.js | 2 +- 1 file changed, 1 insertion(+), 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 05adcaf458a..14019eee62a 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1103,7 +1103,7 @@ openerp.point_of_sale = function(db) { s = $(this).val().toLowerCase(); if (s) { m = products.filter( function(p) { - return p.name.toLowerCase().indexOf(s); + return p.name.toLowerCase().indexOf(s) != -1; }); $('.search-clear').fadeIn(); } else { From e6252ff604ff53ba4e1dc3e1356a1d66303b5734 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 9 Dec 2011 14:47:37 +0100 Subject: [PATCH 02/23] [imp] refactored Pos bzr revid: nicolas.vanhoren@openerp.com-20111209134737-um3fo7qwcwb9wdpo --- addons/point_of_sale/static/src/js/pos.js | 36 +++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 14019eee62a..dc484ad5690 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -49,8 +49,8 @@ openerp.point_of_sale = function(db) { /* Gets all the necessary data from the OpenERP web client (session, shop data etc.) */ - var Pos = (function() { - function Pos(session) { + var Pos = db.web.Class.extend({ + init: function(session) { this.build_tree = _.bind(this.build_tree, this); this.session = session; $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), @@ -58,11 +58,10 @@ openerp.point_of_sale = function(db) { this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name']), this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type'])) .then(this.build_tree); - } - - Pos.prototype.ready = $.Deferred(); - Pos.prototype.store = new Store; - Pos.prototype.fetch = function(osvModel, fields, domain) { + }, + ready: $.Deferred(), + store: new Store, + fetch: function(osvModel, fields, domain) { var dataSetSearch; var self = this; var callback = function(result) { @@ -70,14 +69,14 @@ openerp.point_of_sale = function(db) { }; dataSetSearch = new db.web.DataSetSearch(this, osvModel, {}, domain); return dataSetSearch.read_slice(fields, 0).then(callback); - }; - Pos.prototype.push = function(osvModel, record, callback, errorCallback) { + }, + push: function(osvModel, record, callback, errorCallback) { var dataSet; dataSet = new db.web.DataSet(this, osvModel, null); return dataSet.create(record, callback, errorCallback); - }; - Pos.prototype.categories = {}; - Pos.prototype.build_tree = function() { + }, + categories: {}, + build_tree: function() { var c, id, _i, _len, _ref, _ref2; _ref = this.store.get('pos.category'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -124,14 +123,14 @@ openerp.point_of_sale = function(db) { }).call(this) }; return this.ready.resolve(); - }; - Pos.prototype.build_ancestors = function(parent) { + }, + build_ancestors: function(parent) { if (parent != null) { this.current_category.ancestors.unshift(parent); return this.build_ancestors(this.categories[parent].parent); } - }; - Pos.prototype.build_subtree = function(category) { + }, + build_subtree: function(category) { var c, _i, _len, _ref, _results; _ref = category.children; _results = []; @@ -141,9 +140,8 @@ openerp.point_of_sale = function(db) { _results.push(this.build_subtree(this.categories[c])); } return _results; - }; - return Pos; - })(); + } + }); /* global variable */ var pos; From e7d3b6133918483c52910def38295f47f751280d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 9 Dec 2011 15:22:11 +0100 Subject: [PATCH 03/23] [imp] improved storage bzr revid: nicolas.vanhoren@openerp.com-20111209142211-dgt8s2exjr8pj7ai --- addons/point_of_sale/static/src/js/pos.js | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index dc484ad5690..4af1d8d524b 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -30,22 +30,21 @@ openerp.point_of_sale = function(db) { Local store access. Read once from localStorage upon construction and persist on every change. There should only be one store active at any given time to ensure data consistency. */ - var Store = (function() { - function Store() { - var store; - store = localStorage['pos']; - this.data = (store && JSON.parse(store)) || {}; - } - - Store.prototype.get = function(key) { + var Store = db.web.Class.extend({ + init: function() { + this.data = {}; + }, + get: function(key) { + if (this.data[key] === undefined) { + this.data[key] = JSON.parse(localStorage['oe_pos_' + key]); + } return this.data[key]; - }; - Store.prototype.set = function(key, value) { + }, + set: function(key, value) { this.data[key] = value; - return localStorage['pos'] = JSON.stringify(this.data); - }; - return Store; - })(); + localStorage['oe_pos_' + key] = JSON.stringify(value); + }, + }); /* Gets all the necessary data from the OpenERP web client (session, shop data etc.) */ @@ -60,7 +59,7 @@ openerp.point_of_sale = function(db) { .then(this.build_tree); }, ready: $.Deferred(), - store: new Store, + store: new Store(), fetch: function(osvModel, fields, domain) { var dataSetSearch; var self = this; From e903fc7761146e93e53ac9bfdde909ceeab9389c Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 12 Dec 2011 17:00:01 +0100 Subject: [PATCH 04/23] [imp] added disconnected feature bzr revid: nicolas.vanhoren@openerp.com-20111212160001-vglc3zqz10hlter5 --- addons/point_of_sale/static/src/js/pos.js | 76 ++++++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 4af1d8d524b..39408d1122b 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -34,9 +34,13 @@ openerp.point_of_sale = function(db) { init: function() { this.data = {}; }, - get: function(key) { + get: function(key, _default) { if (this.data[key] === undefined) { - this.data[key] = JSON.parse(localStorage['oe_pos_' + key]); + var stored = localStorage['oe_pos_' + key]; + if (stored) + this.data[key] = JSON.parse(stored); + else + return _default; } return this.data[key]; }, @@ -48,8 +52,12 @@ openerp.point_of_sale = function(db) { /* Gets all the necessary data from the OpenERP web client (session, shop data etc.) */ - var Pos = db.web.Class.extend({ - init: function(session) { + var Pos = Backbone.Model.extend({ + initialize: function(session, attributes) { + Backbone.Model.prototype.initialize.call(this, attributes); + this.store = new Store(); + this.ready = $.Deferred(); + this.flush_mutex = new $.Mutex(); this.build_tree = _.bind(this.build_tree, this); this.session = session; $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), @@ -58,21 +66,56 @@ openerp.point_of_sale = function(db) { this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type'])) .then(this.build_tree); }, - ready: $.Deferred(), - store: new Store(), + get: function(attribute) { + if (attribute === 'pending_operations') { + return this.store.get('pending_operations', []); + } + return Backbone.Model.prototype.get.call(this, attribute); + }, + set: function(attributes, options) { + _.each(attributes, _.bind(function (value, attribute) { + if (attribute === 'pending_operations') { + this.store.set('pending_operations', value); + } + }, this)); + return Backbone.Model.prototype.set.call(this, attributes, options); + }, fetch: function(osvModel, fields, domain) { var dataSetSearch; var self = this; - var callback = function(result) { - return self.store.set(osvModel, result); - }; dataSetSearch = new db.web.DataSetSearch(this, osvModel, {}, domain); - return dataSetSearch.read_slice(fields, 0).then(callback); + return dataSetSearch.read_slice(fields, 0).then(function(result) { + return self.store.set(osvModel, result); + }); }, - push: function(osvModel, record, callback, errorCallback) { - var dataSet; - dataSet = new db.web.DataSet(this, osvModel, null); - return dataSet.create(record, callback, errorCallback); + push: function(osvModel, record) { + var ops = this.get('pending_operations'); + ops.push({model: osvModel, record: record}); + this.set({pending_operations: ops}); + return this.flush(); + }, + flush: function() { + return this.flush_mutex.exec(_.bind(function() { + return this._int_flush(); + }, this)); + }, + _int_flush : function() { + var ops = this.get('pending_operations'); + if (ops.length === 0) + return $.when(); + var op = ops[0]; + var dataSet = new db.web.DataSet(this, op.model, null); + /* we prevent the default error handler and assume errors + * are a normal use case, except we stop the current iteration + */ + return dataSet.create(op.record).fail(function(unused, event) { + event.preventDefault(); + }).pipe(_.bind(function() { + console.debug('saved 1 record'); + var ops2 = this.get('pending_operations'); + this.set({'pending_operations': _.without(ops2, op)}); + return this._int_flush(); + }, this), function() {return $.when()}); }, categories: {}, build_tree: function() { @@ -828,12 +871,11 @@ openerp.point_of_sale = function(db) { validateCurrentOrder: function() { var callback, currentOrder; currentOrder = this.shop.get('selectedOrder'); - callback = _.bind(function() { + pos.push('pos.order', currentOrder.exportAsJSON()).then(_.bind(function() { return currentOrder.set({ validated: true }); - }, this); - pos.push('pos.order', currentOrder.exportAsJSON(), callback); + }, this)); }, bindPaymentLineEvents: function() { this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); From ff182cf4885331864f5046ba8e216257c2fba8b4 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 12 Dec 2011 17:05:58 +0100 Subject: [PATCH 05/23] [imp] disables the payment button during asynch events bzr revid: nicolas.vanhoren@openerp.com-20111212160558-4mm45tdsiao08fqf --- addons/point_of_sale/static/src/js/pos.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 39408d1122b..5022601063e 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -871,7 +871,9 @@ openerp.point_of_sale = function(db) { validateCurrentOrder: function() { var callback, currentOrder; currentOrder = this.shop.get('selectedOrder'); + $('button#validate-order', this.$element).attr('disabled', 'disabled'); pos.push('pos.order', currentOrder.exportAsJSON()).then(_.bind(function() { + $('button#validate-order', this.$element).removeAttr('disabled'); return currentOrder.set({ validated: true }); From 6bbc8b1e31acc4a64b6fe27b51d3dfd2a9556b57 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 12 Dec 2011 17:12:18 +0100 Subject: [PATCH 06/23] [imp] renammed "Back" into "Close" bzr revid: nicolas.vanhoren@openerp.com-20111212161218-9dfsm336yg25qsxw --- addons/point_of_sale/static/src/xml/pos.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 74ff2229729..d8647aaccc9 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -25,7 +25,7 @@
- +
From b9224210c3d509e69120315e2354c314721bfa26 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 12 Dec 2011 17:42:12 +0100 Subject: [PATCH 07/23] [imp] added startup code for synchronisation icon bzr revid: nicolas.vanhoren@openerp.com-20111212164212-3jsfl1fltk6blq93 --- addons/point_of_sale/static/src/js/pos.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 5022601063e..79cba643647 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1167,14 +1167,18 @@ openerp.point_of_sale = function(db) { template: "PointOfSale", start: function() { var self = this; - this.$element.find("#loggedas button").click(function() { - self.stop(); - }); if (pos) throw "It is not possible to instantiate multiple instances "+ "of the point of sale at the same time."; pos = new Pos(this.session); + + pos.bind('change:pending_operations', this.changed_pending_operations, this); + this.changed_pending_operations(); + + this.$element.find("#loggedas button").click(function() { + self.try_close(); + }); this.$element.find('#steps').buttonset(); @@ -1185,6 +1189,17 @@ openerp.point_of_sale = function(db) { pos.app = new App(self.$element); }); }, + changed_pending_operations: function () { + var operations = pos.get('pending_operations'); + var number = operations.length; + + }, + try_close: function() { + this.close(); + }, + close: function() { + this.stop(); + }, stop: function() { $('.oe_footer').show(); $('.oe_toggle_secondary_menu').show(); From 0941028b447165accf5c59a1a0bf3e4d305af138 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 13 Dec 2011 14:45:34 +0100 Subject: [PATCH 08/23] [imp] added notifications when there is pending operations bzr revid: nicolas.vanhoren@openerp.com-20111213134534-xiyd0h096pei1k70 --- addons/point_of_sale/static/src/css/pos.css | 9 ++++++++ addons/point_of_sale/static/src/js/pos.js | 23 ++++++++++++++++++++- addons/point_of_sale/static/src/xml/pos.xml | 8 +++++++ 3 files changed, 39 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 24eb704b7dc..2ff5fbf9dd3 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -478,3 +478,12 @@ .point-of-sale .pos-receipt-container { font-size: 0.75em; } + +.point-of-sale .oe_pos_synch-notification-button { + color: white; + border: 1px solid black; + border-radius: 3px; + padding: 2px 3px 2px 3px; + background-color: #D92A2A; +} + diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 79cba643647..423399b9c07 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1161,6 +1161,23 @@ openerp.point_of_sale = function(db) { }; return App; })(); + + db.point_of_sale.SynchNotification = db.web.Widget.extend({ + template: "pos-synch-notification", + init: function() { + this._super.apply(this, arguments); + this.nbr_pending = 0; + }, + render_element: 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.render_element(); + }, + on_synch: function() {} + }); db.web.client_actions.add('pos.ui', 'db.point_of_sale.PointOfSale'); db.point_of_sale.PointOfSale = db.web.Widget.extend({ @@ -1173,6 +1190,10 @@ openerp.point_of_sale = function(db) { "of the point of sale at the same time."; pos = new Pos(this.session); + this.synch_notification = new db.point_of_sale.SynchNotification(this); + this.synch_notification.replace($('.oe_pos_synch-notification', this.$element)); + this.synch_notification.on_synch.add(_.bind(pos.flush, pos)); + pos.bind('change:pending_operations', this.changed_pending_operations, this); this.changed_pending_operations(); @@ -1192,7 +1213,7 @@ openerp.point_of_sale = function(db) { changed_pending_operations: function () { var operations = pos.get('pending_operations'); var number = operations.length; - + this.synch_notification.on_change_nbr_pending(number); }, try_close: function() { this.close(); diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index d8647aaccc9..61a5af2a17b 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -25,6 +25,7 @@
+
@@ -122,6 +123,13 @@ + + + + pending orders + + +