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

Hello, 

I'm building a new model (odoo16.0) and I have the 2 fields below. I want to make the eur_exc_rate field invisible in my form view when the currency field is set to "EUR".

currency = fields.Many2one(
comodel_name='res.currency',
string='Currency',
required=True,
help='Currency used for the bank transfer',
create=False
)
eur_exc_rate = fields.Monetary(
string='Exchange rate',
help="In case the value isn't euro, please provide the mandatory exchange rate (1 eur = X? )",
currency_field='currency'
)

I declared the fields in my form view as below: 
 
 

But id doesn't work (and can't see any error in the logs).

Any ideas?

(sorry for the newbie questions but I'm quite a beginner)

L.





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

Hi,

The attrs wont work with 'EUR' because the field is a relational field. Either you need to add the attribute as the id of EUR. attrs="{ 'invisible': [('currency', '!=',  #id of EUR currency)]}"

Or another way you can do it is by adding a boolean field and enabling that to true when you change it to EUR using onchange or compute and give attrs invisible based on that boolean field.
Keep in mind if you are using compute, add depends to the currency field and add store=True for storing the value as compute value is not stored. 

Hope it helps

อวตาร
ละทิ้ง
ผู้เขียน

Sure it helped :) I've used a Boolean (hidden) field ad it works perfectly, thanks!

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.พ. 18
3368
1
ก.พ. 16
3564
1
มี.ค. 15
4224
Replace div class on extension view แก้ไขแล้ว
1
ธ.ค. 24
1003
Can't create view (model not found) แก้ไขแล้ว
2
พ.ค. 23
7711