[FIX] Add the docstring for the __getattr__ method in the ORM

[IMP] If the object has a non-callable attribute, just return it

bzr revid: stephane@openerp.com-20100609154330-ulwlthtqfcnexkdt
This commit is contained in:
Stephane Wirtel
2010-06-09 17:43:30 +02:00
parent 03bdb06026
commit 3aca2aea6b
+12 -2
View File
@@ -2695,8 +2695,19 @@ class orm(orm_template):
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():
if hasattr(self.pool.get(model), name):
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)
@@ -2704,7 +2715,6 @@ class orm(orm_template):
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]]
proxy = self.pool.get(model)
return getattr(proxy, name)(cr, uid, lst, *args, **kwargs)
return _proxy