Skip to Content
Menu
This question has been flagged
2 Replies
11840 Views

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.

Avatar
Discard
Author Best Answer
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
Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 22
1221
3
Oct 21
21987
3
Jun 21
19585
2
Jan 20
132
2
Apr 24
13285