[MERGE] lp:~stephane-openerp/openobject-server/call_method_inherits_objects

bzr revid: stephane@openerp.com-20100611133255-o3891oty6nra3l24
This commit is contained in:
Stephane Wirtel
2010-06-11 15:32:55 +02:00
2 changed files with 27 additions and 1 deletions
+26
View File
@@ -2694,6 +2694,32 @@ class orm(orm_template):
self._inherit_fields = res
self._inherits_reload_src()
def __getattr__(self, name):
"""
Proxies attribute accesses to the `inherits` parent so we can call methods defined on the inherited parent
(though inherits doesn't use Python inheritance).
Handles translating between local ids and remote ids.
Known issue: doesn't work correctly when using python's own super(), don't involve inherit-based inheritance
when you have inherits.
"""
for model, field in self._inherits.iteritems():
proxy = self.pool.get(model)
if hasattr(proxy, name):
attribute = getattr(proxy, name)
if not hasattr(attribute, '__call__'):
return attribute
break
else:
return super(orm, self).__getattr__(name)
def _proxy(cr, uid, ids, *args, **kwargs):
objects = self.browse(cr, uid, ids, kwargs.get('context', None))
lst = [obj[field].id for obj in objects if obj[field]]
return getattr(proxy, name)(cr, uid, lst, *args, **kwargs)
return _proxy
def fields_get(self, cr, user, fields=None, context=None):
"""
Get the description of list of fields
+1 -1
View File
@@ -132,7 +132,7 @@ class osv_pool(netsvc.Service):
raise except_osv('Access Denied', 'Private methods (such as %s) cannot be called remotely.' % (method,))
res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
if res is None:
self.logger.warning('RPC methods cannot return `None` at the moment!')
self.logger.warning('The method %s of the object %s can not return `None` at the moment!', method, obj )
cr.commit()
except Exception:
cr.rollback()