Skip to Content
Menu
This question has been flagged
4 Replies
9855 Views

how can i restrict the activate/archive Button (right top of the Products-Detail-Page) to a specifiv group?

i just could use xpath to make it invisible but i tried to set readonly to //button[@name='toggle_active'] and also //button[@name='toggle_active']  but it seems not to work.


any help?


Avatar
Discard
Best Answer

Hi Jack,

You can add the group directly to a button.

Check this example code.

<button name="toggle_active" groups="base.group_no_one" type="object" class="oe_stat_button" icon="fa-archive">
    <field name="active" widget="boolean_button" options="{"terminology": "archive"}"/>
</button>

Here instead of groups="base.group_no_one" you can use your group.


Thanks

Avatar
Discard
Author

but how can i simply make it readonly for non authorized users? they should see that it is currently archived but they should not be able to reactivate it. the readonly attribute did not work for me

For fields, you can't make it readonly for some groups directly like doing for models. you can only hide them.

There are indirect ways. you can do this by inherit the write function and checking the condition as per your need.

Best Answer

Hi, 

This is actually possible regardless of what Avinash says. The idea is to add the attribute disabled="true" to your button. 

In order to do that ( since it's based on conditions like the specific group ), you will need to follow these steps : 

1- Js : call the FormController and specifically function renderButtons.
2- The conditions you need to check are : your model because if not it these changes would apply on all toggle_active buttons. 
3- RPC call to check the user's groups in python side ( very simple solution ). The function call will return True is user has group ( to whom the button won't be 'clickable' )
4- in JS, if result, then :  point your button with a specific class in XML to be easily identified and then : $('.o-your-class-here').prop('disabled', true);

All these steps are a little bit complicated to put together. So even it's true to be possible, you may consider just Hiding the button with groups. It's much easier.

Upvote if this helps.
Regards.

Avatar
Discard
Best Answer

Inherited the 'active' field and add groups and specify which groups you want to have access to it.

(Note: For Action -> Archive)

For example:

from odoo import api, fields, models

class HrAppraisalInherited(models.Model):
   _inherit = "hr.appraisal"

   active = fields.Boolean(groups="hr.group_hr_manager")
Avatar
Discard
Best Answer

Please try this:

https://www.linkedin.com/pulse/how-hide-archiveunarchive-dropdown-specific-users-groups-yadav/?trk=articles_directory

This need a bit of modify to work in odoo 15 and above, but it's the correct way

Avatar
Discard