Odoo Help


how to find the sum of all records in the form

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
On 8/5/15, 2:28 AM


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)--

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

Learning Python..

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

You should add one more field in your file.py :

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


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

And don't forget to add this in your .xml:

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

Hope it works

Thanks & Regards

Ankit H Gandhi.

About This Community

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.

Test it now

Question tools

1 follower(s)


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