2016-07-27 76 views
0

从res.company获取数据时遇到问题 有人能告诉我为什么这段代码给我一个错误吗?AttributeError:'NoneType'对象没有属性'browse'

def refresh_calculation(self,cr,uid,ids, context=None): 
     company_pool = self.pool.get('res.company') 
     company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'res.company', context=context) 
     loan = company_pool.browse(cr, uid, company_id) 

     administration_fee = loan.administration_fee.id 
     interest_rate = percentage_to_float(loan.interest_rate.id) 
     trade_mark = percentage_to_float(loan.trade_mark.id) 

     return self.write(cr, uid, ids, {'monthly_installment': administration_fee}) 

由于提前,

回答

3

self.pool.get将返回无, “res.company”。如果这是一个字典,它没有这个键。

+0

您能告诉我该怎么办?我是openerp的新手。谢谢, – weelDaw

+0

这是Python范围内的正确答案。在openerp作用域中,当池无法从池中获取res.company时,openerp安装有些问题,因为这是openerp基本的orm类。 – CZoellner

+0

好的谢谢。 :) – weelDaw

1

您的company_pool参数由于某种原因存储在None中。为了防止这个错误,一个简单的if语句就足够了。

if company_pool is not None: 
    # doSomething 
else 
    print "You did not enter the parameter res.company" 
+0

错误仍然出现 – weelDaw

+0

现在尝试使用它。用company_id开头的代码替换dosomething –

2

company_pool返回值None。因为self.pool没有键值'res.company'。当使用company_pool.browse(...)时 - >None.browse(...)被调用,并且这会引发错误,因为NoneType没有浏览属性。在调用refresh_calculation(...)之前填写值地图pool或在访问此功能之前执行无检查 - >if company_pool is not None:

+0

我将如何获得关键值'res.company'? – weelDaw

+0

在调用函数之前,在访问该函数之前执行无检查或调用self.pool .__ setitem __('res.company','') –

+0

我可以看到完整的代码吗? – weelDaw