Odoo Help


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.


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

on 8/21/14, 6:38 AM 1,486 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'),
        '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....




| 4 3 4
Cochin, India

Odoo Developer

On 8/21/14, 6:48 AM


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



| 5 4 7
Bikaner, India

OpenERP Devloper at SunARC Technology

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)


Asked: 8/21/14, 6:38 AM
Seen: 1486 times
Last updated: 3/16/15, 8:10 AM