Skip to Content
Menu
This question has been flagged
1 Reply
1756 Views

  I have already set the permissions of my module,There are 3 kinds of permissions as"User","Leader","Manager":

   

<?xml version="1.0" ?>
<odoo>
<record id="module_firmware_category" model="ir.module.category">
<field name="name">firmware_module</field>
</record>

<record id="firmware_group_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_firmware_category" />
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
</record>

<record id="firmware_group_leader" model="res.groups">
<field name="name">Leader</field>
<field name="category_id" ref="module_firmware_category" />
<field name="implied_ids" eval="[(4, ref('firmware_group_user'))]" />
</record>

<record id="firmware_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_firmware_category" />
<field name="implied_ids" eval="[(4, ref('firmware_group_leader'))]" />
<field name="users" eval="[
(4, ref('base.user_root')),
(4, ref('base.user_admin'))
]" />

</record>

</odoo>

   Then in my python code I want to add a  field connected with the permissions:

user_type = fields.Selection([('Tiger_1', 'I'),('Tiger_2','II'),('Tiger_3','III')])

   I want to set user_type with 'I' when permissions is 'User',and 'II'  when permissions is 'Leader',and'III' when permissions is 'Manager',I want to this field be set automatically to avoid mistakes ,how should I add my codes?

  Thanks.    

                                  

Avatar
Discard
Best Answer

Hi,

You can make it as a compute field, then you can compute the value based on the user group, 

def _compute_user_type(self):
if self.env.user.has_group('external_id_of_firmware_group_manager'):
self.user_type = 'Tiger_3'
elif self.env.user.has_group('external_id_of_firmware_group_leader'):
self.user_type = 'Tiger_2'
elif self.env.user.has_group('external_id_of_firmware_group_user'):
self.user_type = 'Tiger_1'

user_type = fields.Selection([('Tiger_1', 'I'), ('Tiger_2', 'II'), ('Tiger_3', 'III')], compute=_compute_user_type)

Don't change the order of the if condition.

Thanks

Avatar
Discard
Author

Hi,Niyas.I have changed my code but it is not working,should I add"@api.depends('')"in front of my function?If i should,what content is supposed to write into "@api.depends('')" ?Thanks.