Skip to Content
Menu
You need to be registered to interact with the community.
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
Opusti
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
Opusti
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
Opusti

Thanks a lot

Related Posts Odgovori Prikazi Aktivnost
2
avg. 23
278
0
okt. 21
1422
1
avg. 19
7784
2
avg. 19
3191
3
jan. 19
3402