简体   繁体   English

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

[英]AttributeError: 'NoneType' object has no attribute 'get' - Python - OpenErp

I need to read a field in an object, which is purchase.order , from another object product.product This field is a selection type field, so if this field has si is selected then do _get_product_available_func(('done')) which is a function already declared in product.product 我需要在一个对象中,这是读取字段purchase.order ,从另一个对象product.product该字段是一个选择类型字段,因此,如果该字段已经si选择然后做_get_product_available_func(('done'))其是已在product.product声明的函数

This is the selection field in purchase.order 这是purchase.order的选择字段

'sel_cert' : fields.selection([('si', 'Si'),('no','No')], 'Origen Certificado'),

And this the function which should "retrieve" that field from product.product 这个函数应该从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

The function which has _get_product_available_func(('done)) 具有_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',))

So, i need to "execute" _get_product_available_func(('done')) in product.product when field sel_cert in purchase.order has the value si , but is giving me an error, here's the traceback in openerp server: 所以,我需要“执行” _get_product_available_func(('done'))product.product当现场sel_certpurchase.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'

Perhaps i should call _product_qty_available instead in _get_product_available_func ? 也许我应该叫_product_qty_available而不是_get_product_available_func

Anybody could clarify this? 有人可以澄清一下吗?

Thanks in advance! 提前致谢!

Try this: 试试这个:

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

Or this: 或这个:

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

More ideas: 更多想法:

Try this for once: 试试一次:

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

If we get an AttributeError: 'int' object has no attribute 'get' , we know that the fault is indeed in the output of this function. 如果我们得到一个AttributeError: 'int' object has no attribute 'get' ,我们知道故障确实在这个函数的输出中。

Another idea: 另一个想法:

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

Now pids may be "si" or "Si". 现在pid可以是“si”或“Si”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:“ NoneType”对象在Openerp中没有属性“ fields_get” - AttributeError: 'NoneType' object has no attribute 'fields_get' in Openerp 如何修复'AttributeError:'NoneType'对象在python中没有属性'get'错误 - How to fix 'AttributeError: 'NoneType' object has no attribute 'get' error in python AttributeError: 'NoneType' object 在 Python 3 中没有属性 'get' 使用 beautifulsoup - AttributeError: 'NoneType' object has no attribute 'get' in Python 3 using beautifulsoup Python-AttributeError:“ NoneType”对象没有属性“ get_text” - Python - AttributeError: 'NoneType' object has no attribute 'get_text' Python,AttributeError:“ NoneType”对象没有属性“ show” - Python, AttributeError: 'NoneType' object has no attribute 'show' Python:AttributeError:'NoneType'对象没有属性'findNext' - Python: AttributeError: 'NoneType' object has no attribute 'findNext' Python AttributeError: 'NoneType' 对象没有属性 'fileno' - Python AttributeError: 'NoneType' object has no attribute 'fileno' Python:AttributeError:'NoneType'对象没有属性'groups' - Python: AttributeError: 'NoneType' object has no attribute 'groups' Python:AttributeError:'NoneType'对象没有属性'type' - Python: AttributeError: 'NoneType' object has no attribute 'type' Python:AttributeError:'NoneType'对象没有属性'split' - Python:AttributeError: 'NoneType' object has no attribute 'split'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM