# how to find the sum of all records in the form

By
aneesh ATEES Infomedia Pvt Ltd
on 8/5/15, 1:26 AM 1,310 views

i want to fined the sum from all the field "cost"..Whic uses the many to one field. example cost filed contains 10,20,30 in rows.i want to get the total of these rows.ie 60..how to solve this?

#### Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
3383
| 5 3 5
Sudan
--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 8/5/15, 2:28 AM

Hello,

As I understand the costs is in o2m fields, like cost_ids

You can use a functional filed 'As in the sale order, ....'

Old API:    'sum_all' : fields.function(_sum_all, type='integer', string='Sum All', multi=True),

You can check the new API from here

the _sum_all method somthing like:

def _sum_all(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for obj in self.browse(cr, uid, ids, context=context):
sum = 0
for c in obj.cost_ids:
sum += c.your_cost_field
res[obj.id] = {'sum_all': sum}
return res

@Ankit gave somehow similar answer while I'm writing this one :)

Ahmed M.Elmubarak
on 8/5/15, 2:37 AM

Thank you soo much Ahmed..

aneesh ATEES Infomedia Pvt Ltd
on 8/5/15, 2:43 AM

How to get calculate 2 fields sum?meas want to calculate total cost and qty sum

aneesh ATEES Infomedia Pvt Ltd
on 8/5/15, 4:02 AM

#### Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--

1249
| 6 5 6
Baroda, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 8/5/15, 2:16 AM

'total_line_sum':fields.function(amount_all,type='integer',string='Total Amount'),

and

def amount_all(self, cr, uid, ids, field, arg, context=None):

res = {}

for order in self.browse(cr, uid, ids, context=context):

res[order.id] = {

'total_line_sum': 0,

}

val = 0

for line in order.order_line:

val += line.cost

res[order.id] = val

return res

<field name="total_line_sum" sum='Total amount'/>

Hope it works

Thanks & Regards

Ankit H Gandhi.

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

### Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

1 follower(s)

### Stats

 Asked: 8/5/15, 1:26 AM Seen: 1310 times Last updated: 8/17/15, 4:22 AM