diff --git a/module_auto_update/__manifest__.py b/module_auto_update/__manifest__.py index db65d269a..57a5846db 100644 --- a/module_auto_update/__manifest__.py +++ b/module_auto_update/__manifest__.py @@ -5,7 +5,7 @@ { 'name': 'Module Auto Update', 'summary': 'Automatically update Odoo modules', - 'version': '10.0.1.0.0', + 'version': '10.0.1.0.1', 'category': 'Extra Tools', 'website': 'https://odoo-community.org/', 'author': 'LasLabs, ' diff --git a/module_auto_update/models/module.py b/module_auto_update/models/module.py index f191dcb75..273d72588 100644 --- a/module_auto_update/models/module.py +++ b/module_auto_update/models/module.py @@ -51,6 +51,13 @@ class Module(models.Model): elif vals.get('state') == 'uninstalled': self.write({'checksum_installed': False}) + @api.multi + def button_uninstall(self): + return super( + Module, + self.with_context(module_uninstall=True), + ).button_uninstall() + @api.multi def button_uninstall_cancel(self): return super( diff --git a/module_auto_update/tests/test_module.py b/module_auto_update/tests/test_module.py index 2cdbba44b..bd25ed07a 100644 --- a/module_auto_update/tests/test_module.py +++ b/module_auto_update/tests/test_module.py @@ -22,6 +22,10 @@ except ImportError: model = 'odoo.addons.module_auto_update.models.module' +class EndTestException(Exception): + pass + + class TestModule(TransactionCase): def setUp(self): @@ -122,6 +126,41 @@ class TestModule(TransactionCase): 'overwrite', ) + @mock.patch('%s.get_module_path' % model) + def test_button_uninstall_no_recompute(self, module_path_mock): + """It should not attempt update on `button_uninstall`.""" + module_path_mock.return_value = self.own_dir_path + vals = { + 'name': 'module_auto_update_test_module', + 'state': 'installed', + } + test_module = self.create_test_module(vals) + test_module.checksum_installed = 'test' + uninstall_module = self.env['ir.module.module'].search([ + ('name', '=', 'web'), + ]) + uninstall_module.button_uninstall() + self.assertNotEqual( + test_module.state, 'to upgrade', + 'Auto update logic was triggered during uninstall.', + ) + + def test_button_immediate_uninstall_no_recompute(self): + """It should not attempt update on `button_immediate_uninstall`.""" + + uninstall_module = self.env['ir.module.module'].search([ + ('name', '=', 'web'), + ]) + + try: + mk = mock.MagicMock() + uninstall_module._patch_method('button_uninstall', mk) + mk.side_effect = EndTestException + with self.assertRaises(EndTestException): + uninstall_module.button_immediate_uninstall() + finally: + uninstall_module._revert_method('button_uninstall') + def test_button_uninstall_cancel(self): """It should preserve checksum_installed when cancelling uninstall""" self.own_module.write({'state': 'to remove'}) diff --git a/module_auto_update/wizards/module_upgrade.py b/module_auto_update/wizards/module_upgrade.py index 0ccfeba9a..188030dd8 100644 --- a/module_auto_update/wizards/module_upgrade.py +++ b/module_auto_update/wizards/module_upgrade.py @@ -10,12 +10,13 @@ class ModuleUpgrade(models.TransientModel): @api.model def get_module_list(self): - Module = self.env["ir.module.module"] - installed_modules = Module.search([('state', '=', 'installed')]) - upgradeable_modules = installed_modules.filtered( - lambda r: r.checksum_dir != r.checksum_installed, - ) - upgradeable_modules.button_upgrade() + if not self.env.context.get('module_uninstall'): + Module = self.env["ir.module.module"] + installed_modules = Module.search([('state', '=', 'installed')]) + upgradeable_modules = installed_modules.filtered( + lambda r: r.checksum_dir != r.checksum_installed, + ) + upgradeable_modules.button_upgrade() return super(ModuleUpgrade, self).get_module_list() @api.multi