[imp] multiple inheritancies
[odoo/odoo.git] / bin / osv / osv.py
index f6a364b..6f795fe 100644 (file)
@@ -1,22 +1,21 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
-#
+#    
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-#    $Id$
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+#    GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 #
 ##############################################################################
 
@@ -34,6 +33,8 @@ from psycopg2 import IntegrityError
 from netsvc import Logger, LOG_ERROR
 from tools.misc import UpdateableDict
 
+from tools.translate import _
+
 module_list = []
 module_class_list = {}
 class_pool = {}
@@ -64,7 +65,7 @@ class osv_pool(netsvc.Service):
             except IntegrityError, inst:
                 for key in self._sql_error.keys():
                     if key in inst[0]:
-                        self.abortResponse(1, 'Constraint Error', 'warning', self._sql_error[key])
+                        self.abortResponse(1, _('Constraint Error'), 'warning', _(self._sql_error[key]))
                 self.abortResponse(1, 'Integrity Error', 'warning', inst[0])
             except Exception, e:
                 import traceback, sys
@@ -86,7 +87,6 @@ class osv_pool(netsvc.Service):
         self._init = True
         self._init_parent = {}
         netsvc.Service.__init__(self, 'object_proxy', audience='')
-        self.joinGroup('web-services')
         self.exportMethod(self.obj_list)
         self.exportMethod(self.exec_workflow)
         self.exportMethod(self.execute)
@@ -192,9 +192,22 @@ class osv_memory(orm.orm_memory):
     #
     def createInstance(cls, pool, module, cr):
         name = hasattr(cls, '_name') and cls._name or cls._inherit
-        parent_name = hasattr(cls, '_inherit') and cls._inherit
-        if parent_name:
-            raise 'Inherit not supported in osv_memory object !'
+        parent_names = hasattr(cls, '_inherit') and cls._inherit
+        if parent_names:
+            for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]):
+                parent_class = pool.get(parent_name).__class__
+                assert pool.get(parent_name), "parent class %s does not exist in module %s !" % (parent_name, module)
+                nattr = {}
+                for s in ('_columns', '_defaults'):
+                    new = copy.copy(getattr(pool.get(parent_name), s))
+                    if hasattr(new, 'update'):
+                        new.update(cls.__dict__.get(s, {}))
+                    else:
+                        new.extend(cls.__dict__.get(s, []))
+                    nattr[s] = new
+                name = hasattr(cls, '_name') and cls._name or cls._inherit
+                cls = type(name, (cls, parent_class), nattr)
+
         obj = object.__new__(cls)
         obj.__init__(pool, cr)
         return obj
@@ -226,31 +239,32 @@ class osv(orm.orm):
     #       put objects in the pool var
     #
     def createInstance(cls, pool, module, cr):
-        parent_name = hasattr(cls, '_inherit') and cls._inherit
-        if parent_name:
-            parent_class = pool.get(parent_name).__class__
-            assert pool.get(parent_name), "parent class %s does not exist in module %s !" % (parent_name, module)
-            nattr = {}
-            for s in ('_columns', '_defaults', '_inherits', '_constraints', '_sql_constraints'):
-                new = copy.copy(getattr(pool.get(parent_name), s))
-                if hasattr(new, 'update'):
-                    new.update(cls.__dict__.get(s, {}))
-                else:
-                    if s=='_constraints':
-                        for c in cls.__dict__.get(s, []):
-                            exist = False
-                            for c2 in range(len(new)):
-                                if new[c2][2]==c[2]:
-                                    new[c2] = c
-                                    exist = True
-                                    break
-                            if not exist:
-                                new.append(c)
+        parent_names = hasattr(cls, '_inherit') and cls._inherit
+        if parent_names:
+            for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]):
+                parent_class = pool.get(parent_name).__class__
+                assert pool.get(parent_name), "parent class %s does not exist in module %s !" % (parent_name, module)
+                nattr = {}
+                for s in ('_columns', '_defaults', '_inherits', '_constraints', '_sql_constraints'):
+                    new = copy.copy(getattr(pool.get(parent_name), s))
+                    if hasattr(new, 'update'):
+                        new.update(cls.__dict__.get(s, {}))
                     else:
-                        new.extend(cls.__dict__.get(s, []))
-                nattr[s] = new
-            name = hasattr(cls, '_name') and cls._name or cls._inherit
-            cls = type(name, (cls, parent_class), nattr)
+                        if s=='_constraints':
+                            for c in cls.__dict__.get(s, []):
+                                exist = False
+                                for c2 in range(len(new)):
+                                    if new[c2][2]==c[2]:
+                                        new[c2] = c
+                                        exist = True
+                                        break
+                                if not exist:
+                                    new.append(c)
+                        else:
+                            new.extend(cls.__dict__.get(s, []))
+                    nattr[s] = new
+                name = hasattr(cls, '_name') and cls._name or cls._inherit
+                cls = type(name, (cls, parent_class), nattr)
         obj = object.__new__(cls)
         obj.__init__(pool, cr)
         return obj