Reputation: 116
I am new in openerp
. I have created a module Testbase
and that is inherited res.partner
module. I get an error when I run this module. My Python file is testbase.py
file:
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()
When I run this code I receive the following error:
ValueError: Invalid field 'invoice_ids' in leaf "<osv.ExtendedLeaf: ('invoice_ids', 'in', [browse_record(account.invoice.line, 1)]) on account_invoice (ctx: )>"
Upvotes: 0
Views: 5188
Reputation: 14746
Try with this:
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()
Upvotes: 0