[FIX][module_auto_update] Record base addon checksum (#948)
parent
3e868c0448
commit
ea9ae22d49
|
@ -41,36 +41,21 @@ class Module(models.Model):
|
||||||
"Cannot compute dir hash for %s, module not found",
|
"Cannot compute dir hash for %s, module not found",
|
||||||
r.display_name)
|
r.display_name)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
def _store_checksum_installed(self, vals):
|
def _store_checksum_installed(self, vals):
|
||||||
if self.env.context.get('retain_checksum_installed'):
|
"""Store the right installed checksum, if addon is installed."""
|
||||||
return
|
|
||||||
if 'checksum_installed' not in vals:
|
if 'checksum_installed' not in vals:
|
||||||
if vals.get('state') == 'installed':
|
try:
|
||||||
for r in self:
|
version = vals["latest_version"]
|
||||||
r.checksum_installed = r.checksum_dir
|
except KeyError:
|
||||||
elif vals.get('state') == 'uninstalled':
|
return # Not [un]installing/updating any addon
|
||||||
|
if version is False:
|
||||||
|
# Uninstalling
|
||||||
self.write({'checksum_installed': False})
|
self.write({'checksum_installed': False})
|
||||||
|
else:
|
||||||
@api.multi
|
# Installing or updating
|
||||||
def button_uninstall(self):
|
for one in self:
|
||||||
return super(
|
one.checksum_installed = one.checksum_dir
|
||||||
Module,
|
|
||||||
self.with_context(module_uninstall=True),
|
|
||||||
).button_uninstall()
|
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def button_uninstall_cancel(self):
|
|
||||||
return super(
|
|
||||||
Module,
|
|
||||||
self.with_context(retain_checksum_installed=True),
|
|
||||||
).button_uninstall_cancel()
|
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def button_upgrade_cancel(self):
|
|
||||||
return super(
|
|
||||||
Module,
|
|
||||||
self.with_context(retain_checksum_installed=True),
|
|
||||||
).button_upgrade_cancel()
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
|
|
|
@ -10,6 +10,7 @@ import mock
|
||||||
|
|
||||||
from odoo.modules import get_module_path
|
from odoo.modules import get_module_path
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
from odoo.tools import mute_logger
|
||||||
|
|
||||||
from .. import post_init_hook
|
from .. import post_init_hook
|
||||||
|
|
||||||
|
@ -81,24 +82,19 @@ class TestModule(TransactionCase):
|
||||||
|
|
||||||
def test_store_checksum_installed_state_installed(self):
|
def test_store_checksum_installed_state_installed(self):
|
||||||
"""It should set the module's checksum_installed equal to
|
"""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.checksum_installed = 'test'
|
||||||
self.own_module._store_checksum_installed({'state': 'installed'})
|
self.own_module._store_checksum_installed({'latest_version': '1.0'})
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.own_module.checksum_installed, self.own_module.checksum_dir,
|
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):
|
def test_store_checksum_installed_state_uninstalled(self):
|
||||||
"""It should clear the module's checksum_installed when vals
|
"""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.checksum_installed = 'test'
|
||||||
self.own_module._store_checksum_installed({'state': 'uninstalled'})
|
self.own_module._store_checksum_installed({'latest_version': False})
|
||||||
self.assertEqual(
|
self.assertIs(self.own_module.checksum_installed, False)
|
||||||
self.own_module.checksum_installed, False,
|
|
||||||
'Setting state to uninstalled does not clear checksum_installed',
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_store_checksum_installed_vals_contain_checksum_installed(self):
|
def test_store_checksum_installed_vals_contain_checksum_installed(self):
|
||||||
"""It should not set checksum_installed to False or checksum_dir when
|
"""It should not set checksum_installed to False or checksum_dir when
|
||||||
|
@ -198,6 +194,7 @@ class TestModule(TransactionCase):
|
||||||
'_store_checksum_installed',
|
'_store_checksum_installed',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@mute_logger("openerp.modules.module")
|
||||||
@mock.patch('%s.get_module_path' % model)
|
@mock.patch('%s.get_module_path' % model)
|
||||||
def test_get_module_list(self, module_path_mock):
|
def test_get_module_list(self, module_path_mock):
|
||||||
"""It should change the state of modules with different
|
"""It should change the state of modules with different
|
||||||
|
|
|
@ -31,4 +31,16 @@ class ModuleUpgrade(models.TransientModel):
|
||||||
# Compute updates by checksum when called in @api.model fashion
|
# Compute updates by checksum when called in @api.model fashion
|
||||||
if not self:
|
if not self:
|
||||||
self.get_module_list()
|
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
|
||||||
|
|
Loading…
Reference in New Issue