Fix TypeError: Check if _renderBody returns promise before calling .then()

This commit is contained in:
Mohamed Eltayar 2025-08-29 18:35:14 +03:00
parent e0a033c6fb
commit 5c63fe567e
1 changed files with 23 additions and 5 deletions

View File

@ -38,15 +38,28 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
var searchValue = this._search ? this._search.value : '';
var self = this;
return this._super.apply(this, arguments).then(function(result) {
// Restore search value after render
var result = this._super.apply(this, arguments);
// Check if result is a Promise
if (result && typeof result.then === 'function') {
return result.then(function(res) {
// Restore search value after render
if (searchValue) {
setTimeout(function() {
self._restoreSearchInput();
}, 0);
}
return res;
});
} else {
// If not a promise, restore immediately
if (searchValue) {
setTimeout(function() {
self._restoreSearchInput();
}, 0);
}
return result;
});
}
},
/**
@ -403,7 +416,8 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
// Render new rows
var result = this._renderBody();
if (result && result.then) {
// Handle both promise and non-promise returns
if (result && typeof result.then === 'function') {
result.then(function() {
self._forceRestoreSearchState();
self.$('.oe_search_count').text(_t('Found: ') + records.length + _t(' records')).show();
@ -670,7 +684,11 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
// Re-render
if (typeof this._renderBody === 'function') {
this._renderBody();
var result = this._renderBody();
// Handle both promise and non-promise
if (!result || typeof result.then !== 'function') {
// Not a promise, already rendered
}
} else {
// Show original rows with pagination
var $rows = this.$('.o_data_row');