Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
5002 Ansichten
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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen

Thanks a lot

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 23
278
0
Okt. 21
1422
1
Aug. 19
7784
2
Aug. 19
3191
3
Jan. 19
3404