Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
16927 Представления

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


Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
мая 24
2335
3
апр. 23
11821
1
апр. 23
14834
9
дек. 23
24087
1
мая 20
6573