Search code examples
xmlbuttonodooodoo-10

How to hide a custom Button in tree view


]([![https://imgur.com/a/CzXG7YL

I have a custom button "View All" in my List view, i want it to be visible only to a user who have a certain group access how can i achieve it?.

I tried adding groups attribute to the button but it didn't work,

<template xml:space="preserve">
    <t t-extend="ListView.buttons">
        <t  t-jquery="button.o_list_button_add" t-operation="before">
            <button t-if="widget.modelName == 'leave.request.allocation'" type="button" class="btn btn-primary btn-sm oe_filter_button" accesskey="f" groups="hr_holidays.group_hr_holidays_manager">
                View All
            </button> 
        </t>
    </t>


Solution

  • On ListView their have render_buttons function which has on js level. So you can add the condition their to check with the user having your group or not and based on that code to display the button and hide. Here you go :

    var ListView = require('web.ListView');
    ListView.include({
        render_buttons: function($node) {
            this._super.apply(this, arguments);
            this.session.user_has_group('Your Group').then(function(has_group) {
                if (has_group) {
                    // Do Something
                } else {
                    // Do Something
                }
            });
        },
    });
    

    Thanks