AttributeError:'NoneType'对象没有属性'get' - Python - OpenErp

时间:2013-07-28 18:35:06

标签: python function orm openerp

我需要从另一个对象purchase.order中读取对象中的字段product.product 此字段是一个选择类型字段,因此如果此字段已选中si,则执行_get_product_available_func(('done')),这是product.product

中已声明的函数

这是purchase.order

中的选择字段
'sel_cert' : fields.selection([('si', 'Si'),('no','No')], 'Origen Certificado'),

这个函数应该从product.product

“检索”该字段
def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val

具有_get_product_available_func(('done))

的功能
def _get_product_available_func(states, what):
    def _product_available(self, cr, uid, ids, name, arg, context=None):
        return {}.fromkeys(ids, 0.0)
    return _product_available

_product_qty_available = _get_product_available_func(('done',), ('in', 'out'))
_product_certificado_qty = _get_product_available_func(('done',), ('in', 'out'))
_product_virtual_available = _get_product_available_func(('confirmed','waiting','assigned','done'), ('in', 'out'))
_product_outgoing_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('out',))
_product_incoming_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('in',))

因此,当_get_product_available_func(('done'))中的字段product.product的值为sel_cert时,我需要在purchase.order中“执行”si,但是却给了我一个错误,这是openerp服务器中的回溯:

Server Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\openerp\addons\web\session.py", line 89, in send
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 197, in execute
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\orm.py", line 3604, in read
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\orm.py", line 3724, in _read_flat
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\fields.py", line 1139, in get
AttributeError: 'NoneType' object has no attribute 'get'

也许我应该在_product_qty_available中致电_get_product_available_func

任何人都可以澄清一下吗?

提前致谢!

2 个答案:

答案 0 :(得分:2)

试试这个:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    if pids == 'si':
        val = self._get_product_available_func(('done'))
        return val

或者这个:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    if self.pool:
        obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val

答案 1 :(得分:2)

更多想法:

尝试一次:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val
    return 10

如果我们得到一个AttributeError: 'int' object has no attribute 'get',我们就知道这个函数的输出确实存在错误。

另一个想法:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids.lower() == 'si':
            return val

现在pids可能是“si”或“Si”。