Skip to content

Commit 644eaeb

Browse files
committed
[FIX] reload validation
1 parent 4ab14b5 commit 644eaeb

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

spp_custom_fields_ui/static/src/js/custom_fields_ui_reload.js

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,40 @@
22

33
import {FormController} from "@web/views/form/form_controller";
44
import {patch} from "@web/core/utils/patch";
5-
import {useService} from "@web/core/utils/hooks";
65

76
patch(FormController.prototype, {
8-
setup() {
9-
super.setup();
10-
this.actionService = useService("action");
11-
},
12-
137
/**
148
* Override the saveButtonClicked method to trigger a reload after saving
159
* custom fields (ir.model.fields records with target_type).
1610
*/
1711
async saveButtonClicked(params = {}) {
18-
// Check if we're editing ir.model.fields with target_type (custom fields UI)
19-
const isCustomField = this.props.resModel === "ir.model.fields" && this.model.root.data.target_type;
20-
21-
if (!isCustomField) {
12+
// Check if we're editing through the custom fields UI specifically:
13+
// 1. Model is ir.model.fields
14+
// 2. Has target_type (grp or indv)
15+
// 3. Model is res.partner (the target of custom fields)
16+
// 4. State is manual (not base fields)
17+
// 5. Context has default_model = 'res.partner' (from the custom fields UI actions)
18+
const isCustomFieldUI =
19+
this.props.resModel === "ir.model.fields" &&
20+
this.model.root.data.target_type &&
21+
this.model.root.data.model === "res.partner" &&
22+
this.model.root.data.state === "manual" &&
23+
this.props.context?.default_model === "res.partner";
24+
25+
if (!isCustomFieldUI) {
2226
return super.saveButtonClicked(params);
2327
}
2428

25-
// Store record ID before save (will be false for new records)
26-
const recordIdBeforeSave = this.model.root.resId;
27-
2829
// Try to save
2930
try {
3031
const result = await super.saveButtonClicked(params);
3132

3233
// Only reload if save was successful
3334
// If result is defined and not false, save was successful
3435
if (result !== false) {
35-
const recordIdAfterSave = this.model.root.resId;
36-
37-
if (!recordIdBeforeSave && recordIdAfterSave) {
38-
// New record was created - reload and navigate to the saved record
39-
// Use actionService to reload the current action with the new record ID
40-
this.actionService.doAction({
41-
type: "ir.actions.act_window",
42-
res_model: this.props.resModel,
43-
res_id: recordIdAfterSave,
44-
views: [[false, "form"]],
45-
target: "current",
46-
});
47-
} else if (recordIdBeforeSave) {
48-
// Existing record was edited - just reload the page
49-
window.location.reload();
50-
}
36+
// Reload the page to refresh the model registry
37+
// The URL will contain the record ID (for both new and existing records)
38+
window.location.reload();
5139
}
5240

5341
return result;

0 commit comments

Comments
 (0)