Python 从另一个类调用函数-字段-Odoo v8

Python 从另一个类调用函数-字段-Odoo v8,python,openerp,odoo-8,Python,Openerp,Odoo 8,我正在努力解决这个问题,但我不太清楚 假设我在一个类中有一个函数: 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.

我正在努力解决这个问题,但我不太清楚

假设我在一个类中有一个函数:

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()
现在我想从另一个类对象调用同一个函数:

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"), 
    }
但这不起作用,我对此非常困惑,我如何从Odoov8中的另一个对象调用函数

我听说过self.pool.get,但我不确定如何调用它

有什么想法吗

提前谢谢

def example(self, cr, uid, ids, context=None):
    otherClass = self.pool.get('my_class')
    ...
    otherClass.func(cr, uid, otherClassIds, name, arg, context)


既然您使用的是odoo8,就应该使用新的API。从文件中

在新的API中引入了环境的概念。主要 目标是围绕游标、用户id、, 模型、上下文、记录集和缓存

这意味着您不再需要在方法中明确地传递
cr
uid
ids
vals
context
,并且不再使用
self.pool.get()
,即使它仍然存在以实现向后兼容性


env
是一种类似字典的对象,用于存储Odoo模型的实例和其他信息,以便您可以从任何Odoo模型访问其他对象及其方法。

既然您使用的是odoo8,那么您应该使用新的API。从文件中

在新的API中引入了环境的概念。主要 目标是围绕游标、用户id、, 模型、上下文、记录集和缓存

这意味着您不再需要在方法中明确地传递
cr
uid
ids
vals
context
,并且不再使用
self.pool.get()
,即使它仍然存在以实现向后兼容性


env
是一个类似字典的对象,用于存储Odoo模型的实例和其他信息,以便您可以从任何Odoo模型访问其他对象及其方法。

感谢您提供的信息,我有点被OpenERP 7 api卡住了,我正在尝试这个,如果我有更多问题,我将打开另一个问题,非常感谢你!谢谢你提供的信息,我有点陷入OpenERP7API,我正在尝试这个,如果我有更多的麻烦,我会打开另一个问题,非常感谢!
def my_func(self):
    other_object = self.env['another_class']
    other_object.create(vals) # just using create as an example