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

Hello,

I want to change the view of the "Contacts/new" form when the "citizen" (I added it in my .py file as a boolean field) is ticked. When it is True, I want the "zip" field to be read-only type with default value "12345" , and when it is False just normally.

If I was not completely clear, or if you need my code, please let me know.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด
Thanks for the advice @Ibrahim ,
I added this in my code

my .py
citizens = fields.Boolean('Citizens', default=True)

@api.onchange('citizens')
def _is_citizens(self):
if self.citizens:
    self.zip = 85320
else:
    self.zip = None

my .xml
<field name="zip" position="replace">
<field
name="zip" placeholder="Zip" attrs="{'readonly':[('citizens','=',True)]}"/>
</field>


now it works as I wanted
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

If i were you, i would do this : 

1- Create a second menu called Citizens. 
2- in the action, i will add a domain [('is_citizen', '=', True)] and a context {'default_citizen': True, 'default_zip':"12345"}
3- In form view, boolean citizen will be invisible, zip will be readonly. I would think of adding a tag called "Citizen" by default.
4- in Contacts, i will add domain [('is_citizen':False)]

That is to say, Citizens will be completely separated from other Contacts.

What do you think ? 
Regards.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 22
2016
Create a dynamic form view แก้ไขแล้ว
3
ต.ค. 21
24001
Odoo - page number in qweb reports แก้ไขแล้ว
3
มิ.ย. 21
22294
2
ม.ค. 20
132
2
เม.ย. 24
14623