Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
5008 มุมมอง
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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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/


อวตาร
ละทิ้ง

Thanks a lot

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 23
278
0
ต.ค. 21
1422
1
ส.ค. 19
7786
2
ส.ค. 19
3193
3
ม.ค. 19
3410