diff --git a/web_database_rollback/README.rst b/web_database_rollback/README.rst index fde4a07..7a3872e 100644 --- a/web_database_rollback/README.rst +++ b/web_database_rollback/README.rst @@ -15,7 +15,7 @@ The database state will revert to the state prior to pressing Activate button. The number of Odoo workers has to be 0. -Note that when you press Rollback button, all the chanages done by other users will be lost. +Note that when you press Rollback button, all the changes done by other users will be lost. Also note that, you always have to press Rollback button at the end of your testing/investigation session. When you press the Activate button, the cursor used for accessing the db is test cursor. diff --git a/web_database_rollback/controllers/main.py b/web_database_rollback/controllers/main.py index 8116bf0..28ac111 100644 --- a/web_database_rollback/controllers/main.py +++ b/web_database_rollback/controllers/main.py @@ -1,13 +1,13 @@ -# -*- coding: utf-8 -*- -############################################################################## +# -*- encoding: utf-8 -*- +# ############################################################################# # # Authors: Cojocaru Marcel (marcel.cojocaru@gmail.com) # Copyright (c) 2019 Cojocaru Aurelian Marcel PFA # # 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. +# 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 @@ -17,30 +17,36 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -############################################################################## +############################################################################# import openerp import openerp.http as http from openerp.http import request +import openerp.tools.config as config +from openerp import exceptions, _ + class DBRollbackController(http.Controller): @http.route( '/web_database_rollback/activate', - type='json', auth='none') + type='json', auth='user') def activate(self): + if config['workers'] > 0: + raise exceptions.Warning(_('Number of workers in Odoo configuration file should be 0.')) + registry = openerp.modules.registry.RegistryManager.get( request.session.db) - if registry.test_cr == None: + if registry.test_cr is None: registry.enter_test_mode() registry.clear_caches() @http.route( '/web_database_rollback/rollback', - type='json', auth='none') + type='json', auth='user') def rollback(self): registry = openerp.modules.registry.RegistryManager.get( request.session.db) - if registry.test_cr != None: + if registry.test_cr is not None: registry.leave_test_mode() registry.clear_caches() diff --git a/web_database_rollback/i18n/web_database_rollback.po b/web_database_rollback/i18n/web_database_rollback.po new file mode 100644 index 0000000..42ce88d --- /dev/null +++ b/web_database_rollback/i18n/web_database_rollback.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_database_rollback +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-02-16 19:19+0000\n" +"PO-Revision-Date: 2019-02-16 19:19+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: web_database_rollback +#. openerp-web +#: code:addons/web_database_rollback/static/src/xml/db_rollback.xml:7 +#, python-format +msgid "Activate" +msgstr "" + +#. module: web_database_rollback +#: code:addons/web_database_rollback/controllers/main.py:32 +#, python-format +msgid "Number of workers in Odoo configuration file should be 0." +msgstr "" + +#. module: web_database_rollback +#. openerp-web +#: code:addons/web_database_rollback/static/src/xml/db_rollback.xml:10 +#, python-format +msgid "Rollback" +msgstr "" + diff --git a/web_database_rollback/static/src/js/db_rollback.js b/web_database_rollback/static/src/js/db_rollback.js index 9ac0b07..64a6a5c 100644 --- a/web_database_rollback/static/src/js/db_rollback.js +++ b/web_database_rollback/static/src/js/db_rollback.js @@ -14,16 +14,12 @@ openerp.web_database_rollback = function (instance) { this.$el.show(); this.$el.find('.activate').on('click', function(ev) { self.$el.find('.activate').css("background-color", "green").css("color", "white"); - var func = '/web_database_rollback/activate'; - self.rpc(func, {}).done(function(res) { - }); + self.rpc('/web_database_rollback/activate', {}).done(function(res) {}); }); this.$el.find('.rollback').on('click', function(ev) { self.$el.find('.activate').css("background-color", "buttonface").css("color", "#777"); - var func = '/web_database_rollback/rollback'; - self.rpc(func, {}).done(function(res) { - }); + self.rpc('/web_database_rollback/rollback', {}).done(function(res) {}); }); }, });