Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra confirm uninstall whn clicking on save in settings if some modules should be ununsatted #2

Open
wants to merge 2 commits into
base: 11.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions res_config_module_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import wizard
from . import models
15 changes: 15 additions & 0 deletions res_config_module_helper/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# 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,
}
5 changes: 5 additions & 0 deletions res_config_module_helper/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import res_config_settings
47 changes: 47 additions & 0 deletions res_config_module_helper/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# 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
6 changes: 6 additions & 0 deletions res_config_module_helper/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import confirm_uninstall

23 changes: 23 additions & 0 deletions res_config_module_helper/wizard/confirm_uninstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# 2019 initOS GmbH (Amjad Enaya <[email protected]>)
# 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()


27 changes: 27 additions & 0 deletions res_config_module_helper/wizard/confirm_uninstall.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
© 2019 initOS GmbHtOS (Amjad Enaya <[email protected]>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo>
<record id="confirm_uninstall_form" model="ir.ui.view">
<field name="name">confirm.uninstall.form</field>
<field name="model">confirm.uninstall</field>
<field name="arch" type="xml">
<form string="Confirmation before uninstall">
<p>
By <b>confirmation</b> some Modules will be <b>uninstalled</b> which can lead to <b>DATA LOST</b>.
Please make sure that you want to proceed
<br></br>
By <b>cancelling</b> all your changes in the settings will be discarded
</p>
<footer>
<button type="object" name="confirmed" string="Confirm uninstall" class="oe_highlight"/>
<button type="object" name="canceled" string="Cancel" class="oe_link"/>
</footer>
</form>
</field>
</record>
</odoo>