in Odoo 8.0, I am trying to calculate the sum of payments made by a customer according to the customer's id. I wrote the following code but this hasn't helped at all. If any suggestions or help, you are more than welcome
def _get_sum_invoices(self, cr, uid, ids, field_name, arg, context=None):
res = dict(map(lambda x: (x, 0), ids))
# The current user may not have access rights for sale orders
try:
for partner in self.browse(cr, uid, ids, context):
setOfInvoices = self.env['account.invoice'].search([('id', "in", partner.invoice_ids)])
total = 0
for invoice in setOfInvoices:
total += invoice.amount
res[partner.id] = total
except:
pass
return res
_columns = {
'sum_payments': fields.function(_get_sum_pay, string='# SUM', type='float'),
'total': fields.one2many('account.invoice', 'partner_id','Sum Of Payments')
}