Skip to Content
Menu
This question has been flagged
Greetings,
 Am working on  petrol station management system, and for the same thing I need to compute fields for calculating prices and meters etc, but I do not know the code to make it work, can anyone tell me the same in details ?

 There are 2 fields which need to be computed one for subtraction and another for multiplication, I need to write the code in compute field which is present in the field making form (front end)


for subtract :

 field name : close_meter_reading - open_meter_reading = difference 

for multiply :

field name : ltr * unit_price = total_price

Avatar
Discard
Best Answer

Hi,

compute function like this,

@api.one
@api.depends('open_meter_reading','unit_price','close_meter_reading','ltr')
def _compute_amount(self):
self.difference = self.close_meter_reading - self.open_meter_reading
self.total_price = self.ltr * self.unit_price

and your field
difference = fields.Float(string='Untaxed Amount',compute='_compute_amount')
total_price = fields.Float(string='Untaxed Amount',compute='_compute_amount')
Thanks
Aswini- iWesabe
Avatar
Discard
Best Answer

If you want to enter it through the front-end, you need something like this:

Dependencies:   difference,close_meter_reading,open_meter_reading
Compute:        for record in self: 
                   record['difference'] = close_meter_reading - open_meter_reading

----

Dependencies:    total_price,ltr,unit_price 
Compute:          for record in self: 
                    record['total_price'] = ltr * unit_price 

ttps://odootricks.tips/computed-fields/


Avatar
Discard

Thanks a lot

Related Posts Replies Views Activity
2
Aug 23
278
0
Oct 21
373
1
Aug 19
6424
2
Aug 19
2228
3
Jan 19
2463