Hi,
In OWL templates, the groups attribute doesn't work
directly as it does in traditional XML views. Instead, you need to
manage group-based visibility through the JS.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="test.ListView.Buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_list_buttons')]" position="inside">
<button type="button" t-if="state.canSeeButton" class="btn btn-primary" t-on-click="onAddNewClick">Test</button>
</xpath>
</t>
</templates>
JS:
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";
import { useState, onWillStart } from "@odoo/owl";
patch(ListController.prototype, {
setup() {
super.setup();
this.user = useService("user");
this.state = useState({
canSeeButton: false, // Initial button visibility state
});
// Check if the user belongs to the "project.group_project_manager" group
onWillStart(async () => {
this.state.canSeeButton = await this.user.hasGroup("project.group_project_manager");
});
},
onAddNewClick() {
//Add code according to the logic of the test button click
}
});
Ensure that both the JS and XML files are loaded by adding them to your module's __manifest__.py under the assets section:
'assets': {
'web.assets_backend': [
'path/to/your/js/file',
'path/to/your/xml/file',
],
},
Hope it helps