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..2a8f4c2c --- /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, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/pos', + '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..c97c4cbc --- /dev/null +++ b/pos_check_session_state/i18n/fr.po @@ -0,0 +1,61 @@ +# 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: 2020-03-09 20:22+0000\n" +"PO-Revision-Date: 2020-03-09 20:22+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: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/js/chrome.js:45 +#, python-format +msgid "This PoS window will be closed and you'll have to open a new session." +msgstr "Cette fenêtre de point de vente sera fermée et vous devrez ouvrir une nouvelle sessions." + +#. 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/js/chrome.js:44 +#, python-format +msgid "Session not opened : " +msgstr "Session non ouverte : " + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/js/chrome.js:49 +#, python-format +msgid "The session you're working on is closed : " +msgstr "La sessions sur laquelle vous travaillez est fermée : " + +#. module: pos_check_session_state +#. openerp-web +#: code:addons/pos_check_session_state/static/src/js/chrome.js:47 +#, python-format +msgid "The session you're working on is in closing control : " +msgstr "La session 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 +#: model_terms:ir.ui.view,arch_db:pos_check_session_state.view_pos_config_form +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..7d341968 --- /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 odoo 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..44def5e4 --- /dev/null +++ b/pos_check_session_state/readme/DESCRIPTION.rst @@ -0,0 +1,17 @@ +**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 doesn't 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 +open a new session. + +.. 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..22467cd8 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..c71ca079 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/chrome.js b/pos_check_session_state/static/src/js/chrome.js new file mode 100644 index 00000000..3c66a24a --- /dev/null +++ b/pos_check_session_state/static/src/js/chrome.js @@ -0,0 +1,69 @@ +/* +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.chrome', function (require){ + + "use strict"; + var rpc = require('web.rpc'); + var core = require('web.core'); + var chrome = require('point_of_sale.chrome'); + var _t = core._t; + + /* + 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') { + var title = _t("Session not opened : ") + self.pos.pos_session.name; + var body = _t("This PoS window will be closed and you'll have to open a new session."); + if ((sessions[0].state) !== 'closing_control') { + body = _t("The session you're working on is in closing control : ") + body; + } else { + body = _t("The session you're working on is closed : ") + body; + } + // warn user if current session is not opened + self.gui.show_popup('error', { + 'title': title, + 'body': body, + cancel: function(){ + self.gui.close(); + }, + }); + clearInterval(self.intervalIDCheckSessionState); + } + }) + .fail(function(error, event){ + // Prevent error if server is unreachable + event.preventDefault(); + }); + } + }); + +}); diff --git a/pos_check_session_state/views/templates.xml b/pos_check_session_state/views/templates.xml new file mode 100644 index 00000000..7084416d --- /dev/null +++ b/pos_check_session_state/views/templates.xml @@ -0,0 +1,16 @@ + + + + + +