Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:叶中的“发票ID”字段无效_Python_Openerp - Fatal编程技术网

Python ValueError:叶中的“发票ID”字段无效

Python ValueError:叶中的“发票ID”字段无效,python,openerp,Python,Openerp,我是新来的。我创建了一个模块Testbase,它继承了res.partner模块。我运行此模块时出错。我的Python文件是testbase.py文件: 运行此代码时,我收到以下错误: ValueError: Invalid field 'invoice_ids' in leaf "<osv.ExtendedLeaf: ('invoice_ids', 'in', [browse_record(account.invoice.line, 1)]) on account_invoice (ct

我是新来的。我创建了一个模块Testbase,它继承了res.partner模块。我运行此模块时出错。我的Python文件是testbase.py文件:

运行此代码时,我收到以下错误:

ValueError: Invalid field 'invoice_ids' in leaf "<osv.ExtendedLeaf: ('invoice_ids', 'in', [browse_record(account.invoice.line, 1)]) on account_invoice (ctx: )>" 
试试这个:

from openerp.osv import fields, osv, orm

def fnct(self, cr, uid, ids, fields, arg, context={}):
    total = {}
    for partner_id in ids:
        sub_total=0.0
        ac_obj = self.pool.get('account.invoice')
        ac_obj_ids= ac_obj.search(cr, uid,[('partner_id','=',partner_id)], context=context)
        for rec in ac_obj.browse(cr,uid,ac_obj_ids,context=context):
            sub_total += rec.total
        total[partner_id] = sub_total
    return total

class testbase(osv.osv):
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'points' : fields.function(fnct, method=True, string='Points',type='char', readonly = True, help="it indicates to how much points a customer earned"),
    }
testbase()

谢谢@Emipro技术。我和你一样进行更改,但当我确认销售时,我使用了一个客户会计->客户,它会引发一个错误值错误:叶中的无效字段“invoice\u id”(如果可能),然后给出完整的调试日志。解决问题更有帮助。您可能在表单视图或搜索视图中使用了发票id字段…谢谢@Emipro Technologies,太长了,所以请将其作为答案。当然我会@Emipro Technologies根据您的日志,我是对的。您已在搜索视图中放置了一个名为invoice\u id的字段。这会导致错误。请删除它,然后在没有该字段的情况下进行测试。
from openerp.osv import fields, osv, orm

def fnct(self, cr, uid, ids, fields, arg, context={}):
    total = {}
    for partner_id in ids:
        sub_total=0.0
        ac_obj = self.pool.get('account.invoice')
        ac_obj_ids= ac_obj.search(cr, uid,[('partner_id','=',partner_id)], context=context)
        for rec in ac_obj.browse(cr,uid,ac_obj_ids,context=context):
            sub_total += rec.total
        total[partner_id] = sub_total
    return total

class testbase(osv.osv):
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'points' : fields.function(fnct, method=True, string='Points',type='char', readonly = True, help="it indicates to how much points a customer earned"),
    }
testbase()