From b51b82c280440597f6c69c9e2bd07041fdebc81b Mon Sep 17 00:00:00 2001 From: aenaya Date: Tue, 1 Oct 2019 18:48:29 +0200 Subject: [PATCH 1/2] extra confirmation box when click on save in settings if some modules should be uninstalled --- res_config_module_helper/__init__.py | 6 +++ res_config_module_helper/__manifest__.py | 19 +++++++ res_config_module_helper/models/__init__.py | 5 ++ .../models/res_config_settings.py | 49 +++++++++++++++++++ res_config_module_helper/wizard/__init__.py | 5 ++ .../wizard/confirm_uninstall.py | 23 +++++++++ .../wizard/confirm_uninstall.xml | 28 +++++++++++ 7 files changed, 135 insertions(+) create mode 100644 res_config_module_helper/__init__.py create mode 100644 res_config_module_helper/__manifest__.py create mode 100644 res_config_module_helper/models/__init__.py create mode 100644 res_config_module_helper/models/res_config_settings.py create mode 100644 res_config_module_helper/wizard/__init__.py create mode 100644 res_config_module_helper/wizard/confirm_uninstall.py create mode 100644 res_config_module_helper/wizard/confirm_uninstall.xml diff --git a/res_config_module_helper/__init__.py b/res_config_module_helper/__init__.py new file mode 100644 index 000000000..569d85882 --- /dev/null +++ b/res_config_module_helper/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard +from . import models \ No newline at end of file diff --git a/res_config_module_helper/__manifest__.py b/res_config_module_helper/__manifest__.py new file mode 100644 index 000000000..2a1ce3b51 --- /dev/null +++ b/res_config_module_helper/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Res Config Module Helper', + 'version': '11.0.1.0.0', + 'category': 'Base', + 'license': 'AGPL-3', + 'summary': 'Extra Confirmation box for uninstall modules from settings', + 'author': 'initOS, Amjad Enaya, Odoo Community Association (OCA)', + 'website': '', + 'depends': [ + ], + 'data': [ + 'wizard/confirm_uninstall.xml', + ], + 'installable': True, +} \ No newline at end of file diff --git a/res_config_module_helper/models/__init__.py b/res_config_module_helper/models/__init__.py new file mode 100644 index 000000000..a061a4a51 --- /dev/null +++ b/res_config_module_helper/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import res_config_settings \ No newline at end of file diff --git a/res_config_module_helper/models/res_config_settings.py b/res_config_module_helper/models/res_config_settings.py new file mode 100644 index 000000000..3161cc068 --- /dev/null +++ b/res_config_module_helper/models/res_config_settings.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields, api, _ + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + @api.multi + def execute_from_confirm_wiz(self): + self.ensure_one() + res = super(ResConfigSettings, self).execute() + return res + + @api.multi + def execute(self): + self.ensure_one() + ModuleSudo = self.env['ir.module.module'].sudo() + module_fields = filter(lambda x: x.startswith('module_'), self._fields.keys()) + module_names = list(map(lambda x: x.replace("module_", ''), module_fields)) + modules = ModuleSudo.search( + [('name', 'in', module_names), + ('state', 'in', ['to install', 'installed', 'to upgrade']) + ]) + need_warning = False + for obj in modules: + field_name = 'module_' + obj.name + if not self[field_name]: + need_warning = True + break + if need_warning: + print('warning needed') + dic = { + 'type': 'ir.actions.act_window', + 'name': 'Confirmation', + 'res_model': 'confirm.uninstall', + 'view_type': 'form', + 'view_mode': 'form', + 'res_id': False, + 'view_id': self.env.ref('res_config_module_helper.confirm_uninstall_form', False).id, + 'target': 'new', + 'context': {'default_res_id': self.id} + } + return dic + else: + res = super(ResConfigSettings, self).execute() + return res + diff --git a/res_config_module_helper/wizard/__init__.py b/res_config_module_helper/wizard/__init__.py new file mode 100644 index 000000000..bb0c28f17 --- /dev/null +++ b/res_config_module_helper/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import confirm_uninstall diff --git a/res_config_module_helper/wizard/confirm_uninstall.py b/res_config_module_helper/wizard/confirm_uninstall.py new file mode 100644 index 000000000..14b3a414e --- /dev/null +++ b/res_config_module_helper/wizard/confirm_uninstall.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# 2019 initOS (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ConfirmUninstall(models.TransientModel): + _name = 'confirm.uninstall' + _description = 'Confirm before uninstall a module from config' + + def confirmed(self): + self.ensure_one() + res_id = int(self.env.context.get('default_res_id')) + self.env["res.config.settings"].browse(res_id).execute_from_confirm_wiz() + return + + def canceled(self): + self.ensure_one() + res_id = int(self.env.context.get('default_res_id')) + return self.env["res.config.settings"].browse(res_id).cancel() + + diff --git a/res_config_module_helper/wizard/confirm_uninstall.xml b/res_config_module_helper/wizard/confirm_uninstall.xml new file mode 100644 index 000000000..385eb546b --- /dev/null +++ b/res_config_module_helper/wizard/confirm_uninstall.xml @@ -0,0 +1,28 @@ + + + + + + + confirm.uninstall.form + confirm.uninstall + +
+

+ By confirmation some Modules will be uninstalled which can lead to DATA LOST. + Please make sure that you want to proceed +

+ By cancelling all your changes in the settings will be discarded +

+
+
+
+
+
+ +
From aa0e59f8937283a313123788bd4739b0f128ab8f Mon Sep 17 00:00:00 2001 From: aenaya Date: Wed, 2 Oct 2019 12:11:02 +0200 Subject: [PATCH 2/2] improve the code and delete unneeded code --- res_config_module_helper/__init__.py | 4 ++-- res_config_module_helper/__manifest__.py | 8 ++------ res_config_module_helper/models/__init__.py | 4 ++-- res_config_module_helper/models/res_config_settings.py | 8 +++----- res_config_module_helper/wizard/__init__.py | 3 ++- res_config_module_helper/wizard/confirm_uninstall.py | 2 +- res_config_module_helper/wizard/confirm_uninstall.xml | 3 +-- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/res_config_module_helper/__init__.py b/res_config_module_helper/__init__.py index 569d85882..edbf0a33c 100644 --- a/res_config_module_helper/__init__.py +++ b/res_config_module_helper/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import wizard -from . import models \ No newline at end of file +from . import models diff --git a/res_config_module_helper/__manifest__.py b/res_config_module_helper/__manifest__.py index 2a1ce3b51..6418bc9dc 100644 --- a/res_config_module_helper/__manifest__.py +++ b/res_config_module_helper/__manifest__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - { 'name': 'Res Config Module Helper', 'version': '11.0.1.0.0', @@ -9,11 +8,8 @@ 'license': 'AGPL-3', 'summary': 'Extra Confirmation box for uninstall modules from settings', 'author': 'initOS, Amjad Enaya, Odoo Community Association (OCA)', - 'website': '', - 'depends': [ - ], 'data': [ 'wizard/confirm_uninstall.xml', ], 'installable': True, -} \ No newline at end of file +} diff --git a/res_config_module_helper/models/__init__.py b/res_config_module_helper/models/__init__.py index a061a4a51..af2dd69b8 100644 --- a/res_config_module_helper/models/__init__.py +++ b/res_config_module_helper/models/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import res_config_settings \ No newline at end of file +from . import res_config_settings diff --git a/res_config_module_helper/models/res_config_settings.py b/res_config_module_helper/models/res_config_settings.py index 3161cc068..107b0950a 100644 --- a/res_config_module_helper/models/res_config_settings.py +++ b/res_config_module_helper/models/res_config_settings.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api, _ @@ -17,8 +17,8 @@ def execute_from_confirm_wiz(self): def execute(self): self.ensure_one() ModuleSudo = self.env['ir.module.module'].sudo() - module_fields = filter(lambda x: x.startswith('module_'), self._fields.keys()) - module_names = list(map(lambda x: x.replace("module_", ''), module_fields)) + module_fields = filter(lambda x: x.startswith('module_'), self._fields) + module_names = [x.replace("module_", '') for x in module_fields] modules = ModuleSudo.search( [('name', 'in', module_names), ('state', 'in', ['to install', 'installed', 'to upgrade']) @@ -30,7 +30,6 @@ def execute(self): need_warning = True break if need_warning: - print('warning needed') dic = { 'type': 'ir.actions.act_window', 'name': 'Confirmation', @@ -46,4 +45,3 @@ def execute(self): else: res = super(ResConfigSettings, self).execute() return res - diff --git a/res_config_module_helper/wizard/__init__.py b/res_config_module_helper/wizard/__init__.py index bb0c28f17..6a1f90ca8 100644 --- a/res_config_module_helper/wizard/__init__.py +++ b/res_config_module_helper/wizard/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import confirm_uninstall + diff --git a/res_config_module_helper/wizard/confirm_uninstall.py b/res_config_module_helper/wizard/confirm_uninstall.py index 14b3a414e..b0ca9ed16 100644 --- a/res_config_module_helper/wizard/confirm_uninstall.py +++ b/res_config_module_helper/wizard/confirm_uninstall.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# 2019 initOS (Amjad Enaya ) +# 2019 initOS GmbH (Amjad Enaya ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models diff --git a/res_config_module_helper/wizard/confirm_uninstall.xml b/res_config_module_helper/wizard/confirm_uninstall.xml index 385eb546b..168166383 100644 --- a/res_config_module_helper/wizard/confirm_uninstall.xml +++ b/res_config_module_helper/wizard/confirm_uninstall.xml @@ -1,7 +1,7 @@ @@ -24,5 +24,4 @@ -