[IMP] indicate tests in current thread, and prevent email sending during tests
[odoo/odoo.git] / openerp / modules / loading.py
index 4098658..1ea0bdb 100644 (file)
@@ -31,6 +31,7 @@ import logging
 import os
 import re
 import sys
+import threading
 import zipfile
 import zipimport
 
@@ -97,11 +98,13 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
         cr.commit()
         if not tools.config.options['test_disable']:
             try:
+                threading.currentThread().testing = True
                 _load_data(cr, module_name, idref, mode, 'test')
             except Exception, e:
                 logging.getLogger('init.test').exception(
                     'Tests failed to execute in module %s', module_name)
             finally:
+                threading.currentThread().testing = False
                 if tools.config.options['test_commit']:
                     cr.commit()
                 else:
@@ -147,6 +150,10 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
     migrations = openerp.modules.migration.MigrationManager(cr, graph)
     logger.debug('loading %d packages...', len(graph))
 
+    # get db timestamp
+    cr.execute("select now()::timestamp")
+    dt_before_load = cr.fetchone()[0]
+
     # register, instantiate and initialize models for each modules
     for index, package in enumerate(graph):
         module_name = package.name
@@ -214,6 +221,9 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
 
         cr.commit()
 
+    # mark new res_log records as read
+    cr.execute("update res_log set read=True where create_date >= %s", (dt_before_load,))
+
     cr.commit()
 
     return loaded_modules, processed_modules
@@ -339,16 +349,16 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
             cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""")
             for (model, name) in cr.fetchall():
                 model_obj = pool.get(model)
-                if model_obj and not isinstance(model_obj, osv.osv.osv_memory):
-                    logger.notifyChannel('init', netsvc.LOG_WARNING, 'object %s (%s) has no access rules!' % (model, name))
+                if model_obj and not model_obj.is_transient():
+                    logger.notifyChannel('init', netsvc.LOG_WARNING, 'Model %s (%s) has no access rules!' % (model, name))
 
             # Temporary warning while we remove access rights on osv_memory objects, as they have
             # been replaced by owner-only access rights
             cr.execute("""select distinct mod.model, mod.name from ir_model_access acc, ir_model mod where acc.model_id = mod.id""")
             for (model, name) in cr.fetchall():
                 model_obj = pool.get(model)
-                if isinstance(model_obj, osv.osv.osv_memory) and not isinstance(model_obj, osv.osv.osv):
-                    logger.notifyChannel('init', netsvc.LOG_WARNING, 'In-memory object %s (%s) should not have explicit access rules!' % (model, name))
+                if model_obj and model_obj.is_transient():
+                    logger.notifyChannel('init', netsvc.LOG_WARNING, 'The transient model %s (%s) should not have explicit access rules!' % (model, name))
 
             cr.execute("SELECT model from ir_model")
             for (model,) in cr.fetchall():
@@ -356,7 +366,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
                 if obj:
                     obj._check_removed_columns(cr, log=True)
                 else:
-                    logger.notifyChannel('init', netsvc.LOG_WARNING, "Model %s is referenced but not present in the orm pool!" % model)
+                    logger.notifyChannel('init', netsvc.LOG_WARNING, "Model %s is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)" % model)
 
             # Cleanup orphan records
             pool.get('ir.model.data')._process_end(cr, 1, processed_modules)