This question has been flagged
2 Replies
4803 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 ?

Avatar
Discard
Author Best Answer

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 ?

Avatar
Discard
Best Answer

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

Avatar
Discard