[REF] osv: previous diff makes unneccessary one of makeInstance/createInstance.
authorVo Minh Thu <vmt@openerp.com>
Tue, 16 Aug 2011 07:44:31 +0000 (09:44 +0200)
committerVo Minh Thu <vmt@openerp.com>
Tue, 16 Aug 2011 07:44:31 +0000 (09:44 +0200)
bzr revid: vmt@openerp.com-20110816074431-v16wfzcy55ojkhwi

openerp/addons/base/ir/ir_model.py
openerp/modules/registry.py
openerp/osv/orm.py
openerp/osv/osv.py

index d3dfd98..0f60ef4 100644 (file)
@@ -161,7 +161,7 @@ class ir_model(osv.osv):
             pass
         x_custom_model._name = model
         x_custom_model._module = False
-        a = x_custom_model.createInstance(self.pool, cr)
+        a = x_custom_model.create_instance(self.pool, cr)
         if (not a._columns) or ('x_name' in a._columns.keys()):
             x_name = 'x_name'
         else:
index 11f484a..b276892 100644 (file)
@@ -73,12 +73,12 @@ class Registry(object):
         # Instanciate classes registered through their constructor and
         # add them to the pool.
         for klass in openerp.osv.orm.module_class_list.get(module, []):
-            res.append(klass.createInstance(self, cr))
+            res.append(klass.create_instance(self, cr))
 
         # Instanciate classes automatically discovered.
         for cls in openerp.osv.orm.MetaModel.module_to_models.get(module, []):
             if cls not in openerp.osv.orm.module_class_list.get(module, []):
-                res.append(cls.createInstance(self, cr))
+                res.append(cls.create_instance(self, cr))
 
         return res
 
index 8c9b6ec..cdb8a96 100644 (file)
@@ -562,22 +562,26 @@ class MetaModel(type):
         self.module_to_models.setdefault(self._module, []).append(self)
 
 
-class orm(object):
+class Model(object):
     """ Base class for OpenERP models.
 
-    OpenERP models are created by inheriting from this class (although
-    not directly; more specifically by inheriting from osv or
-    osv_memory). The constructor is called once, usually directly
-    after the class definition, e.g.:
+    OpenERP models are created by inheriting from this class (or from
+    TransientModel)
 
-        class user(osv):
+        class user(Model):
             ...
-        user()
 
     The system will later instanciate the class once per database (on
     which the class' module is installed).
 
+    To create a class that should not be instanciated (because it is not a
+    model per se, but a class to be inherited to really create a model later),
+    the _register class attribute should be set to False.   
+
     """
+    __metaclass__ = MetaModel
+    _register = False # Set to false if the model shouldn't be automatically discovered.
+    _transient = False # True in a TransientModel
     _name = None
     _columns = {}
     _constraints = []
@@ -736,7 +740,7 @@ class orm(object):
     #       put objects in the pool var
     #
     @classmethod
-    def makeInstance(cls, pool, cr, attributes):
+    def create_instance(cls, pool, cr):
         """ Instanciate a given model.
 
         This class method instanciates the class of some model (i.e. a class
@@ -751,6 +755,9 @@ class orm(object):
         this method. This is probably unnecessary.
 
         """
+        attributes = ['_columns', '_defaults', '_inherits', '_constraints',
+            '_sql_constraints']
+
         parent_names = getattr(cls, '_inherit', None)
         if parent_names:
             if isinstance(parent_names, (str, unicode)):
@@ -807,9 +814,6 @@ class orm(object):
         This doesn't create an instance but simply register the model
         as being part of the module where it is defined.
 
-        TODO make it possible to not even have to call the constructor
-        to be registered.
-
         """
 
         # Set the module name (e.g. base, sale, accounting, ...) on the class.
@@ -2926,11 +2930,6 @@ class orm(object):
                     cr.execute(line2)
                     cr.commit()
 
-    @classmethod
-    def createInstance(cls, pool, cr):
-        return cls.makeInstance(pool, cr, ['_columns', '_defaults',
-            '_inherits', '_constraints', '_sql_constraints'])
-
     #
     # Update objects that uses this one to update their _inherits fields
     #
@@ -3068,8 +3067,6 @@ class orm(object):
 
         return res
 
-
-
     def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
         """ Read records with given ids with the given fields
 
index e848a2c..616d9e3 100644 (file)
@@ -31,7 +31,7 @@ from psycopg2 import IntegrityError, errorcodes
 from openerp.tools.config import config
 from openerp.tools.func import wraps
 from openerp.tools.translate import translate
-from openerp.osv.orm import MetaModel
+from openerp.osv.orm import MetaModel, Model
 
 
 class except_osv(Exception):
@@ -201,7 +201,7 @@ class object_proxy(netsvc.Service):
         return res
 
 
-class osv_memory(orm.orm):
+class osv_memory(Model):
     """ Deprecated class. """
     __metaclass__ = MetaModel
     _register = False # Set to false if the model shouldn't be automatically discovered.
@@ -297,11 +297,10 @@ class osv_memory(orm.orm):
         return self._search(cr, uid, domain, offset, limit, order, context, count, access_rights_uid)
 
 
-class osv(orm.orm):
+class osv(Model):
     """ Deprecated class. """
     __metaclass__ = MetaModel
     _register = False # Set to false if the model shouldn't be automatically discovered.
-    _transient = False
 
 
 def start_object_proxy():