Merge pull request #4433 from expsa/eltayar
Fix: Enhanced Search Module v2.1 - Critical Issues Resolved
This commit is contained in:
commit
1ad600302c
|
|
@ -205,10 +205,10 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
|
|
||||||
// IMPROVED: Use proper domain and controller approach
|
// IMPROVED: Use proper domain and controller approach
|
||||||
return self._performServerSearch(value).then(function(results) {
|
return self._performServerSearch(value).then(function(results) {
|
||||||
if (results && results.records) {
|
if (results && results.records !== undefined) {
|
||||||
self._updateStateWithResults(results);
|
self._updateStateWithResults(results);
|
||||||
// CRITICAL: Trigger proper re-render using Odoo's mechanism
|
// CRITICAL FIX: Force complete re-render
|
||||||
return self._triggerProperUpdate();
|
return self._forceCompleteRerender();
|
||||||
}
|
}
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.error('Server search failed:', error);
|
console.error('Server search failed:', error);
|
||||||
|
|
@ -320,29 +320,30 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NEW: Trigger proper update using Odoo's mechanisms
|
* CRITICAL FIX: Force complete re-render to show filtered results
|
||||||
*/
|
*/
|
||||||
_triggerProperUpdate: function() {
|
_forceCompleteRerender: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log('=== TRIGGER PROPER UPDATE ===');
|
console.log('=== FORCE COMPLETE RE-RENDER ===');
|
||||||
|
|
||||||
// Method 1: Use _renderRows if available (most compatible)
|
|
||||||
if (this._renderRows && typeof this._renderRows === 'function') {
|
|
||||||
try {
|
try {
|
||||||
|
// Method 1: Try using _renderRows if available (most reliable)
|
||||||
|
if (this._renderRows && typeof this._renderRows === 'function') {
|
||||||
console.log('Using _renderRows method');
|
console.log('Using _renderRows method');
|
||||||
return this._renderRows().then(function() {
|
return this._renderRows().then(function() {
|
||||||
self._updatePager();
|
self._updatePager();
|
||||||
console.log('✓ _renderRows update completed');
|
console.log('✓ _renderRows update completed');
|
||||||
|
return Promise.resolve();
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.warn('_renderRows failed, trying fallback:', error);
|
||||||
|
return self._fallbackRerender();
|
||||||
});
|
});
|
||||||
} catch (err) {
|
|
||||||
console.warn('_renderRows failed:', err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method 2: Use _renderBody if available
|
// Method 2: Try using _renderBody if available
|
||||||
if (this._renderBody && typeof this._renderBody === 'function') {
|
if (this._renderBody && typeof this._renderBody === 'function') {
|
||||||
try {
|
|
||||||
console.log('Using _renderBody method');
|
console.log('Using _renderBody method');
|
||||||
|
try {
|
||||||
var $body = this._renderBody();
|
var $body = this._renderBody();
|
||||||
if ($body && $body.length) {
|
if ($body && $body.length) {
|
||||||
this.$('tbody').replaceWith($body);
|
this.$('tbody').replaceWith($body);
|
||||||
|
|
@ -355,10 +356,123 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method 3: Trigger view update event (safest fallback)
|
// Method 3: Manual DOM manipulation (most reliable fallback)
|
||||||
console.log('Using event trigger method');
|
return this._fallbackRerender();
|
||||||
this.trigger_up('reload');
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Complete re-render failed:', error);
|
||||||
|
return this._fallbackRerender();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NEW: Fallback re-render method
|
||||||
|
*/
|
||||||
|
_fallbackRerender: function() {
|
||||||
|
var self = this;
|
||||||
|
console.log('Using fallback re-render method');
|
||||||
|
|
||||||
|
// Clear existing rows
|
||||||
|
this.$('tbody .o_data_row').remove();
|
||||||
|
this.$('.oe_no_results').remove();
|
||||||
|
|
||||||
|
// Check if we have filtered results
|
||||||
|
if (!this.state || !this.state.data || !this.state.data.records) {
|
||||||
|
console.warn('No state data available for rendering');
|
||||||
|
this._showNoResults();
|
||||||
|
this._updatePager();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
var records = this.state.data.records;
|
||||||
|
console.log('Rendering', records.length, 'filtered records');
|
||||||
|
|
||||||
|
if (records.length === 0) {
|
||||||
|
this._showNoResults();
|
||||||
|
} else {
|
||||||
|
// Create rows for filtered records using Odoo's method
|
||||||
|
this._createFilteredRows(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._updatePager();
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NEW: Create filtered rows using proper Odoo rendering
|
||||||
|
*/
|
||||||
|
_createFilteredRows: function(records) {
|
||||||
|
var self = this;
|
||||||
|
var $tbody = this.$('tbody');
|
||||||
|
|
||||||
|
records.forEach(function(record, index) {
|
||||||
|
try {
|
||||||
|
// Use Odoo's internal row rendering if available
|
||||||
|
var $row;
|
||||||
|
if (self._renderRow && typeof self._renderRow === 'function') {
|
||||||
|
$row = $(self._renderRow(record, index));
|
||||||
|
} else {
|
||||||
|
// Fallback to manual row creation
|
||||||
|
$row = self._createBasicRow(record, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row && $row.length) {
|
||||||
|
$tbody.append($row);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to create row for record', record.id, ':', error);
|
||||||
|
// Create basic fallback row
|
||||||
|
var $fallbackRow = self._createBasicRow(record, index);
|
||||||
|
if ($fallbackRow && $fallbackRow.length) {
|
||||||
|
$tbody.append($fallbackRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Created', records.length, 'filtered rows');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NEW: Create basic row as fallback
|
||||||
|
*/
|
||||||
|
_createBasicRow: function(record, index) {
|
||||||
|
var self = this;
|
||||||
|
var $row = $('<tr class="o_data_row"></tr>');
|
||||||
|
|
||||||
|
// Set proper Odoo attributes
|
||||||
|
$row.attr('data-id', record.res_id || record.id);
|
||||||
|
$row.data('id', record.res_id || record.id);
|
||||||
|
|
||||||
|
// Add record data for proper event handling
|
||||||
|
$row.data('record', record);
|
||||||
|
|
||||||
|
// Create cells based on columns
|
||||||
|
if (this.columns && this.columns.length > 0) {
|
||||||
|
this.columns.forEach(function(col) {
|
||||||
|
if (!col.invisible && col.attrs && col.attrs.name) {
|
||||||
|
var fieldValue = record.data ? record.data[col.attrs.name] : null;
|
||||||
|
var $cell = $('<td class="o_data_cell"></td>');
|
||||||
|
|
||||||
|
// Basic field value display
|
||||||
|
if (fieldValue !== null && fieldValue !== undefined) {
|
||||||
|
if (Array.isArray(fieldValue) && fieldValue.length >= 2) {
|
||||||
|
// Many2one field [id, name]
|
||||||
|
$cell.text(fieldValue[1]);
|
||||||
|
} else {
|
||||||
|
$cell.text(String(fieldValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$row.append($cell);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Simple fallback
|
||||||
|
var displayName = record.data ? (record.data.display_name || record.data.name || record.id) : record.id;
|
||||||
|
$row.append($('<td class="o_data_cell"></td>').text(displayName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -439,6 +553,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
* NEW: Internal clear search logic
|
* NEW: Internal clear search logic
|
||||||
*/
|
*/
|
||||||
_clearSearchInternal: function() {
|
_clearSearchInternal: function() {
|
||||||
|
var self = this;
|
||||||
console.log('=== CLEARING SEARCH (INTERNAL) ===');
|
console.log('=== CLEARING SEARCH (INTERNAL) ===');
|
||||||
|
|
||||||
if (this._searchInProgress) {
|
if (this._searchInProgress) {
|
||||||
|
|
@ -466,8 +581,8 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
// Clear stored original state
|
// Clear stored original state
|
||||||
this._search.originalState = null;
|
this._search.originalState = null;
|
||||||
|
|
||||||
// Trigger proper update
|
// Force complete re-render to show all records
|
||||||
return this._triggerProperUpdate();
|
return this._forceCompleteRerender();
|
||||||
} else {
|
} else {
|
||||||
// Just show all visible rows
|
// Just show all visible rows
|
||||||
this.$('.o_data_row').show();
|
this.$('.o_data_row').show();
|
||||||
|
|
@ -693,7 +808,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
_getOrderString: function() {
|
_getOrderString: function() {
|
||||||
if (this.state.orderedBy && this.state.orderedBy.length > 0) {
|
if (this.state.orderedBy && this.state.orderedBy.length > 0) {
|
||||||
return this.state.orderedBy.map(function(order) {
|
return this.state.orderedBy.map(function(order) {
|
||||||
return order.name + ' ' + order.asc ? 'ASC' : 'DESC';
|
return order.name + ' ' + (order.asc ? 'ASC' : 'DESC');
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue