I'm struggling with this and I'm not so clear about it.
Let's say I have a function in a class:
class my_class(osv.Model):
_name = 'my_class'
_description = 'my description'
def func (self, cr, uid, ids, name, arg, context=None):
res = dict((id, 0) for id in ids)
sur_res_obj = self.pool.get('contratos.user_input')
for id in ids:
res[id] = sur_res_obj.search(cr, uid, # SUPERUSER_ID,
[('contratos_id', '=', id), ('state', '=', 'done')],
context=context, count=True)
return res
columns = {
'function': fields.function(_get_func,
string="Number of completed Contratos", type="integer"),
my_class()
Now I want to call this very same function from another class-object:
class another_class(osv.Model):
_inherit = 'my_class'
_name = 'my_class'
columns = {
'another_field' : fields.related('function', 'state', type='char', string = "Related field which calls a function from another object"),
}
But this isn't working, I'm very confused about this, how can I call a function from another object in Odoov8?
I've heard about self.pool.get
but I'm not really sure on how to invoke it.
Any ideas?
Thanks in advance!
More information.
Since you're using odoo8 you should use the new API. from the docs
That means you don't need to explicity pass
cr
,uid
,ids
,vals
andcontext
in your methods anymore and you don't useself.pool.get()
even though it's still there for backward compatibilityenv
is dictionary-like object that is used to store instances of the Odoo models and other information so you can access other objects and their methods from any Odoo model.