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.

0

How to sum values in a one2many field and store it in a text field?

By
rosey
on 8/21/14, 6:38 AM 1,655 views

class hr_extra(osv.osv):
       

      _inherit = "res.partner"
      _columns = {
              
                  'date_join': fields.date('Date of Joining'),
                  'service_date': fields.date('Service Benefit Payment Date'),
                  'order_line': fields.one2many('hr.payment.line','order_id','Payment Structure'),
                  'amount_total': fields.function(_amount,string='Total', multi="sums",help="The total amount"),
      }

class payment_description(osv.osv):

      _name = 'payment.description'
      _description = 'payment Description'
      _columns = {
                  'name': fields.char('Description'),
                        
      }


class hr_payment_description_line(osv.osv):
    

    _name ='hr.payment.description.line'
    _columns = {
        'description' :fields.many2one('payment.description','Description'),
        'amount':fields.float('Amount'),
        'order_id':fields.many2one('rea.partner','Payment Details'),  
       }

I have a description & amount field in my one2many relation.

I want to sum all the values, that given in the tree structure.

Where should i call the sum ans dispaly function?

What is the code?

 

Please help me....

Thanks.

3

Janeesh

--Janeesh--
1641
| 4 3 4
Cochin, India
--Janeesh--

Odoo Developer

Janeesh
On 8/21/14, 6:48 AM

Hi.

function should be in 'res.partner'. Use this function.

One2many seems linked with 'hr.payment.line'. But there seems no object decalred with 'hr.payment.line'.

    def _amount_total(self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        for partner in self.browse(cr, uid, ids, context=context):
            total = 0.0
            for line in partner.order_line:
                total += line.amount
            res[partner.id] = total
        return res

'amount_total': fields.function(_amount_total, type='float', string='Total'),

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 8/21/14, 6:48 AM

In xml file tree view add sum attributes. It calculates sum all the amount values in list view

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

 

 

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/21/14, 6:38 AM
Seen: 1655 times
Last updated: 3/16/15, 8:10 AM