我有这张表 student_resources ,这里有数据:
p_id p_name res_code tax base_amt date
2300 |A student |WC158 - EWT 1% |133.93 |13392.86 |2015-07-01
2300 |A student |WC158 - EWT 1% |62.50 |6250.00 |2015-07-01
901 |B student |WC158 - EWT 1% |8.31 |830.58 |2015-06-09
2831 |C student |WC160 - EWT 2% |2736.84 |136842.11 |2015-06-04
905 |D student |WC158 - EWT 1% |31.25 |3125.00 |2015-06-16
905 |D student |WC158 - EWT 1% |31.25 |3125.00 |2015-06-29
905 |D student |WC158 - EWT 1% |31.25 |3125.00 |2015-06-29
905 |D student |WC158 - EWT 1% |26.79 |2678.57 |2015-06-16
959 |G student |WC158 - EWT 1% |114.29 |11428.57 |2015-01-10
959 |G student |WC158 - EWT 1% |478.90 |47890.18 |2015-01-20
2424 |L student |WC158 - EWT 1% |45.54 |4553.58 |2015-03-03
在我的班级 student_resources_report 中我有这个定义:
...
cr.execute("select es.id from student_resource es where date >= '"+str(ewt.date_from)+"' and date <= '"+str(ewt.date_to)+"'")
source_id = cr.fetchall()
_logger.info("\n\t\t\tSource ... %s"%(str(source_id)))
s_id = self.pool.get('student.resource').search(cr,uid,[('id','in',source_id)])
#_logger.info("\n\t\t\tSource in a list ... %s"%(str(s_id)))
for resource in self.pool.get('student.resource').browse(cr,uid,s_id,context=context):
if 'WC158' in resource.res_code:
atc_code = 'WC158'
nature = 'NOTEBOOK'
seq = 1
base += resource.base_amt
amount += resource.tax
elif 'WC160' in resource.res_code:
atc_code = 'WC160'
nature = 'BACKPACK'
base += resource.base_amt
amount += resource.tax
seq = 2
elif 'WC010' in resource.res_code:
atc_code = 'WC010'
nature = 'COLOR'
base = resource.base_amt
amount = resource.tax
seq = 3
elif 'WC140' in ait.res_code:
atc_code = 'WC140'
nature = 'BOOKS'
base = resource.base_amt
amount = resource.tax
seq = 4
percent = self._get_ewt_percentage(cr, uid, ids, resource.res_code, context=context)
partner_id = resource.partner_id.id
dictionary = {
'name' : ewt.id,
'parent_id' : ewt.id,
'partner_id' : partner_id,
'atc_code' : atc_code,
'nature_of_resource' : nature,
'base_amount' : base,
'percentage' : percent,
'tax_amount' : amount,
'seq' : seq,
}
self.pool.get('student.resource.line').create(cr, uid, dictionary, context=context)
list = self.pool.get('student.resource.line').search(cr,uid,[('parent_id','=',ewt.id)])
lines = [line.id if line.id else False for line in self.pool.get('student.resource.line').browse(cr,uid,list,context=context)]
value = {
"value" : {
'name' : 'Student Resources Report',
"ewt_line" : lines
}
}
return value
我无法理解的是,当我的视图被渲染时,它的输出只是这样:
Seq Stud Code Nature Base Amt Percent Tax
1 B student WC158 NOTEBOOK 830.58 1.0 8.31
1 D student WC158 NOTEBOOK 2678.57 1.0 26.79
2 C student WC160 BACKPACK 136842.11 2.0 2736.84
我的预期是下图,这是我想要的输出,即获得特定学生的所有 base_amount 和 tax_amount 的总和:
Seq Stud Code Nature Base Amt Percent Tax
1 B student WC158 NOTEBOOK 830.58 1.0 8.31
1 D student WC158 NOTEBOOK 12053.57 1.0 120.54 ----> since (3125.00+3125.00+3125.00+2678.57) = 12053.57 and (31.25+31.25+31.25+26.79) = 120.54
2 C student WC160 BACKPACK 136842.11 2.0 2736.84
非常感谢任何帮助/建议/评论