Browse Source

[ADD] pos_check_session_state

pull/387/head
Sylvain LE GAL 5 years ago
parent
commit
553fe96325
  1. 83
      pos_check_session_state/README.rst
  2. 1
      pos_check_session_state/__init__.py
  3. 28
      pos_check_session_state/__manifest__.py
  4. 58
      pos_check_session_state/i18n/fr.po
  5. 1
      pos_check_session_state/models/__init__.py
  6. 13
      pos_check_session_state/models/pos_config.py
  7. 4
      pos_check_session_state/readme/CONFIGURE.rst
  8. 1
      pos_check_session_state/readme/CONTRIBUTORS.rst
  9. 16
      pos_check_session_state/readme/DESCRIPTION.rst
  10. BIN
      pos_check_session_state/static/description/error_message.png
  11. BIN
      pos_check_session_state/static/description/icon.png
  12. BIN
      pos_check_session_state/static/description/pos_config_form.png
  13. 79
      pos_check_session_state/static/src/js/pos_check_session_state.js
  14. 34
      pos_check_session_state/static/src/xml/pos_check_session_state.xml
  15. 16
      pos_check_session_state/views/templates.xml
  16. 22
      pos_check_session_state/views/view_pos_config.xml

83
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 <https://github.com/grap/grap-odoo-incubator/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 <https://github.com/grap/grap-odoo-incubator/issues/new?body=module:%20pos_check_session_state%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* GRAP
Contributors
~~~~~~~~~~~~
* Sylvain LE GAL <https://twitter.com/legalsylvain>
Maintainers
~~~~~~~~~~~
This module is part of the `grap/grap-odoo-incubator <https://github.com/grap/grap-odoo-incubator/tree/8.0/pos_check_session_state>`_ project on GitHub.
You are welcome to contribute.

1
pos_check_session_state/__init__.py

@ -0,0 +1 @@
from . import models

28
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,
}

58
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."

1
pos_check_session_state/models/__init__.py

@ -0,0 +1 @@
from . import pos_config

13
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.")

4
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

1
pos_check_session_state/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>

16
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

BIN
pos_check_session_state/static/description/error_message.png

After

Width: 599  |  Height: 490  |  Size: 50 KiB

BIN
pos_check_session_state/static/description/icon.png

After

Width: 64  |  Height: 64  |  Size: 4.1 KiB

BIN
pos_check_session_state/static/description/pos_config_form.png

After

Width: 780  |  Height: 472  |  Size: 41 KiB

79
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,
};
});

34
pos_check_session_state/static/src/xml/pos_check_session_state.xml

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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).
-->
<templates id="template" xml:space="preserve">
<t t-name="ErrorClosedSessionPopupWidget">
<div role="cialog" class="modal-dialog">
<div class="popup popup-error">
<p class="title"><t t-esc="widget.pos.pos_session.name" /></p>
<t t-if="widget.options.session_state === 'closing_control'">
<p class="body">
The session you're working on is in closing control.
</p>
</t>
<t t-if="widget.options.session_state === 'closed'">
<p class="body">
The session you're working on is closed.
</p>
</t>
<p class="body">
Please close the current Point Of Sale Window and open it again to use a correct session.
</p>
</div>
</div>
</t>
</templates>

16
pos_check_session_state/views/templates.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_check_session_state/static/src/js/pos_check_session_state.js"></script>
</xpath>
</template>
</odoo>

22
pos_check_session_state/views/view_pos_config.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2017 - 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>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='title']" position="after">
<group string="Check Session State">
<field name="check_session_state_frequency"/>
</group>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save