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

Hello,

I have 2 fields: Phone and is_created 


- I want the user for the first time can add the phone, but can not update it after saving 

- and is_created field is created on save (i know how to do that) 


How can I make is_created only visible for the admin user 

And phone only the admin can update it


Thank you for your help

形象
丢弃
最佳答案

Hi,

is_created only visible for the admin user
Add the groups parameter for the field

is_created is_created = fields.Date(groups="base.group_system")

phone only the admin can update it

First we need to create a boolean field and assign default values for that field based on the user's group.

is_created_test = fields.Boolean(default=lambda self: self._default_is_created_test(), store=True)

def _default_is_created_test(self):
 if self.env.user.has_group('base.group_system'):
    return True
 else:
     return False

add that field in xml

<field name="is_created_test"/>


then set the attributes like this

<field name="phone" attrs="{'readonly': [('is_created_test', '!=', True)]}"/>




Regards

形象
丢弃
相关帖文 回复 查看 活动
1
10月 24
3262
9
7月 21
63175
8
11月 19
7855
3
8月 24
16029
0
5月 23
1814