ValueError:叶子中的字段'invoice_ids'无效

时间:2015-05-19 13:38:58

标签: python openerp

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

from openerp.osv import fields, osv, orm


def fnct(self, cr, uid, ids, fields, arg, context):
    total = {}
    for record in self.browse(cr,uid,ids):
        ac_obj = self.pool.get('account.invoice')
        ac_obj_id= ac_obj.search(cr, uid,[('invoice_id','=',record.invoice_id.id)], context=context)
        for rec in ac_obj.browse(cr,uid,ids,context=context):
            total += rec.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()

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

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

1 个答案:

答案 0 :(得分:0)

试试这个:

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()