-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathbase_exception.js
More file actions
62 lines (53 loc) · 1.73 KB
/
base_exception.js
File metadata and controls
62 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {patch} from "@web/core/utils/patch";
import {rpc} from "@web/core/network/rpc";
import {FormController} from "@web/views/form/form_controller";
// keep track of the current FormController by storing it
const activeForm = {
controller: null,
};
patch(FormController.prototype, {
setup() {
super.setup();
activeForm.controller = this;
},
willUnmount() {
if (activeForm.controller === this) {
activeForm.controller = null;
}
super.willUnmount();
},
});
async function refreshExceptionIdsField() {
const controller = activeForm.controller;
if (!controller) return false;
const model = controller.model;
const root = model?.root;
const resModel = root?.resModel;
const resId = root?.resId;
if (!resModel || !resId) return false;
// Use services from the controller's env (OWL environment)
const orm = controller.env.services.orm;
// Read the latest value for just that field
await orm.read(resModel, [resId], ["exception_ids"]);
// Reload the record; OWL will re-render the field
await root.load();
return true;
}
patch(rpc, {
async _rpc(url, params = {}, settings = {}) {
try {
return await super._rpc(url, params, settings);
} catch (error) {
if (
error.exceptionName ===
"odoo.addons.base_exception.exceptions.BaseExceptionError"
) {
await refreshExceptionIdsField();
// Swallow the error so no stacktrace dialog appears.
// Return a never-resolving promise to stop further handling cleanly
return new Promise(() => {});
}
throw error;
}
},
});