Odoo Help


OnChange a value make the sum with an other

on 9/6/16, 8:46 AM 785 views


I've 3 fields :

    'units': fields.float('Number of unities'),
'price': fields.float('Price of an Unit),
'total': fields.float('Total', readonly=True),

And a view like this :

    <field name="units" nolabel="1" on_change="onchange_calculate()"/>
<field name="price" nolabel="1" on_change="onchange_calculate()"/>
<field name="total" nolabel="1"/>

I need on change of units or price, calculate the Total,

    def onchange_calculate(self, cr, uid, ids, context=None):
        return {'value': {'total': self.units + self.price}}

but didn't work :(

Help please ?

On 9/6/16, 9:04 AM

Ok, I've found a Way with 

    'total': fields.float('Total', compute='_compute_total', readonly=True),

    @api.depends('units', price', total')
  def _compute_total(self):
  self.total= self.units * self.price

is it the right way ?

ayman mohammed adam
On 9/7/16, 3:18 AM

dear all,

i think you don't need total on depends:

@api.depends('units', price')    
def _compute_total(self): 
    self.total= self.units * self.price

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

3 follower(s)


Asked: 9/6/16, 8:46 AM
Seen: 785 times
Last updated: 9/7/16, 3:18 AM