Odoo Help

Welcome!

This community 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.

1

how to find the sum of all records in the form

By
aneesh ATEES Infomedia Pvt Ltd
on 8/5/15, 1:26 AM 594 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?

1

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 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
1

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, 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'),

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

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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