From 43db1a784d8c3ed3e077ad1e3365b7b6afd3e3e4 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Sat, 27 Jun 2015 14:51:38 +0200 Subject: [PATCH 1/4] [ADD] new module pos_check_session_state to avoid PoS users use closed sessions; --- pos_check_session_state/__init__.py | 21 ++++++ pos_check_session_state/__openerp__.py | 68 +++++++++++++++++ pos_check_session_state/i18n/fr.po | 31 ++++++++ .../static/src/img/icon.png | Bin 0 -> 4232 bytes .../static/src/js/pos_check_session_state.js | 69 ++++++++++++++++++ .../src/xml/pos_check_session_state.xml | 35 +++++++++ 6 files changed, 224 insertions(+) create mode 100644 pos_check_session_state/__init__.py create mode 100644 pos_check_session_state/__openerp__.py create mode 100644 pos_check_session_state/i18n/fr.po create mode 100644 pos_check_session_state/static/src/img/icon.png create mode 100644 pos_check_session_state/static/src/js/pos_check_session_state.js create mode 100644 pos_check_session_state/static/src/xml/pos_check_session_state.xml diff --git a/pos_check_session_state/__init__.py b/pos_check_session_state/__init__.py new file mode 100644 index 00000000..743db2e9 --- /dev/null +++ b/pos_check_session_state/__init__.py @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Point Of Sale - Check Session State module for OpenERP +# Copyright (C) 2015 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/pos_check_session_state/__openerp__.py b/pos_check_session_state/__openerp__.py new file mode 100644 index 00000000..01fdee37 --- /dev/null +++ b/pos_check_session_state/__openerp__.py @@ -0,0 +1,68 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Point Of Sale - Check Session State module for OpenERP +# Copyright (C) 2015 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Point Of Sale - Check Session State', + 'summary': 'Check if the session state is still opened', + 'version': '0.1', + 'category': 'Point Of Sale', + 'description': """ +Check if the session state is still opened +========================================== + +Context: +-------- +In Point Of Sale module, the front-end works offline, so all datas are +loaded at the beginning. +At the end of the session, if user do not close the window, it will be +possible to create new pos order on a closed session, generating errors. + +Functionality: +-------------- + * This module prevent the possility to create a pos order via the front + end PoS UI, when session is closed. + * The session state is checked every 10 seconds. If the state of the + session is not opened, a blocking pop up is displayed, and user has to + reload the current page. + +Copyright, Authors and Licence: +------------------------------- + * Copyright: 2015, GRAP: Groupement Régional Alimentaire de Proximité; + * Author: + * Sylvain LE GAL (https://twitter.com/legalsylvain); + * Licence: AGPL-3 (http://www.gnu.org/licenses/);""", + 'author': "GRAP,Odoo Community Association (OCA)", + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'qweb': [ + 'static/src/xml/pos_check_session_state.xml', + ], + 'js': [ + 'static/src/js/pos_check_session_state.js', + ], + 'css': [ + 'static/src/css/pos_check_session_state.css', + ], +} diff --git a/pos_check_session_state/i18n/fr.po b/pos_check_session_state/i18n/fr.po new file mode 100644 index 00000000..f55a6f39 --- /dev/null +++ b/pos_check_session_state/i18n/fr.po @@ -0,0 +1,31 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * pos_check_session_state +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-27 12:47+0000\n" +"PO-Revision-Date: 2015-06-27 12:47+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/xml/pos_check_session_state.xml:29 +#, python-format +msgid "Please close the current Point Of Sale Window and open it again to use a correct session." +msgstr "Veuillez fermer la fenêtre courante du point de vente et en ouvrir une autre, afin d'utiliser une session correcte." + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/xml/pos_check_session_state.xml:28 +#, python-format +msgid "Sorry, the session you're working on is now closing or closed." +msgstr "Désolé, la session sur laquelle vous travaillez est désormais en cours de clôture, ou clôturée." + diff --git a/pos_check_session_state/static/src/img/icon.png b/pos_check_session_state/static/src/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a9e1244dae8e6ba3a6375b61161f431e07413158 GIT binary patch literal 4232 zcmV;35O?p1P)05UKzIV~_b zEip4xF*G_dI65^lD=;!TFfd#ppnFgYzSIV~|W zR53Ie~AYeS1mV%*ULcyY{SWGHDhaG^)R0bVc zH4@CLVRSi|OlKsg>F9<*(a^D~DrQARQNR#kHk(5M%&J0BGgi%yyQ+YhOjeS`B6&?m zRTQkMf>~8j6a@uPP*84qq~81wAgAf5szPWLRB%@mFdR=xM$?!|XECdbGB@9hR5Juc z5wxPl;J^ThM1t+x?#FC0Es~-rm{f(FzB(#cH3G&K5)#Yi$r(DaY!0j0gw3R)uqg3@ z2&$r>YZ_ytqv*QMv(N6r?sO6kH&9g>L=;d&Pyi8OGL@F9Qs;`QKwU{=6S26Q9T}73 zR|aKpcAlKBVYisEnN1*2&E}>*sT^6ML`om({x0Hcr3>F zjT;PJ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0000. +******************************************************************************/ + +openerp.pos_check_session_state = function (instance) { + module = instance.point_of_sale; + + /* + Define : New ErrorClosedSessionPopupWidget Widget. + This pop up will be shown if the current pos.session of the PoS is not + in an 'open' state; + The check will be down each 10 seconds; + */ + module.ErrorClosedSessionPopupWidget = module.ErrorPopupWidget.extend({ + template:'ErrorClosedSessionPopupWidget', + + check_session_frequency: 2000, + session_name: '', + + init: function(parent, options) { + var self = this; + this._super(parent,options); + this.intervalID = setInterval(function() { + var loaded = self.pos.fetch('pos.session', ['name','state'], [['id', '=', self.pos.get('pos_session').id]]) + .then(function(sessions){ +// if (sessions[0]['state'] != 'opened') { + if (true){ + self.session_name = sessions[0]['name']; + self.renderElement(); + self.pos_widget.screen_selector.show_popup('error-closed-session'); + clearInterval(self.intervalID); + } + }) + }, this.check_session_frequency); + }, + }); + + /* + Overload : PosWidget to include ErrorClosedSessionPopupWidget inside. + */ + module.PosWidget = module.PosWidget.extend({ + build_widgets: function(){ + this._super(); + this.error_closed_session_popup = new module.ErrorClosedSessionPopupWidget(this, {}); + this.error_closed_session_popup.appendTo($('.point-of-sale')); + this.screen_selector.popup_set['error-closed-session'] = this.error_closed_session_popup; + + // Hide the popup because all pop up are displayed at the + // beginning by default + this.error_closed_session_popup.hide(); + }, + }); + +}; diff --git a/pos_check_session_state/static/src/xml/pos_check_session_state.xml b/pos_check_session_state/static/src/xml/pos_check_session_state.xml new file mode 100644 index 00000000..f784531c --- /dev/null +++ b/pos_check_session_state/static/src/xml/pos_check_session_state.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 0e08df7f62de478ee70c00a677b4e1fdaddbf6b0 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Sat, 27 Jun 2015 14:54:49 +0200 Subject: [PATCH 2/4] [FIX] remove test values; --- .../static/src/js/pos_check_session_state.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pos_check_session_state/static/src/js/pos_check_session_state.js b/pos_check_session_state/static/src/js/pos_check_session_state.js index ff6fe8a2..19c18ba4 100644 --- a/pos_check_session_state/static/src/js/pos_check_session_state.js +++ b/pos_check_session_state/static/src/js/pos_check_session_state.js @@ -29,7 +29,7 @@ openerp.pos_check_session_state = function (instance) { module.ErrorClosedSessionPopupWidget = module.ErrorPopupWidget.extend({ template:'ErrorClosedSessionPopupWidget', - check_session_frequency: 2000, + check_session_frequency: 10000, session_name: '', init: function(parent, options) { @@ -38,8 +38,7 @@ openerp.pos_check_session_state = function (instance) { this.intervalID = setInterval(function() { var loaded = self.pos.fetch('pos.session', ['name','state'], [['id', '=', self.pos.get('pos_session').id]]) .then(function(sessions){ -// if (sessions[0]['state'] != 'opened') { - if (true){ + if (sessions[0]['state'] != 'opened') { self.session_name = sessions[0]['name']; self.renderElement(); self.pos_widget.screen_selector.show_popup('error-closed-session'); From 32fe4dc5175279bbd948a8946fdb3e9185602fff Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 15 Sep 2015 21:43:50 +0200 Subject: [PATCH 3/4] [IMP] make silent error if server is down, because PoS should work offline; --- .../static/src/js/pos_check_session_state.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pos_check_session_state/static/src/js/pos_check_session_state.js b/pos_check_session_state/static/src/js/pos_check_session_state.js index 19c18ba4..c484438f 100644 --- a/pos_check_session_state/static/src/js/pos_check_session_state.js +++ b/pos_check_session_state/static/src/js/pos_check_session_state.js @@ -39,12 +39,17 @@ openerp.pos_check_session_state = function (instance) { var loaded = self.pos.fetch('pos.session', ['name','state'], [['id', '=', self.pos.get('pos_session').id]]) .then(function(sessions){ if (sessions[0]['state'] != 'opened') { + // warn user if current session is not opened self.session_name = sessions[0]['name']; self.renderElement(); self.pos_widget.screen_selector.show_popup('error-closed-session'); clearInterval(self.intervalID); } }) + .fail(function(error, event){ + // Prevent error if server is unreachable + event.preventDefault(); + }); }, this.check_session_frequency); }, }); From 56b5401fb6a584e4214eb1eabf459915e2864e72 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 15 Sep 2015 21:44:12 +0200 Subject: [PATCH 4/4] [REF] change frequency of the check from 10 sec to 60 sec; --- .../static/src/js/pos_check_session_state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pos_check_session_state/static/src/js/pos_check_session_state.js b/pos_check_session_state/static/src/js/pos_check_session_state.js index c484438f..84031031 100644 --- a/pos_check_session_state/static/src/js/pos_check_session_state.js +++ b/pos_check_session_state/static/src/js/pos_check_session_state.js @@ -24,12 +24,12 @@ openerp.pos_check_session_state = function (instance) { Define : New ErrorClosedSessionPopupWidget Widget. This pop up will be shown if the current pos.session of the PoS is not in an 'open' state; - The check will be down each 10 seconds; + The check will be down each 60 seconds; */ module.ErrorClosedSessionPopupWidget = module.ErrorPopupWidget.extend({ template:'ErrorClosedSessionPopupWidget', - check_session_frequency: 10000, + check_session_frequency: 60000, session_name: '', init: function(parent, options) {