Hello,
How can I restrict certain users from being able to remove the default filter from the Search view in Odoo 17?
Thank you!
Hello,
How can I restrict certain users from being able to remove the default filter from the Search view in Odoo 17?
Thank you!
Hi Anush Soghomonyan,
This is not possible at the Studio level because Studio does not provide control over the SearchModel behavior in the web client. A custom module is required.
One approach is to create a security group and patch the Odoo 17 SearchModel to prevent users in that group from removing default search filters.
1. Create a Security Group
<!-- security/security.xml -->
<record id="group_search_filter_manager" model="res.groups">
<field name="name">Restricted From Removing Default Search Filters</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
Assign this group to users who should be restricted from removing default filters.
2. Patch the SearchModel
/** @odoo-module **/
import { SearchModel } from "@web/search/search_model";
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
patch(SearchModel.prototype, {
async load(config) {
await super.load(config);
// Store default filters loaded initially
this._defaultGroupIds = new Set(
this.query.map((q) => this.searchItems[q.searchItemId]?.groupId)
);
// Check whether current user is restricted
this._canRemoveDefaultFilters = await this.userService.hasGroup(
"your_module.group_search_filter_manager"
).then((isRestricted) => !isRestricted);
},
deactivateGroup(groupId) {
if (
!this._canRemoveDefaultFilters &&
this._defaultGroupIds?.has(groupId)
) {
this.env.services.notification.add(
_t("You are not allowed to remove default filters."),
{ type: "warning" }
);
return;
}
return super.deactivateGroup(groupId);
},
});
3. Load the JS File in Assets
Add the JS file to the backend assets in your module manifest:
'assets': {
'web.assets_backend': [
'your_module/static/src/js/search_model_patch.js',
],
},Result:
If you have any questions, feel free to reach out.
Hope this helps!
Thanks and Regards,
Email: odoo@aktivsoftware.com
Thank you!
Therefore, in a standard Odoo 17 Online environment, it is not possible to prevent selected users from removing default search filters. If the goal is to restrict which records users can see, using appropriate security groups and record rules would be the recommended approach.
Hope it helps
Thank you!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up| Related Posts | Replies | Views | Activity | |
|---|---|---|---|---|
|
2
Mar 26
|
2568 | |||
|
1
Sep 25
|
4088 | |||
|
3
Jul 25
|
12257 | |||
|
1
May 25
|
4091 | |||
|
2
Jan 25
|
4894 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.
Hello
Yes it is possible but you need required small customization for that.
I can write small code at Studio level. If that’s convenient, I would appreciate it if you could provide the code, or explain what needs to be done.
It required to update JS file so It is not possible through studio customization.