|
2 | 2 |
|
3 | 3 | import {FormController} from "@web/views/form/form_controller"; |
4 | 4 | import {patch} from "@web/core/utils/patch"; |
5 | | -import {useService} from "@web/core/utils/hooks"; |
6 | 5 |
|
7 | 6 | patch(FormController.prototype, { |
8 | | - setup() { |
9 | | - super.setup(); |
10 | | - this.actionService = useService("action"); |
11 | | - }, |
12 | | - |
13 | 7 | /** |
14 | 8 | * Override the saveButtonClicked method to trigger a reload after saving |
15 | 9 | * custom fields (ir.model.fields records with target_type). |
16 | 10 | */ |
17 | 11 | 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) { |
22 | 26 | return super.saveButtonClicked(params); |
23 | 27 | } |
24 | 28 |
|
25 | | - // Store record ID before save (will be false for new records) |
26 | | - const recordIdBeforeSave = this.model.root.resId; |
27 | | - |
28 | 29 | // Try to save |
29 | 30 | try { |
30 | 31 | const result = await super.saveButtonClicked(params); |
31 | 32 |
|
32 | 33 | // Only reload if save was successful |
33 | 34 | // If result is defined and not false, save was successful |
34 | 35 | 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(); |
51 | 39 | } |
52 | 40 |
|
53 | 41 | return result; |
|
0 commit comments