Skip to content

Commit

Permalink
[IMP] optimization for pos_mobile, pos_multi_session modules: dramati…
Browse files Browse the repository at this point in the history
…cally improved performance (#608)

* [REF] refactoring and optimization rendering floors

* [IMP] asynchronous loading of data from the server
  • Loading branch information
Dinar authored and ilmir-k committed Feb 26, 2018
1 parent 552a6c2 commit 379d32b
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pos_mobile/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Point of Sale",
"live_test_url": "http://apps.it-projects.info/shop/product/pos-mobile-ui?version=10.0",
"images": ["images/pos_mobile.png"],
"version": "1.1.5",
"version": "10.0.1.1.5",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
Expand Down
2 changes: 1 addition & 1 deletion pos_mobile/static/lib/jquery.nicescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
cursoropacitymax: 1,
cursorcolor: "#424242",
cursorwidth: "6px",
cursorborder: "1px solid #fff",
cursorborder: "0px solid #424242",
cursorborderradius: "5px",
scrollspeed: 40,
mousescrollstep: 9 * 3,
Expand Down
2 changes: 1 addition & 1 deletion pos_mobile_restaurant/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Point of Sale",
"live_test_url": "http://apps.it-projects.info/shop/product/pos-mobile-ui?version=10.0",
"images": ["images/pos_mobile_restaurant.png"],
"version": "10.0.1.2.4",
"version": "10.0.1.2.5",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
Expand Down
5 changes: 5 additions & 0 deletions pos_mobile_restaurant/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
`1.2.5`
-------

- **IMP:** A floor screen rendering

`1.2.4`
-------

Expand Down
54 changes: 22 additions & 32 deletions pos_mobile_restaurant/static/src/js/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ odoo.define('pos_mobile_restaurant.chrome', function (require) {
chrome.Chrome.include({
// This method instantiates all the screens, widgets, etc.
build_widgets: function() {
this._super();
var self = this;
// floors swiper (you can to use the 'resistanceRatio': 1 parameter)
// read more about it http://idangero.us/swiper/api/#parameters
this.swiper_floors = new window.Swiper('.swiper-container-map', {
'resistanceRatio': 0
});

// Event will be fired after transition to another slide
this.swiper_floors.on('transitionEnd', function() {
self.change_current_floor();
});

this._super();

// floor screen swiper
this.swiper_floor_screen = new window.Swiper('.swiper-container-floor-screen', {
Expand All @@ -24,17 +35,6 @@ odoo.define('pos_mobile_restaurant.chrome', function (require) {
// remove all events for floor swiper
this.swiper_floor_screen.destroy(false , false);

// floors swiper (you can to use the 'resistanceRatio': 1 parameter)
// read more about it http://idangero.us/swiper/api/#parameters
this.swiper_floors = new window.Swiper('.swiper-container-map', {
'resistanceRatio': 0
});

// Event will be fired after transition to another slide
this.swiper_floors.on('transitionEnd', function() {
self.change_current_floor();
});

var floor_selector = $('.floor-screen .floor-selector');
if (floor_selector.length) {
floor_selector.detach();
Expand All @@ -44,7 +44,7 @@ odoo.define('pos_mobile_restaurant.chrome', function (require) {
// floors
if (this.pos.floors) {
_.each(this.pos.floors, function(floor, index){
self.rerender_floors(floor.id, index);
self.render_all_floors(floor.id, index);
});
}

Expand Down Expand Up @@ -98,44 +98,31 @@ odoo.define('pos_mobile_restaurant.chrome', function (require) {
this.menu_is_opened = true;
}
},
rerender_floors: function(id, index) {
render_all_floors: function(id, index) {
var floor_widget = this.gui.screen_instances.floors;
floor_widget.floor = this.pos.floors_by_id[id];
this.swiper_floors.appendSlide('<div class="swiper-slide slide-floor" id="slide-floor" data-id='+id+'></div>');
floor_widget.renderElement();
var floor_map = $('.floor-screen .floor-map');
floor_map.detach();
$($(".swiper-container-map .swiper-wrapper .slide-floor")[index]).append(floor_map);
this.rerender_floors_scrolling();
},
// set or change current order
change_current_floor: function(id) {
if (!this.pos.floors || !this.pos.floors.length) {
return false;
}

var self = this;

var active_floor = $('.slide-floor.swiper-slide-active');

var floor_id = id || active_floor.data('id');

this.gui.screen_instances.floors.floor = this.pos.floors_by_id[floor_id];
this.gui.screen_instances.floors.renderElement();

var floor_map = $('.floor-screen .floor-map');
if (floor_map.length) {
floor_map.detach();
$('.slide-floor.swiper-slide-active .floor-map').replaceWith(floor_map);
}
// replace floor selector
var floor_selector = $('.floor-screen .floor-selector');
if (floor_selector.length) {
floor_selector.detach();
$(".mobile-floor-selector .floor-selector").replaceWith(floor_selector);
}

this.rerender_floors_scrolling();

// event for menu button
this.menuButton = $('.menu-button');
this.menu_is_opened = false;
Expand All @@ -146,11 +133,14 @@ odoo.define('pos_mobile_restaurant.chrome', function (require) {

// close left menu
this.swiper_floor_screen.slideTo(1);
},
rerender_floors_scrolling: function(){

// set active selector
$('.mobile-floor-selector').find('.button-floor.active').removeClass('active');
$('.mobile-floor-selector').find('.button-floor[data-id=' + floor_id +']').addClass('active');
active_floor.find('.tables').getNiceScroll().doScrollPos(0, 0);

if (!this.pos.iOS) {
$('.floor-scroll').remove();
$('.tables').niceScroll({
active_floor.find('.tables').niceScroll({
horizrailenabled: false,
scrollCLass: 'floor-scroll',
});
Expand Down
35 changes: 35 additions & 0 deletions pos_mobile_restaurant/static/src/js/floors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ odoo.define('pos_mobile_restaurant.floors', function (require) {
var floor = this.pos.floors_by_id[id];
var slide = $('div[data-id='+id+'][id=slide-floor]').index();
this.chrome.swiper_floors.slideTo(slide);
},
save_current_floor_changes_data: function() {
var self = this;
if (this.get_current_data) {
var collection = this.get_current_data();
this.pos.saved_floors_data[this.floor.id] = JSON.stringify(collection);
}
},
compare_current_floor_data: function() {
if (this.get_current_data) {
var collection = this.get_current_data();
return this.pos.saved_floors_data[this.floor.id] === JSON.stringify(collection);
}
return false;
},
renderElement: function(){
if (this.compare_current_floor_data()) {
return false;
}
this._super();
var map = this.$el.find('.floor-map');
var slide = this.get_floor_slide_by_id(this.floor.id);
if (slide.length) {
// replace exist slide
slide.find('.floor-map').replaceWith(map);
} else {
// append new slide
this.chrome.swiper_floors.appendSlide('<div class="swiper-slide slide-floor" id="slide-floor" data-id='+this.floor.id+'></div>');
slide = this.get_floor_slide_by_id(this.floor.id);
slide.append(map);
}
this.save_current_floor_changes_data();
},
get_floor_slide_by_id: function(id) {
return $('.swiper-slide.slide-floor[data-id='+ id +']');
}
});

Expand Down
4 changes: 4 additions & 0 deletions pos_mobile_restaurant/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ odoo.define('pos_mobile_restaurant.models', function (require) {

var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
initialize: function (session, attributes) {
this.saved_floors_data = {};
return _super_posmodel.initialize.call(this, session, attributes);
},
set_table: function(table) {
this.table = table;
var orders = this.get_order_list();
Expand Down
2 changes: 1 addition & 1 deletion pos_multi_session/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Point Of Sale",
"live_test_url": 'http://apps.it-projects.info/shop/product/pos-multi-session?version=10.0',
"images": ["images/pos-multi-session.png"],
"version": "10.0.4.0.1",
"version": "10.0.4.0.2",
"application": False,

"author": "IT-Projects LLC, Ivan Yelizariev",
Expand Down
4 changes: 4 additions & 0 deletions pos_multi_session/doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Updates
=======

`4.0.2`
-------
- **IMP:** Dramatically improved performance

`4.0.1`
-------
- **IMP:** Refactoring the code to fix a slow POS synchronization
Expand Down
23 changes: 21 additions & 2 deletions pos_multi_session/static/src/js/pos_multi_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ odoo.define('pos_multi_session', function(require){
var Model = require('web.Model');
var PosBaseWidget = require('point_of_sale.BaseWidget');
var gui = require('point_of_sale.gui');
var framework = require('web.framework');


var _t = core._t;

Expand Down Expand Up @@ -690,11 +692,28 @@ odoo.define('pos_multi_session', function(require){
sync_all: function(data) {
var server_orders_uid = [];
var self = this;
data.orders.forEach(function (item) {
self.pos.ms_on_update(item, true);
function delay(ms) {
var d = $.Deferred();
setTimeout(function(){
d.resolve();
}, ms);
return d.promise();
}

framework.blockUI();
this.q = $.when();
data.orders.forEach(function (item, index) {
self.q = self.q.then(function(){
self.pos.ms_on_update(item, true);
return delay(100);
});
server_orders_uid.push(item.data.uid);
});

self.q.then(function() {
framework.unblockUI();
});

this.pos.pos_session.order_ID = data.order_ID;

if (data.order_ID !== 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,13 @@ odoo.define('pos_multi_session_restaurant', function(require){
multi_session.MultiSession = multi_session.MultiSession.extend({
sync_all: function(data) {
MultiSessionSuper.prototype.sync_all.apply(this, arguments);
if (this.pos.gui.screen_instances.floors && this.pos.gui.get_current_screen() === "floors") {
this.pos.gui.screen_instances.floors.renderElement();
}
var self = this;
this.q.then(function(){
if (self.pos.gui.screen_instances.floors && self.pos.gui.get_current_screen() === "floors") {
self.pos.gui.screen_instances.floors.renderElement();
}
});

}
});

Expand Down
9 changes: 4 additions & 5 deletions pos_order_cancel/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ odoo.define('pos_order_cancel.models', function (require) {
var self = this;
this.is_cancelled = true;
this.reason = reason;
this.orderlines.each(function(line){
self.save_canceled_line(line);
self.save_reason_cancelled_line(line, _t("Order Deleting") + "; " + reason, cancelled_reason_ids);
});
while (this.get_orderlines().length) {
self.remove_orderline(this.get_orderlines()[0]);
var line = this.get_orderlines()[0];
this.save_canceled_line(line);
this.save_reason_cancelled_line(line, _t("Order Deleting") + "; " + reason, cancelled_reason_ids);
this.remove_orderline(line);
}
this.upload_order_as_canceled();
},
Expand Down
2 changes: 1 addition & 1 deletion pos_restaurant_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Point of Sale",
# "live_test_URL": "",
"images": [],
"version": "1.0.0",
"version": "10.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
Expand Down
16 changes: 14 additions & 2 deletions pos_restaurant_base/static/lib/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,21 @@ odoo.define('pos_restaurant_base.models', function (require) {
}
},
print_order_receipt: function(printer, changes) {
var self = this;
function delay(ms) {
var d = $.Deferred();
setTimeout(function(){
d.resolve();
}, ms);
return d.promise();
}
var q = $.when();
if ( changes['new'].length > 0 || changes['cancelled'].length > 0){
var receipt = QWeb.render('OrderChangeReceipt',{changes:changes, widget:this});
printer.print(receipt);
q = q.then(function(){
var receipt = QWeb.render('OrderChangeReceipt',{changes:changes, widget:this});
printer.print(receipt);
return delay(100);
});
}
},
hasChangesToPrint: function(){
Expand Down

0 comments on commit 379d32b

Please sign in to comment.