Skip to Content
Menú
This question has been flagged
2 Respostes
16934 Vistes

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>
Avatar
Descartar
Best Answer

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>


Avatar
Descartar
Best Answer

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


Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de maig 24
2339
3
d’abr. 23
11826
1
d’abr. 23
14840
9
de des. 23
24097
1
de maig 20
6575