From 87a8c01e853cbb302fbcb0f3c44c36736ce7378c Mon Sep 17 00:00:00 2001 From: Mohamed Eltayar <152964073+maltayyar2@users.noreply.github.com> Date: Sat, 30 Aug 2025 21:01:30 +0300 Subject: [PATCH] Fix: Prevent search box in Many2Many/One2Many fields by checking parentID --- .../static/src/js/list_search.js | 46 ++++--------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js b/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js index 93bad4ea9..fa584496e 100644 --- a/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js +++ b/odex25_base/fims_general_search_tree_view/static/src/js/list_search.js @@ -390,7 +390,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { }, _shouldAddSearchBox: function() { - // Basic requirements check + // التحقق من المتطلبات الأساسية if (!this.arch || this.arch.tag !== 'tree' || !this.$el || @@ -399,45 +399,19 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) { 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 - } + // الحل الدقيق الوحيد المؤكد: + // فحص الـ model state للـ ListRenderer + var controller = this.getParent(); + if (controller && controller.model && controller.handle) { + var state = controller.model.get(controller.handle); - // 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 + // إذا كان parentID موجود، فهذا يعني أن الـ list embedded داخل relational field + if (state && state.parentID) { + return false; // لا نظهر البحث للـ embedded lists } - - // 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 + return true; // نظهر البحث للـ standalone lists فقط }, _addCustomSearchBox: function() {