Merge pull request #4448 from expsa/eltayar

🎯 [REFINE] Hide search box from Many2Many/One2Many fields in fims_general_search_tree_view
This commit is contained in:
Mohamed Eltayar 2025-08-30 20:35:49 +03:00 committed by GitHub
commit 112f106b75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 50 additions and 7 deletions

View File

@ -382,7 +382,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
if (state.isFiltered && state.filteredCount >= 0) {
this.$('.oe_search_count')
.text(_t('Records: ') + state.filteredCount)
.text(_t('عدد السجلات: ') + state.filteredCount)
.removeClass('text-danger')
.show();
}
@ -390,11 +390,54 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
},
_shouldAddSearchBox: function() {
return this.arch &&
this.arch.tag === 'tree' &&
this.$el &&
this.$el.hasClass('o_list_view') &&
!this.$el.find('.oe_search_container').length;
// Basic requirements check
if (!this.arch ||
this.arch.tag !== 'tree' ||
!this.$el ||
!this.$el.hasClass('o_list_view') ||
this.$el.find('.oe_search_container').length > 0) {
return false;
}
// Check if this is inside a relational field (Many2Many/One2Many)
// Look for parent containers that indicate we're inside a form field
var $parent = this.$el.parent();
// Check for various indicators that we're inside a relational field
while ($parent.length > 0) {
// Check if parent has classes that indicate it's a field widget
if ($parent.hasClass('o_field_widget') ||
$parent.hasClass('o_field_many2many') ||
$parent.hasClass('o_field_one2many') ||
$parent.hasClass('o_field_x2many_list') ||
$parent.hasClass('o_x2many_control_panel') ||
$parent.attr('name') && $parent.closest('.o_form_view').length > 0) {
return false; // Don't show search box in relational fields
}
// Check if we're inside a form view (not a standalone list view)
if ($parent.hasClass('o_form_view') &&
this.$el.closest('.o_content').find('.o_form_view').length > 0) {
return false; // Don't show in embedded lists within forms
}
// Stop at main content area
if ($parent.hasClass('o_content') ||
$parent.hasClass('o_action_manager') ||
$parent.hasClass('o_main_content')) {
break;
}
$parent = $parent.parent();
}
// Additional check: if the list is very small (likely embedded), don't show
if (this.$el.find('tbody tr').length <= 5 &&
this.$el.closest('.o_form_view').length > 0) {
return false;
}
return true; // Show search box for standalone list views
},
_addCustomSearchBox: function() {
@ -410,7 +453,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
}
var countText = isFiltered ?
_t('Records: ') + savedCount : '';
_t('عدد السجلات: ') + savedCount : '';
var html =
'<div class="oe_search_container d-flex align-items-center">' +