diff --git a/res_config_module_helper/__init__.py b/res_config_module_helper/__init__.py new file mode 100644 index 000000000..edbf0a33c --- /dev/null +++ b/res_config_module_helper/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# 2019 initOS GmbH (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard +from . import models diff --git a/res_config_module_helper/__manifest__.py b/res_config_module_helper/__manifest__.py new file mode 100644 index 000000000..6418bc9dc --- /dev/null +++ b/res_config_module_helper/__manifest__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# 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', + 'category': 'Base', + 'license': 'AGPL-3', + 'summary': 'Extra Confirmation box for uninstall modules from settings', + 'author': 'initOS, Amjad Enaya, Odoo Community Association (OCA)', + 'data': [ + 'wizard/confirm_uninstall.xml', + ], + 'installable': True, +} diff --git a/res_config_module_helper/models/__init__.py b/res_config_module_helper/models/__init__.py new file mode 100644 index 000000000..af2dd69b8 --- /dev/null +++ b/res_config_module_helper/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# 2019 initOS GmbH (Amjad Enaya ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +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 new file mode 100644 index 000000000..107b0950a --- /dev/null +++ b/res_config_module_helper/models/res_config_settings.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# 2019 initOS GmbH (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) + module_names = [x.replace("module_", '') for x in 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: + 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..6a1f90ca8 --- /dev/null +++ b/res_config_module_helper/wizard/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# 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 new file mode 100644 index 000000000..b0ca9ed16 --- /dev/null +++ b/res_config_module_helper/wizard/confirm_uninstall.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# 2019 initOS GmbH (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..168166383 --- /dev/null +++ b/res_config_module_helper/wizard/confirm_uninstall.xml @@ -0,0 +1,27 @@ + + + + + + + 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 +

+ +
+
+
+