Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spp_custom_fields_ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 2025-11-20

### 2025-11-20 10:12:34 - [FIX] remove meaningless return after page reload in custom fields UI
- Fixed bug where return statement after window.location.reload() was unreachable
- For existing records, reload happens immediately before return, destroying page context
- For new records, setTimeout creates race condition where return value is meaningless
- Added proper handling for result === false case without reload
- Added comments explaining control flow in reload scenarios

6 changes: 5 additions & 1 deletion spp_custom_fields_ui/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"maintainers": ["jeremi", "gonzalesedwin1123"],
"depends": ["base", "g2p_registry_base", "g2p_registry_membership", "spp_custom_field"],
"data": ["views/custom_fields_ui.xml"],
"assets": {},
"assets": {
"web.assets_backend": [
"spp_custom_fields_ui/static/src/js/custom_fields_ui_reload.js",
],
},
"demo": [],
"images": [],
"application": True,
Expand Down
50 changes: 50 additions & 0 deletions spp_custom_fields_ui/static/src/js/custom_fields_ui_reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @odoo-module **/

import {FormController} from "@web/views/form/form_controller";
import {patch} from "@web/core/utils/patch";

patch(FormController.prototype, {
/**
* Override the saveButtonClicked method to trigger a reload after saving
* custom fields (ir.model.fields records with target_type).
*/
async saveButtonClicked(params = {}) {
// Check if we're editing ir.model.fields with target_type (custom fields UI)
const isCustomField = this.props.resModel === "ir.model.fields" && this.model.root.data.target_type;

if (!isCustomField) {
return super.saveButtonClicked(params);
}

// Check if this is a new record (before save)
const isNewRecord = !this.model.root.resId;

// Try to save
try {
const result = await super.saveButtonClicked(params);

// Only reload if save was successful
if (result !== false) {
if (isNewRecord) {
// For new records, wait a bit for URL to update, then reload
// This ensures the URL contains the new record ID
setTimeout(() => {
window.location.reload();
}, 100);
Comment thread
emjay0921 marked this conversation as resolved.
// Don't return - page will reload soon, making return value meaningless
} else {
// For existing records, reload immediately
// This destroys the page context, so no return is needed
window.location.reload();
}
Comment thread
emjay0921 marked this conversation as resolved.
} else {
// Save returned false, don't reload but propagate the result
return result;
}
} catch (error) {
// Save failed (validation error, required fields missing, etc.)
// Don't reload, let the user fix the errors
throw error;
}
},
});
Loading