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

OnChange a value make the sum with an other

By
VodoO
on 9/6/16, 8:46 AM 152 views

Hi,


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 ?

1
VodoO
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 ?

0
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

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

3 follower(s)

Stats

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