Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2177 มุมมอง


@api.onchange('uom_id.id')
def onchange_unite(self):
if self.uom_id.id == 'M3':
self.quantity = self.quantity / 700

elif self.uom_id.id == 't':
self.quantity = self.quantity / 1000

else :
self.quantity = self.quantity / 1


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

Hi,

In your function it seems in the if condition your are checking the id of the chosen unit of measure,  the id will always a integer value, might be M3, t will be the names of the unit of measure. 


If they are the names of the Unit of measure,  instead of the self.uom_id.id in the conditions use self.uom_id.name . Also change this @api.onchange('uom_id.id') to  @api.onchange('uom_id')


Also by putting some print statements or logger messages inside the function, make sure that the function is getting executed during the onchange.


Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

thank you my brother Niyas Raphy but i have a  question if in odoo 11 there is a function to update quantity when change unite of mesure because i try a lot of solution but no results ??

อวตาร
ละทิ้ง

is the above function is not working ? there might be some default function which work on this onchange, you can check the code by searching the onchange of this field and rewrite that function or super it. By putting a print statement in this function and see whether it is working or not

ผู้เขียน

thank you so much my brother i will try this solution and tell you if it work