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

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 24
3248
Make field readonly based on group แก้ไขแล้ว
9
ก.ค. 21
63174
8
พ.ย. 19
7852
3
ส.ค. 24
16027
0
พ.ค. 23
1814