summaryrefslogtreecommitdiff
path: root/odoo/modules/loading.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2018-06-22 15:33:25 +0200
committerXavier Morel <xmo@odoo.com>2018-07-16 11:44:33 +0200
commite89131381015e0ca155f64500d077a7a7bfff9c8 (patch)
treeab71505096477a4cfb7023bd193332e75c33319a /odoo/modules/loading.py
parent93c0d7e811da0e64d03bfea0f131c6ace1fbde05 (diff)
[IMP] base: disable demo data if they can't install
Task 1856935 Currently, if installing a module's demo data fails (because the module was uninstalled and some were left over and can't be reinstalled, or because they're broken, or…) the installation of the module fails and further installations are skipped (?). Since demo data are non-essential (though required to run tests), rather than fail everything if they fail just roll them back and notify the user. This change generates a warning log *and* shows a notification popup to the end user.
Diffstat (limited to 'odoo/modules/loading.py')
-rw-r--r--odoo/modules/loading.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py
index f9a41c9161b..af4ed28ca59 100644
--- a/odoo/modules/loading.py
+++ b/odoo/modules/loading.py
@@ -75,10 +75,27 @@ def load_demo(cr, package, idref, mode, report=None):
"""
Loads demo data for the specified package.
"""
- has_demo = hasattr(package, 'demo') or (package.dbdemo and package.state != 'installed')
- if has_demo:
- load_data(cr, idref, mode, kind='demo', package=package, report=report)
- return has_demo
+ if not package.should_have_demo():
+ return False
+
+ try:
+ _logger.info("Module %s: loading demo", package.name)
+ with cr.savepoint():
+ load_data(cr, idref, mode, kind='demo', package=package, report=report)
+ return True
+ except Exception as e:
+ # If we could not install demo data for this module
+ _logger.warning(
+ "Module %s demo data failed to install, installed without demo data",
+ package.name, exc_info=True)
+
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ todo = env.ref('base.demo_failure_todo', raise_if_not_found=False)
+ Failure = env.get('ir.demo_failure')
+ if todo and Failure is not None:
+ todo.state = 'open'
+ Failure.create({'module_id': package.id, 'error': str(e)})
+ return False
def force_demo(cr):
@@ -205,10 +222,9 @@ def load_module_graph(cr, graph, status=None, perform_checks=True,
# upgrading the module information
module.write(module.get_values_from_terp(package.data))
load_data(cr, idref, mode, kind='data', package=package, report=report)
- demo_loaded = load_demo(cr, package, idref, mode, report)
- if demo_loaded:
- cr.execute('update ir_module_module set demo=%s where id=%s', (True, module_id))
- module.invalidate_cache(['demo'])
+ demo_loaded = package.dbdemo = load_demo(cr, package, idref, mode, report)
+ cr.execute('update ir_module_module set demo=%s where id=%s', (demo_loaded, module_id))
+ module.invalidate_cache(['demo'])
migrations.migrate_module(package, 'post')