Hi Arjun,
You want to get the sum of costs in expense records, that related to an expenditure right? Try like the following:
class expenditure_records(osv.Model):
_name="expenditure.records"
_columns={
'name':fields.char('Expense name'),
'cost':fields.float('Expenditure cost'),
'expense_id':fields.many2one('expenditure','Expense ID'),
}
class expenditure(osv.Model):
_name="expenditure"
def _get_total(self, cr, uid, ids,field_name, args, context=None):
expenditure_pool = self.pool.get('expenditure')
res = {}
for exp_id in self.browse(cr, uid, ids, context=context):
s_total = 0
exp = expenditure_pool.browse(cr,uid, exp_id.id, context=None)
for line in exp.expense_ids:
s_total += line.cost
res[exp_id.id] = s_total
return res
_columns={
'name':fields.char('Expense'),
'date': fields.date(string="Date"),
'expense_ids':fields.one2many('expenditure.records', 'expense_id', string="Expenses"),
'total_expense':fields.function(_get_total, type="float", string="Total Expenses")
}