From fc97124e1836744ddffd719fa934abe4972465bc Mon Sep 17 00:00:00 2001 From: Marcel Cojocaru Date: Thu, 7 Feb 2019 13:56:19 +0200 Subject: [PATCH] [ADD] web_database_rollback: allow rollback database changes --- web_database_rollback/README.rst | 60 +++++++++++++++++++ web_database_rollback/__init__.py | 21 +++++++ web_database_rollback/__openerp__.py | 39 ++++++++++++ web_database_rollback/controllers/__init__.py | 19 ++++++ web_database_rollback/controllers/main.py | 46 ++++++++++++++ .../static/src/js/db_rollback.js | 45 ++++++++++++++ .../static/src/xml/db_rollback.xml | 15 +++++ web_database_rollback/view/db_rollback.xml | 12 ++++ 8 files changed, 257 insertions(+) create mode 100644 web_database_rollback/README.rst create mode 100644 web_database_rollback/__init__.py create mode 100644 web_database_rollback/__openerp__.py create mode 100644 web_database_rollback/controllers/__init__.py create mode 100644 web_database_rollback/controllers/main.py create mode 100644 web_database_rollback/static/src/js/db_rollback.js create mode 100644 web_database_rollback/static/src/xml/db_rollback.xml create mode 100644 web_database_rollback/view/db_rollback.xml diff --git a/web_database_rollback/README.rst b/web_database_rollback/README.rst new file mode 100644 index 0000000..fde4a07 --- /dev/null +++ b/web_database_rollback/README.rst @@ -0,0 +1,60 @@ +================================================= +Revert the changes done on the database +================================================= + +This module allows to revert the database state prior to a certain moment chosen by the user. +It is useful when you test something in Odoo and afterwards want to go back to the initial database state. + +Usage +===== + +On the right side of the systray there are two buttons: Activate and Rollback +Press the Activate button (it will turn green), do any changes/actions in odoo (products, pickings, sale orders, etc) and save them. +If you want to undo all the changes, press Rollback button. +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. + +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. +The Rollback button will revert to the real odoo cursor. So in case the results seen are the ones you expect and want to keep them in the database, you have to press Rollback and do the same actions again in Odoo. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Marcel Cojocaru + +Do not contact contributors directly about support or help with technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_database_rollback/__init__.py b/web_database_rollback/__init__.py new file mode 100644 index 0000000..1f1fce9 --- /dev/null +++ b/web_database_rollback/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: 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. +# +# 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 . +# +############################################################################## +from . import controllers diff --git a/web_database_rollback/__openerp__.py b/web_database_rollback/__openerp__.py new file mode 100644 index 0000000..72df647 --- /dev/null +++ b/web_database_rollback/__openerp__.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Odoo, Open Source Management Solution +# This module copyright (C) 2014 Therp BV (). +# +# 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': 'Database Rollback', + 'version': '8.0.1.0.0', + 'category': 'web', + 'author': "Cojocaru Marcel", + 'website': '', + 'license': 'AGPL-3', + 'depends': [ + 'web', + ], + 'data': [ + 'view/db_rollback.xml', + ], + 'qweb': [ + 'static/src/xml/db_rollback.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/web_database_rollback/controllers/__init__.py b/web_database_rollback/controllers/__init__.py new file mode 100644 index 0000000..c2c8ea1 --- /dev/null +++ b/web_database_rollback/controllers/__init__.py @@ -0,0 +1,19 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## + +from . import main diff --git a/web_database_rollback/controllers/main.py b/web_database_rollback/controllers/main.py new file mode 100644 index 0000000..8116bf0 --- /dev/null +++ b/web_database_rollback/controllers/main.py @@ -0,0 +1,46 @@ +# -*- coding: 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. +# +# 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 . +# +############################################################################## +import openerp +import openerp.http as http +from openerp.http import request + + +class DBRollbackController(http.Controller): + @http.route( + '/web_database_rollback/activate', + type='json', auth='none') + def activate(self): + registry = openerp.modules.registry.RegistryManager.get( + request.session.db) + if registry.test_cr == None: + registry.enter_test_mode() + registry.clear_caches() + + @http.route( + '/web_database_rollback/rollback', + type='json', auth='none') + def rollback(self): + registry = openerp.modules.registry.RegistryManager.get( + request.session.db) + if registry.test_cr != None: + registry.leave_test_mode() + registry.clear_caches() + diff --git a/web_database_rollback/static/src/js/db_rollback.js b/web_database_rollback/static/src/js/db_rollback.js new file mode 100644 index 0000000..9ac0b07 --- /dev/null +++ b/web_database_rollback/static/src/js/db_rollback.js @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Cojocaru Aurelian Marcel PFA +// @author Marcel Cojocaru +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +openerp.web_database_rollback = function (instance) { + + instance.web_database_rollback.RollbackButtonsWidget = instance.web.Widget.extend({ + + template:'web_database_rollback.ButtonsWidget', + + renderElement: function() { + var self = this; + this._super(); + 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) { + }); + }); + + 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) { + }); + }); + }, + }); + + instance.web.UserMenu.include({ + do_update: function () { + this._super(); + var self = this; + this.update_promise.done(function () { + if (!_.isUndefined(self.rollbackButtons)) { + return; + } + self.rollbackButtons = new instance.web_database_rollback.RollbackButtonsWidget(self); + self.rollbackButtons.prependTo(instance.webclient.$('.oe_systray')); + }); + }, + }); + +} diff --git a/web_database_rollback/static/src/xml/db_rollback.xml b/web_database_rollback/static/src/xml/db_rollback.xml new file mode 100644 index 0000000..e3ec2cd --- /dev/null +++ b/web_database_rollback/static/src/xml/db_rollback.xml @@ -0,0 +1,15 @@ + + diff --git a/web_database_rollback/view/db_rollback.xml b/web_database_rollback/view/db_rollback.xml new file mode 100644 index 0000000..7e9bace --- /dev/null +++ b/web_database_rollback/view/db_rollback.xml @@ -0,0 +1,12 @@ + + + + + + + +