Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/9.0' into 10.0-merge-9.0-multi…
Browse files Browse the repository at this point in the history
…-session
  • Loading branch information
Ivan Yelizariev committed Oct 24, 2017
2 parents e22763f + 5be4f4b commit 90f3b7d
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ language: python

python:
- "2.7"


#dist: trusty

sudo: false
cache: pip

Expand Down
16 changes: 6 additions & 10 deletions pos_debt_notebook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,11 @@ class PosConfig(models.Model):
_inherit = 'pos.config'

debt_dummy_product_id = fields.Many2one(
'product.product',
string='Dummy Product for Debt',
domain=[('available_in_pos', '=', True)],
'product.product', string='Dummy Product for Debt', domain=[('available_in_pos', '=', True)],
help="Dummy product used when a customer pays his debt "
"without ordering new products. This is a workaround to the fact "
"that Odoo needs to have at least one product on the order to "
"validate the transaction.")
"without ordering new products. This is a workaround to the fact "
"that Odoo needs to have at least one product on the order to "
"validate the transaction.")

def init_debt_journal(self):
journal_obj = self.env['account.journal']
Expand Down Expand Up @@ -251,18 +249,16 @@ def init_debt_journal(self):
'noupdate': True, # If it's False, target record (res_id) will be removed while module update
})

config = self
config.write({
self.write({
'journal_ids': [(4, debt_journal.id)],
'debt_dummy_product_id': self.env.ref('pos_debt_notebook.product_pay_debt').id,
})

statement = [(0, 0, {
'journal_id': debt_journal.id,
'user_id': user.id,
'company_id': user.company_id.id
})]
current_session = config.current_session_id
current_session = self.current_session_id
current_session.write({
'statement_ids': statement,
})
Expand Down
14 changes: 11 additions & 3 deletions pos_debt_notebook/static/src/js/pos.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ odoo.define('pos_debt_notebook.pos', function (require) {
}, 30);
}

var newPaymentline = new models.Paymentline({},{order: this, cashregister: cashregister, pos: this.pos});
var newPaymentline = new models.Paymentline({}, {
order: this,
cashregister: cashregister,
pos: this.pos
});
if (cashregister.journal.debt){
newPaymentline.set_amount(this.get_due_debt());
} else if (cashregister.journal.type !== 'cash' || this.pos.config.iface_precompute_cash){
Expand Down Expand Up @@ -301,12 +305,12 @@ odoo.define('pos_debt_notebook.pos', function (require) {

pay_full_debt: function(){
var order = this.pos.get_order();

var debtjournal = false;
_.each(this.pos.cashregisters, function(cashregister) {
if (cashregister.journal.debt) {
debtjournal = cashregister;
}

});

var paymentLines = order.get_paymentlines();
Expand All @@ -318,7 +322,11 @@ odoo.define('pos_debt_notebook.pos', function (require) {
});
}

var newDebtPaymentline = new models.Paymentline({},{order: order, cashregister: debtjournal, pos: this.pos});
var newDebtPaymentline = new models.Paymentline({},{
order: order,
cashregister: debtjournal,
pos: this.pos
});
newDebtPaymentline.set_amount(order.get_client().debt * -1);
order.paymentlines.add(newDebtPaymentline);
this.render_paymentlines();
Expand Down
37 changes: 37 additions & 0 deletions pos_longpolling/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
{
"name": """POS Longpolling""",
"summary": """Technical module implement instant updates in POS""",
"category": "Point of Sale",
"images": [],
"version": "1.1.1",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
"support": "apps@it-projects.info",
"website": "https://twitter.com/gabbasov_dinar",
"license": "GPL-3",
# "price": 0.00,
# "currency": "EUR",

"depends": [
"bus",
"point_of_sale",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
"views/pos_longpolling_template.xml",
"views/pos_longpolling_view.xml",
],
"qweb": [
"static/src/xml/pos_longpolling_connection.xml",
],
"demo": [],

"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,

"auto_install": False,
"installable": True,
}
2 changes: 1 addition & 1 deletion pos_longpolling/controllers/pos_longpolling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from odoo.addons.bus.controllers.main import BusController
except ImportError:
_logger.error('pos_multi_session inconsisten with odoo version')
_logger.error('pos_longpolling inconsisten with odoo version')
BusController = object


Expand Down
Binary file added pos_longpolling/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 19 additions & 16 deletions pos_longpolling/static/src/js/pos_longpolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ odoo.define('pos_longpolling', function(require){
var _t = core._t;

// prevent bus to be started by chat_manager.js
bus.bus.activated = true; // fake value to ignore start_polling call
// fake value to ignore start_polling call
bus.bus.activated = true;

var PosModelSuper = models.PosModel;
models.PosModel = models.PosModel.extend({
Expand Down Expand Up @@ -43,10 +44,11 @@ odoo.define('pos_longpolling', function(require){
this.longpolling_connection.send();
},
add_channel: function(channel_name, callback, thisArg) {
var current_callback = callback;
if (thisArg){
callback = _.bind(callback, thisArg);
current_callback = _.bind(callback, thisArg);
}
this.channels[channel_name] = callback;
this.channels[channel_name] = current_callback;
if (this.lonpolling_activated) {
this.init_channel(channel_name);
}
Expand Down Expand Up @@ -75,18 +77,18 @@ odoo.define('pos_longpolling', function(require){
},
on_notification_do: function (channel, message) {
var self = this;
if (_.isString(channel)) {
var channel = JSON.parse(channel);
if (_.isString(channel)){
var current_channel = JSON.parse(channel);
}
if(Array.isArray(channel) && (channel[1] in self.channels)){
if(Array.isArray(current_channel) && current_channel[1] in self.channels){
try{
self.longpolling_connection.network_is_on();
var callback = self.channels[channel[1]];
var callback = self.channels[current_channel[1]];
if (callback) {
if (self.debug){
console.log('POS LONGPOLLING', self.config.name, channel[1], JSON.stringify(message));
console.log('POS LONGPOLLING', self.config.name, current_channel[1], JSON.stringify(message));
}
callback(message);
return callback(message);
}
}catch(err){
this.chrome.gui.show_popup('error',{
Expand All @@ -102,7 +104,8 @@ odoo.define('pos_longpolling', function(require){
this.pos = pos;
this.timer = false;
this.status = false;
this.response_status = false; // Is the message "PONG" received from the server
// Is the message "PONG" received from the server
this.response_status = false;
},
network_is_on: function(message) {
if (message) {
Expand All @@ -116,7 +119,7 @@ odoo.define('pos_longpolling', function(require){
this.set_status(false);
},
set_status: function(status) {
if (this.status == status) {
if (this.status === status) {
return;
}
this.status = status;
Expand All @@ -134,18 +137,18 @@ odoo.define('pos_longpolling', function(require){
}
},
start_timer: function(time, type){
var time = Math.round(time * 3600.0);
var response_time = Math.round(time * 3600.0);
var self = this;
this.timer = setTimeout(function() {
if (type == "query") {
if (type === "query") {
self.send();
} else if (type == "response") {
} else if (type === "response") {
if (self.pos.debug){
console.log('POS LONGPOLLING start_timer error', self.pos.config.name);
}
self.network_is_off();
}
}, time * 1000);
}, response_time * 1000);
},
response_timer: function() {
this.stop_timer();
Expand All @@ -156,7 +159,7 @@ odoo.define('pos_longpolling', function(require){
this.response_status = false;
openerp.session.rpc("/pos_longpolling/update", {message: "PING", pos_id: self.pos.config.id}).then(function(){
/* If the value "response_status" is true, then the poll message came earlier
if the value is false you need to start the response timer*/
if the value is false you need to start the response timer*/
if (!self.response_status) {
self.response_timer();
}
Expand Down
1 change: 1 addition & 0 deletions pos_multi_session/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.png
39 changes: 39 additions & 0 deletions pos_multi_session/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
{
"name": """Sync POS orders across multiple sessions""",
"summary": """Use multiple POS for handling orders""",
"category": "Point Of Sale",
"images": ["images/pos-multi-session.png"],
"version": "3.0.2",
"application": False,

"author": "IT-Projects LLC, Ivan Yelizariev",
"support": "apps@it-projects.info",
"website": "https://yelizariev.github.io",
"license": "LGPL-3",
"price": 160.00,
"currency": "EUR",

"depends": [
"pos_disable_payment",
"pos_longpolling",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
"security/ir.model.access.csv",
"views/pos_multi_session_views.xml",
],
"qweb": [
"static/src/xml/pos_multi_session.xml",
],
"demo": [
"demo/demo.xml",
],

"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,

"auto_install": False,
"installable": True,
}
17 changes: 17 additions & 0 deletions pos_multi_session/doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ Updates
- NEW: Added connection status with server to POS interface
- NEW: Create new orders even if the connection with server temporarily has been lost

`3.0.2`
-------

- FIX: sequence number error after closing all sessions

`3.0.1`
-------

- FIX: Reference Error "Model is not defined" if a customer is created from Pos interface directly

`3.0.0`
-------

- FIX: Added a queue for request sending that allows to fix the syncronization error on slow or lost connection
- NEW: Added connection status with server to POS interface
- NEW: Create new orders even if the connection with server temporarily has been lost

`2.0.1`
-------

Expand Down
14 changes: 13 additions & 1 deletion pos_multi_session/external_tests/phantomtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Modified phantomtest.js from odoo ( https://github.com/odoo/odoo/blob/8.0/opener
[{"session": "session1",
"extra": "connection_on" | "connection_off" | "connection_slow"
"screenshot": screenshot_name,
"code": "console.log('ok')",
"ready": false, # wait before calling next command
"timeout": 60000, # code execution timeout
Expand All @@ -28,6 +29,11 @@ Modified phantomtest.js from odoo ( https://github.com/odoo/odoo/blob/8.0/opener
* to communicate between commands, variable ``share`` can be used. It's saved right after execution finish. It's not save in async code (e.g. inside setTimeout function)
* screenshot:
* make screenshot before execution of the code
* filename is SESSION-SCREENSHOT-NUM.png
*/

var system = require('system');
Expand Down Expand Up @@ -250,10 +256,16 @@ function PhantomTest() {
sname = command.session;
page = self.pages[sname];
extra = command.extra;
screenshot = command.screenshot;
code = command.code || 'true';
ready = command.ready || 'true';

console.log("PhantomTest.runCommands: executing: " + code);
if (screenshot){
console.log('Make screenshot', screenshot);
page.render(sname + '-' + screenshot + '-' + i + '.png');
}

console.log("PhantomTest.runCommands: executing as "+sname+ ": " + code);
(function(){
var commandNum = i;
timer = setTimeout(function () {
Expand Down
14 changes: 11 additions & 3 deletions pos_multi_session/external_tests/tests/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ window.mstest = {
$('.order-sequence').each(function(){
var order_num = $.trim($(this).html()).split("\n");
if (parseInt(order_num[2]) == order.order_num){
$(this).click();
if (!$(this).parent().hasClass('selected')){
// click only on inactive tab.
// Otherwise Customer Selection screen will be opened
$(this).click();
}
return false;
}
});
Expand Down Expand Up @@ -117,7 +121,11 @@ window.mstest = {
setTimeout(function(){
callback();
mstest.is_wait = false;
}, timeout || 1000);
}, timeout || 3000);
},
check_revision_error: function(){
warning_message = 'There is a conflict during synchronization, try your action again';
if ($('.modal .in').text() == warning_message)
console.log('error', warning_message);
},

};
Loading

0 comments on commit 90f3b7d

Please sign in to comment.