4

我需要读取一个对象中的一个字段,也就是purchase.order从另一个对象中读取product.product 这个字段是一个选择类型字段,所以如果这个字段已经si被选中,那么 do _get_product_available_func(('done'))which 是一个已经声明的函数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_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'

也许我应该打电话_product_qty_available来代替_get_product_available_func

任何人都可以澄清这一点?

提前致谢!

4

2 回答 2

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
于 2013-07-28T18:56:27.390 回答
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”。

于 2013-07-29T00:12:26.313 回答