Odoo Help


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

on 8/21/14, 6:38 AM 2,687 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....


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

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"/>



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/21/14, 6:38 AM
Seen: 2687 times
Last updated: 9/22/17, 3:15 AM