From 89beb536f293d6f48b4525e0997d7db0ffd1ef1f Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 28 Aug 2017 12:33:43 +0200 Subject: [PATCH] [FIX][module_auto_update] Record base addon checksum (#948) --- module_auto_update/__openerp__.py | 2 +- module_auto_update/models/module.py | 34 +++++++------------- module_auto_update/tests/test_module.py | 17 ++++------ module_auto_update/wizards/module_upgrade.py | 14 +++++++- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/module_auto_update/__openerp__.py b/module_auto_update/__openerp__.py index 36afb51c4..5bd2fc850 100644 --- a/module_auto_update/__openerp__.py +++ b/module_auto_update/__openerp__.py @@ -5,7 +5,7 @@ { 'name': 'Module Auto Update', 'summary': 'Automatically update Odoo modules', - 'version': '9.0.1.0.0', + 'version': '9.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 68d92ef74..91373e617 100644 --- a/module_auto_update/models/module.py +++ b/module_auto_update/models/module.py @@ -41,31 +41,21 @@ class Module(models.Model): "Cannot compute dir hash for %s, module not found", r.display_name) + @api.multi def _store_checksum_installed(self, vals): - if self.env.context.get('retain_checksum_installed'): - return + """Store the right installed checksum, if addon is installed.""" if 'checksum_installed' not in vals: - if vals.get('state') == 'installed': - for r in self: - r.checksum_installed = r.checksum_dir - elif vals.get('state') == 'uninstalled': + try: + version = vals["latest_version"] + except KeyError: + return # Not [un]installing/updating any addon + if version is False: + # Uninstalling self.write({'checksum_installed': False}) - - @api.multi - def button_uninstall_cancel(self): - # TODO Use super() like in v10 after pull is merged - # HACK https://github.com/odoo/odoo/pull/18597 - return self.with_context(retain_checksum_installed=True).write({ - 'state': 'installed', - }) - - @api.multi - def button_upgrade_cancel(self): - # TODO Use super() like in v10 after pull is merged - # HACK https://github.com/odoo/odoo/pull/18597 - return self.with_context(retain_checksum_installed=True).write({ - 'state': 'installed', - }) + else: + # Installing or updating + for one in self: + one.checksum_installed = one.checksum_dir @api.model def create(self, vals): diff --git a/module_auto_update/tests/test_module.py b/module_auto_update/tests/test_module.py index 432256ed5..4ed7bed08 100644 --- a/module_auto_update/tests/test_module.py +++ b/module_auto_update/tests/test_module.py @@ -10,6 +10,7 @@ import mock from openerp.modules import get_module_path from openerp.tests.common import TransactionCase +from openerp.tools import mute_logger from .. import post_init_hook @@ -77,24 +78,19 @@ class TestModule(TransactionCase): def test_store_checksum_installed_state_installed(self): """It should set the module's checksum_installed equal to - checksum_dir when vals contain state 'installed'""" + checksum_dir when vals contain a ``latest_version`` str.""" self.own_module.checksum_installed = 'test' - self.own_module._store_checksum_installed({'state': 'installed'}) + self.own_module._store_checksum_installed({'latest_version': '1.0'}) self.assertEqual( self.own_module.checksum_installed, self.own_module.checksum_dir, - 'Setting state to installed does not store checksum_dir ' - 'as checksum_installed', ) def test_store_checksum_installed_state_uninstalled(self): """It should clear the module's checksum_installed when vals - contain state 'uninstalled'""" + contain ``"latest_version": False``""" self.own_module.checksum_installed = 'test' - self.own_module._store_checksum_installed({'state': 'uninstalled'}) - self.assertEqual( - self.own_module.checksum_installed, False, - 'Setting state to uninstalled does not clear checksum_installed', - ) + self.own_module._store_checksum_installed({'latest_version': False}) + self.assertIs(self.own_module.checksum_installed, False) def test_store_checksum_installed_vals_contain_checksum_installed(self): """It should not set checksum_installed to False or checksum_dir when @@ -159,6 +155,7 @@ class TestModule(TransactionCase): '_store_checksum_installed', ) + @mute_logger("openerp.modules.module") @mock.patch('%s.get_module_path' % model) def test_get_module_list(self, module_path_mock): """It should change the state of modules with different diff --git a/module_auto_update/wizards/module_upgrade.py b/module_auto_update/wizards/module_upgrade.py index fed343957..a9b577e3d 100644 --- a/module_auto_update/wizards/module_upgrade.py +++ b/module_auto_update/wizards/module_upgrade.py @@ -30,4 +30,16 @@ class ModuleUpgrade(models.TransientModel): # Compute updates by checksum when called in @api.model fashion if not self: self.get_module_list() - return super(ModuleUpgrade, self).upgrade_module() + # Get base adddon status before updating + base = self.env["ir.module.module"].search([("name", "=", "base")]) + pre_state = base.state + result = super(ModuleUpgrade, self).upgrade_module() + # Update base addon checksum if its state changed + base.invalidate_cache() + if base.state != pre_state: + # This triggers the write hook that should have been triggered + # when the module was [un]installed/updated in the base-only + # module graph inside above call to super(), and updates its + # dir checksum as needed + base.latest_version = base.latest_version + return result