From 9d51409bd80a713813fbdacb5855346d907a596c Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Wed, 9 Jun 2010 16:07:29 +0200 Subject: [PATCH 1/3] [IMP] Change the message for the developer if the rpc method return None bzr revid: stephane@openerp.com-20100609140729-it5qqr3qmyc5zc3p --- bin/osv/osv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/osv/osv.py b/bin/osv/osv.py index 6f85cd6d2ca..5f583b894c9 100644 --- a/bin/osv/osv.py +++ b/bin/osv/osv.py @@ -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() From 03bdb0602697a733154ecfe2394c893ad30b7858 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Wed, 9 Jun 2010 16:08:02 +0200 Subject: [PATCH 2/3] [FIX] Allow to call the methods defined in the _inherits objects bzr revid: stephane@openerp.com-20100609140802-ln5p45v1437obdkc --- bin/osv/orm.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index b166881798b..f84aff175ea 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2694,6 +2694,22 @@ class orm(orm_template): self._inherit_fields = res self._inherits_reload_src() + def __getattr__(self, name): + for model, field in self._inherits.iteritems(): + if hasattr(self.pool.get(model), name): + 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]] + proxy = self.pool.get(model) + 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 From 3aca2aea6be0a69e44f2c91121c40eb244b7b047 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Wed, 9 Jun 2010 17:43:30 +0200 Subject: [PATCH 3/3] [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 --- bin/osv/orm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index f84aff175ea..2e57e5bec31 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -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