跳至内容
菜单
此问题已终结
2 回复
12625 查看

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.

形象
丢弃
相关帖文 回复 查看 活动
0
3月 22
1659
3
10月 21
23340
3
6月 21
21314
2
1月 20
132
2
4月 24
14105