Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
4984 Visualizações
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
Cancelar
Melhor resposta

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
Cancelar
Melhor resposta

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
Cancelar

Thanks a lot

Publicações relacionadas Respostas Visualizações Atividade
2
ago. 23
278
0
out. 21
1422
1
ago. 19
7782
2
ago. 19
3191
3
jan. 19
3402