Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
13022 Переглядів

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
2014
3
жовт. 21
23994
3
черв. 21
22277
2
січ. 20
132
2
квіт. 24
14621