Skip to content

Commit 3829b88

Browse files
committed
[FIX] use js approach
1 parent 5a2ec01 commit 3829b88

File tree

4 files changed

+27
-119
lines changed

4 files changed

+27
-119
lines changed

spp_custom_fields_ui/__manifest__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"maintainers": ["jeremi", "gonzalesedwin1123"],
1111
"depends": ["base", "g2p_registry_base", "g2p_registry_membership", "spp_custom_field"],
1212
"data": ["views/custom_fields_ui.xml"],
13-
"assets": {},
13+
"assets": {
14+
"web.assets_backend": [
15+
"spp_custom_fields_ui/static/src/js/custom_fields_ui_reload.js",
16+
],
17+
},
1418
"demo": [],
1519
"images": [],
1620
"application": True,

spp_custom_fields_ui/models/custom_fields_ui.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
22

33
from odoo import api, fields, models
4-
from odoo.exceptions import UserError
54

65
FIELD_TYPES = [(key, key) for key in sorted(fields.Field.by_type)]
76

@@ -119,33 +118,3 @@ def set_compute(self):
119118
else:
120119
rec.ttype = "integer"
121120
rec.compute += "self.compute_count_and_set_indicator('%s', kinds, domain)" % name
122-
123-
def _should_reload_view(self):
124-
"""
125-
Check if the view should be reloaded after creating/updating custom fields.
126-
This is needed because custom fields modify the model registry.
127-
"""
128-
return any(record.target_type for record in self)
129-
130-
@api.model_create_multi
131-
def create(self, vals_list):
132-
"""Override create to trigger page reload after field creation"""
133-
records = super().create(vals_list)
134-
# Trigger reload only for custom fields with target_type in UI context
135-
if self.env.context.get("params") and records._should_reload_view():
136-
return {
137-
"type": "ir.actions.client",
138-
"tag": "reload",
139-
}
140-
return records
141-
142-
def write(self, vals):
143-
"""Override write to trigger page reload after field update"""
144-
result = super().write(vals)
145-
# Trigger reload only for custom fields with target_type in UI context
146-
if self.env.context.get("params") and self._should_reload_view():
147-
return {
148-
"type": "ir.actions.client",
149-
"tag": "reload",
150-
}
151-
return result
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @odoo-module **/
2+
3+
import {FormController} from "@web/views/form/form_controller";
4+
import {patch} from "@web/core/utils/patch";
5+
6+
patch(FormController.prototype, {
7+
/**
8+
* Override the saveButtonClicked method to trigger a reload after saving
9+
* custom fields (ir.model.fields records with target_type).
10+
*/
11+
async saveButtonClicked(params = {}) {
12+
const result = await super.saveButtonClicked(params);
13+
14+
// Check if we're editing ir.model.fields with target_type (custom fields UI)
15+
if (this.props.resModel === "ir.model.fields" && this.model.root.data.target_type) {
16+
// Reload the page to refresh the model registry
17+
window.location.reload();
18+
}
19+
20+
return result;
21+
},
22+
});

spp_custom_fields_ui/tests/test_custom_fields_ui.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -196,90 +196,3 @@ def test_09_set_compute_error_on_type_change(self):
196196
"Changing the type of a field is not yet supported",
197197
):
198198
field.set_compute()
199-
200-
def test_10_create_with_ui_context_returns_reload_action(self):
201-
"""Test that create with UI context returns reload action"""
202-
# Simulate UI context with params
203-
context = {"params": {"model": "ir.model.fields", "view_type": "form"}}
204-
result = (
205-
self.field_model.with_context(context)
206-
.create(
207-
{
208-
"name": "x_cst_grp_reload_test",
209-
"model_id": self.model_id.id,
210-
"field_description": "Reload Test",
211-
"ttype": "char",
212-
"state": "manual",
213-
"target_type": "grp",
214-
"field_category": "cst",
215-
}
216-
)
217-
)
218-
219-
# When created in UI context with target_type, should return reload action
220-
self.assertIsInstance(result, dict)
221-
self.assertEqual(result.get("type"), "ir.actions.client")
222-
self.assertEqual(result.get("tag"), "reload")
223-
224-
def test_11_create_without_ui_context_returns_recordset(self):
225-
"""Test that create without UI context returns normal recordset"""
226-
# Create without params in context (programmatic call)
227-
result = self.field_model.create(
228-
{
229-
"name": "x_cst_grp_no_reload",
230-
"model_id": self.model_id.id,
231-
"field_description": "No Reload Test",
232-
"ttype": "char",
233-
"state": "manual",
234-
"target_type": "grp",
235-
"field_category": "cst",
236-
}
237-
)
238-
239-
# Should return recordset, not action dict
240-
self.assertEqual(result._name, "ir.model.fields")
241-
self.assertTrue(result.id)
242-
243-
def test_12_write_with_ui_context_returns_reload_action(self):
244-
"""Test that write with UI context returns reload action"""
245-
field = self.field_model.create(
246-
{
247-
"name": "x_cst_grp_write_test",
248-
"model_id": self.model_id.id,
249-
"field_description": "Write Test",
250-
"ttype": "char",
251-
"state": "manual",
252-
"target_type": "grp",
253-
"field_category": "cst",
254-
}
255-
)
256-
257-
# Update with UI context
258-
context = {"params": {"model": "ir.model.fields", "view_type": "form"}}
259-
result = field.with_context(context).write({"field_description": "Updated Description"})
260-
261-
# Should return reload action
262-
self.assertIsInstance(result, dict)
263-
self.assertEqual(result.get("type"), "ir.actions.client")
264-
self.assertEqual(result.get("tag"), "reload")
265-
266-
def test_13_write_without_ui_context_returns_boolean(self):
267-
"""Test that write without UI context returns boolean"""
268-
field = self.field_model.create(
269-
{
270-
"name": "x_cst_grp_write_no_reload",
271-
"model_id": self.model_id.id,
272-
"field_description": "Write No Reload",
273-
"ttype": "char",
274-
"state": "manual",
275-
"target_type": "grp",
276-
"field_category": "cst",
277-
}
278-
)
279-
280-
# Update without UI context (programmatic call)
281-
result = field.write({"field_description": "Updated Without Reload"})
282-
283-
# Should return boolean True
284-
self.assertTrue(result)
285-
self.assertIsInstance(result, bool)

0 commit comments

Comments
 (0)