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

I have some custom code which should only be available for a specific user group. This is triggered by an action trough the 'more' button in the listview.

Is there a way to add a group to this action so it is only visible for the right user group?

Exemple code:

<record id="generate_invoices_action" model="ir.actions.server">
    <field name="name">Generate invoices</field>
    <field name="model_id" ref="model_my_model"/>
    <field name="state">code</field>
    <field name="code">
        if env.context.get('active_ids'):model.browse(context['active_ids']).generate_invoices()
    </field>
</record>
<record id="generate_invoices" model="ir.values">
    <field name="name">generate_invoices</field>
    <field name="model">my.model</field>
    <field name="key">action</field>
    <field name="key2">client_action_multi</field>
    <field name="value" eval="'ir.actions.server,%d'%generate_invoices_action"/>
</record>
形象
丢弃
最佳答案

Hi,

if I'm not mistaken, you can restrict rights for "ir.actions.server" (in comparison to "ir.actions.act_window"). There are no fields for user groups! So, visibility would be for everyone.

However, you may restrict users for execution right in your code:

<field name="code">
    group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base','user_group')[1]
    user_group = self.pool("res.users").browse(cr, uid, [uid]).groups_id.ids
    if group_id in user_group:
         if env.context.get('active_ids'):model.browse(context['active_ids']).generate_invoices()
</field>


形象
丢弃
最佳答案

here is something more recent wich work for me :

ack_workflows = name of my module
group_manager = my group name
generate_project_task() = my method name
@api.multi
def generate_task_action(self):
# On test l'appartenance au groupe
flag = self.env['res.users'].has_group('ack_workflows.group_manager')
if flag:
order.generate_project_task()
else:
raise UserError('Vous n\'avez pas les droits pour réaliser cette action')

very good link for the security : 
 https://www.odoo.yenthevg.com/creating-security-groups-odoo/
import for raise UserError :
from odoo.exceptions import UserError
I hope it useful


形象
丢弃
相关帖文 回复 查看 活动
2
5月 24
2339
3
4月 23
11826
1
4月 23
14838
9
12月 23
24094
1
5月 20
6574