I have this table student_resources and here are data that it hold:
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
and in my class student_resources_report i have this definition:
...
atc_code = nature = ''
_logger.info("\n\t\t\tI was called. My method name is %s"%(str('generate_student_resource_report')))
base = amount = percent = 0.00
for ewt in self.browse(cr,uid,ids,context):
old_history = stud_re_report_line_obj.search(cr, uid, [('parent_id','=',ewt.id)],context=context)
if old_history:
stud_re_report_line_obj.unlink(cr, uid, old_history,context=context)
lines = student_resource_obj.search(cr, uid,[('date', '>=', ewt.date_from),('date', '<=', ewt.date_to)])
for resource in student_resource_obj.browse(cr,uid,lines,context=context):
if 'WC158' in resource.name:
atc_code = 'WC158'
nature = 'NOTBOOK'
seq = 1
base += resource.base_amount
amount += resource.tax_amount
elif 'WC160' in resource.name:
atc_code = 'WC160'
nature = 'BACKPACK'
base += resource.base_amount
amount += resource.tax_amount
seq = 2
elif 'WC010' in resource.name:
atc_code = 'WC010'
nature = 'COLOR'
base += resource.base_amount
amount += resource.tax_amount
seq = 3
elif 'WC140' in ait.name:
atc_code = 'WC140'
nature = 'BOOKS'
base += resource.base_amount
amount += resource.tax_amount
seq = 4
percent = self._get_percentage(cr, uid, ids, resource.name, 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' : nature,
'base_amt' : base,
'percent' : percent,
'tax_amt' : amount,
'seq' : seq,
}
stud_re_report_line_obj.create(cr, uid, dictionary, context=context)
list = stud_re_report_line_obj.search(cr,uid,[('parent_id','=',ewt.id)])
lines = [line.id if line.id else False for line in stud_re_report_line_obj.browse(cr,uid,list,context=context)]
value = {
"value" : {
'name' : 'Student Resource Report',
"ewt_line" : lines
}
}
return value
What i can't understand is that when my view is being rendered it output only looks like this:
Seq Stud Code Nature Base Amt Percent Tax 1 B student WC158 NOTEBOOK 830.58 1.0 8.31 1 D student WC158 NOTEBOOK 3509.15 1.0 35.10 ---> (it adds 2678.57 and 830.58, which must not because it's p_id(student) is not the same (I don't know why)) 2 C student WC160 BACKPACK 136842.11 2.0 2736.84
What i expected was the figure below and this is my desired output, that is to get the sum of all base_amt and tax_amt of particular student :
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
Actually, this is somehow related with my 2 previous questions, but used sql statement instead and i get another error.
Any help/suggestions/comments is very much appreciated