我是OpenERP的新手,我正在尝试创建一个函数来查找在会话中注册的学生百分比。到目前为止,函数compute_percentage应该找到每个会话的与会者数量 我得到的错误是:AttributeError:'在browse_record中找不到字段attendee_id(attendee.attendee,3)'。我的代码中缺少什么?希望你能帮忙,我已经在这整整3天了!
class session(osv.osv):
_name = 'session.session'
def compute_percentage(self, cr, uid, ids, fields, arg, context=None):
record_id=ids[0]
res={record_id:0.0}
# percentage= (attendees/seats)*100
current_form_object=self.browse(cr, uid, ids)
for r in current_form_object:
other_form_object=self.pool.get("attendee.attendee").browse(cr,uid,ids)
total= [item.attendee_id for item in other_form_object]
res[item.id]=len(total)
print res
return res
_columns = {
'name': fields.char('Session Title', size = 50, required=True),
'instructor_id':fields.many2one('res.partner', 'Instructor',ondelete="set null"),
'start_date': fields.date('Start Date'),
'duration': fields.integer('Duration'),
'seats': fields.float('Number of Seats'),
'attendee_ids':fields.one2many('attendee.attendee','attendee_id', 'Attendees'),
'percentage':fields.function(compute_percentage, type='float', method=True, store=False, string='% of Headcount'),
}
session()
class attendee(osv.osv):
_name = 'attendee.attendee'
_columns = {
'name':fields.char('Attendee Name'),
'attendee_id':fields.many2one('res.partner','Attendee', ondelete="set null"),
'session_id':fields.many2one('session.session', 'Session', ondelete="set null"),
}
attendee()
答案 0 :(得分:0)
以下是compute_percentage的修改代码,如果您喜欢这个,可能会有效
def compute_percentage(self, cr, uid, ids, fields, arg, context=None):
res = {}
total =0.0
for r in self.browse(cr, uid, ids):
for line in r.attendee_ids:
total+=1
res[item.id]=total
print res
return res
供参考检查sale.py _amount_all功能