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

How can i make field read-only when creating a record based on the group

i need to make field "VAT" readonly if user does not have 2 groups that are described in my method


@api.multi
def _check_pricelist_access_rights(self, vals):
context = self._context or {}
user_id = context.get('uid') or self.env.uid
usr = self.env['res.users'].browse(user_id)
pricelist_obj = self.env['product.pricelist']
if usr.has_group('config.group_hetlita_manager') and not usr.has_group(
'config.group_hetlita_general_manager'):
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Create a boolean computed field and in compute function, First of all check login user group and make that boolean field True if the logged in user is your desired user in that group. Now use that boolean computed field in your XML to make field readonly.

Reference:

1- How to check login user group in odoo (https://goo.gl/Ts3qqK)

2- How to visible, invisible and readonly fields (https://goo.gl/BCxCpk)

 

อวตาร
ละทิ้ง

Reference:

1- How to check login user group in odoo (https://goo.gl/Ts3qqK)

2- How to visible, invisible and readonly fields (https://goo.gl/BCxCpk)

คำตอบที่ดีที่สุด

add new boolean field with default function, based on login user you can update true or False.

Based on boolean field we can make it by using attrs attribute.

อวตาร
ละทิ้ง
ผู้เขียน

I dont need it permenantly readonly i need dynamic readonly based on group

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 24
1592
0
เม.ย. 24
1935
Make field readonly based on group แก้ไขแล้ว
9
ก.ค. 21
62804
0
ธ.ค. 19
4629
5
ธ.ค. 19
3735