diff --git a/pos_check_session_state/README.rst b/pos_check_session_state/README.rst new file mode 100644 index 00000000..9875df61 --- /dev/null +++ b/pos_check_session_state/README.rst @@ -0,0 +1,83 @@ +=================================== +Point Of Sale - Check Session State +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-grap%2Fgrap--odoo--incubator-lightgray.png?logo=github + :target: https://github.com/grap/grap-odoo-incubator/tree/8.0/pos_check_session_state + :alt: grap/grap-odoo-incubator + +|badge1| |badge2| |badge3| + +**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 minute by default. If the state of the + session is not opened, a blocking pop up is displayed, and user has to + reload the current page. + +.. figure:: https://raw.githubusercontent.com/grap/grap-odoo-incubator/8.0/pos_check_session_state/static/description/error_message.png + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +* Go to Point of Sale / Configuration / Point of Sales +* Open a PoS Config and set a frequency for the check + +.. figure:: https://raw.githubusercontent.com/grap/grap-odoo-incubator/8.0/pos_check_session_state/static/description/pos_config_form.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Sylvain LE GAL + +Maintainers +~~~~~~~~~~~ + + + +This module is part of the `grap/grap-odoo-incubator `_ project on GitHub. + + +You are welcome to contribute. diff --git a/pos_check_session_state/__init__.py b/pos_check_session_state/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_check_session_state/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_check_session_state/__manifest__.py b/pos_check_session_state/__manifest__.py new file mode 100644 index 00000000..b187f6c4 --- /dev/null +++ b/pos_check_session_state/__manifest__.py @@ -0,0 +1,28 @@ +# Copyright (C) 2015-Today GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Point Of Sale - Check Session State', + 'summary': 'Check if the session state is still opened', + 'version': '12.0.1.0.0', + 'category': 'Point Of Sale', + 'author': "GRAP", + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'views/templates.xml', + 'views/view_pos_config.xml', + ], + 'qweb': [ + 'static/src/xml/pos_check_session_state.xml', + ], + 'images': [ + 'static/description/error_message.png', + 'static/description/pos_config_form.png', + ], + 'installable': True, +} diff --git a/pos_check_session_state/i18n/fr.po b/pos_check_session_state/i18n/fr.po new file mode 100644 index 00000000..42581c2b --- /dev/null +++ b/pos_check_session_state/i18n/fr.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_check_session_state +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-07-03 12:10+0000\n" +"PO-Revision-Date: 2019-07-03 12:10+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 +#: model_terms:ir.ui.view,arch_db:pos_check_session_state.view_pos_config_form +msgid "Check Session State" +msgstr "Vérifier l'état de la session" + +#. module: pos_check_session_state +#: model:ir.model.fields,field_description:pos_check_session_state.field_pos_config__check_session_state_frequency +msgid "Frequency of Checking the State of the Session" +msgstr "Fréquence de vérification de l'état de la session" + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/xml/pos_check_session_state.xml:24 +#, 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 +#: model:ir.model,name:pos_check_session_state.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Paramétrage du point de vente" + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/xml/pos_check_session_state.xml:19 +#, python-format +msgid "The session you're working on is closed." +msgstr "La sessions sur laquelle vous travaillez est close." + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/xml/pos_check_session_state.xml:14 +#, python-format +msgid "The session you're working on is in closing control." +msgstr "La sessions sur laquelle vous travaillez est en contrôle de fermeture." + +#. module: pos_check_session_state +#: model:ir.model.fields,help:pos_check_session_state.field_pos_config__check_session_state_frequency +msgid "The value is set in seconds." +msgstr "La valeur est définie en seconde." + diff --git a/pos_check_session_state/models/__init__.py b/pos_check_session_state/models/__init__.py new file mode 100644 index 00000000..db8634ad --- /dev/null +++ b/pos_check_session_state/models/__init__.py @@ -0,0 +1 @@ +from . import pos_config diff --git a/pos_check_session_state/models/pos_config.py b/pos_check_session_state/models/pos_config.py new file mode 100644 index 00000000..447bfc31 --- /dev/null +++ b/pos_check_session_state/models/pos_config.py @@ -0,0 +1,13 @@ +# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + check_session_state_frequency = fields.Integer( + string="Frequency of Checking the State of the Session", + default=60, help="The value is set in seconds.") diff --git a/pos_check_session_state/readme/CONFIGURE.rst b/pos_check_session_state/readme/CONFIGURE.rst new file mode 100644 index 00000000..68817923 --- /dev/null +++ b/pos_check_session_state/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +* Go to Point of Sale / Configuration / Point of Sales +* Open a PoS Config and set a frequency for the check + +.. figure:: ../static/description/pos_config_form.png diff --git a/pos_check_session_state/readme/CONTRIBUTORS.rst b/pos_check_session_state/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9f76a75b --- /dev/null +++ b/pos_check_session_state/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/pos_check_session_state/readme/DESCRIPTION.rst b/pos_check_session_state/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c0266ca5 --- /dev/null +++ b/pos_check_session_state/readme/DESCRIPTION.rst @@ -0,0 +1,16 @@ +**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 minute by default. If the state of the + session is not opened, a blocking pop up is displayed, and user has to + reload the current page. + +.. figure:: ../static/description/error_message.png diff --git a/pos_check_session_state/static/description/error_message.png b/pos_check_session_state/static/description/error_message.png new file mode 100644 index 00000000..eeace3f9 Binary files /dev/null and b/pos_check_session_state/static/description/error_message.png differ diff --git a/pos_check_session_state/static/description/icon.png b/pos_check_session_state/static/description/icon.png new file mode 100644 index 00000000..a9e1244d Binary files /dev/null and b/pos_check_session_state/static/description/icon.png differ diff --git a/pos_check_session_state/static/description/pos_config_form.png b/pos_check_session_state/static/description/pos_config_form.png new file mode 100644 index 00000000..09684305 Binary files /dev/null and b/pos_check_session_state/static/description/pos_config_form.png differ 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 new file mode 100644 index 00000000..2baa4065 --- /dev/null +++ b/pos_check_session_state/static/src/js/pos_check_session_state.js @@ -0,0 +1,79 @@ +/* +Copyright (C) 2015-Today GRAP (http://www.grap.coop) +@author: Sylvain LE GAL (https://twitter.com/legalsylvain) +License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + +odoo.define('pos_check_session_state.pos_check_session_state', function (require){ + + "use strict"; + var PopupWidget = require('point_of_sale.popups'); + var gui = require('point_of_sale.gui'); + var chrome = require('point_of_sale.chrome'); + + var rpc = require('web.rpc'); + + /* + Overload build_widgets to add a check done every + check_session_state_frequency seconds, by a setInterval. + */ + chrome.Chrome.include({ + + build_widgets: function () { + var self = this; + var res = this._super.apply(this, arguments); + var frequency = self.pos.config.check_session_state_frequency * 1000; + + self.intervalIDCheckSessionState = setInterval(function() { + self._check_session_state(); + }, frequency); + return res; + }, + + _check_session_state: function() { + var self = this; + var params = { + model: 'pos.session', + method: 'search_read', + domain: [['id', '=', self.pos.pos_session.id]], + fields: ['state'], + }; + + rpc.query(params) + .then(function(sessions){ + if (sessions[0].state !== 'opened') { + // warn user if current session is not opened + self.gui.show_popup('error-closed-session', {session_state: sessions[0].state}); + clearInterval(self.intervalIDCheckSessionState); + } + }) + .fail(function(error, event){ + // Prevent error if server is unreachable + event.preventDefault(); + }); + } + }); + + /* + 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 done depending on a parameter on the PoS config + */ + var ErrorClosedSessionPopupWidget = PopupWidget.extend({ + template: 'ErrorClosedSessionPopupWidget', + + show: function(options){ + this._super(options); + this.gui.play_sound('error'); + }, + + }); + + gui.define_popup({name:'error-closed-session', widget: ErrorClosedSessionPopupWidget}); + + return { + ErrorClosedSessionPopupWidget: ErrorClosedSessionPopupWidget, + }; + +}); 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..3285ce36 --- /dev/null +++ b/pos_check_session_state/static/src/xml/pos_check_session_state.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/pos_check_session_state/views/templates.xml b/pos_check_session_state/views/templates.xml new file mode 100644 index 00000000..b8ee86a7 --- /dev/null +++ b/pos_check_session_state/views/templates.xml @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/pos_check_session_state/views/view_pos_config.xml b/pos_check_session_state/views/view_pos_config.xml new file mode 100644 index 00000000..f9277547 --- /dev/null +++ b/pos_check_session_state/views/view_pos_config.xml @@ -0,0 +1,22 @@ + + + + + + + pos.config + + + + + + + + + + +