当前位置:网站首页>Detailed explanation of odoo JS DoAction
Detailed explanation of odoo JS DoAction
2022-07-24 13:18:00 【Jiang Zhenjian 15954039008】
doAction Actions are commonly used js Action one , Support
ir.actions.act_url url Jump
Native code :
function _executeActURLAction(action, options) {
if (action.target === "self") {
env.services.router.redirect(action.url);
} else {
const w = browser.open(action.url, "_blank");
if (!w || w.closed || typeof w.closed === "undefined") {
const msg = env._t(
"A popup window has been blocked. You may need to change your " +
"browser settings to allow popup windows for this page."
);
env.services.notification.add(msg, {
sticky: true,
type: "warning",
});
}
if (options.onClose) {
options.onClose();
}
}
}
Sample code :
@api.model
def _redirect_to_iap_account(self):
return {
'type': 'ir.actions.act_url',
'url': self.env['iap.account'].get_account_url(),
}
ir.actions.act_window Back end window ( Back end form\tree View etc. ) call
Such as code :
await doAction(webClient, {
name: "Action name",
res_model: "foo",
type: "ir.actions.act_window",
views: [
[false, "graph"],
[false, "legacy_toy"],
],
context: {
search_default_forecast_filter: 1,
forecast_field: "date_field",
},
});
effect :
ir.actions.act_window_close close window , Through the “next” step
ir.actions.client Trigger the action completely implemented in the client
The use examples of the above two lines :
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'warning',
'message': _("Two-factor authentication disabled for the following user(s): %s", ', '.join(self.mapped('name'))),
'next': {
'type': 'ir.actions.act_window_close'},
}
}
ir.actions.report Generate qweb-html or qweb-pdf report form
See the code :
ir.actions.server Execute server-side actions
For example, the following code :
The effect that can be achieved :
The above code explanation :
And everything else in the data file (XML) Data defined in , The first is a containing attribute id and model Of label , What we want to define is Server Action, So we need to model Set to ir.actions.server, Then there is the corresponding Server Action Some fields under the model :
model_id: On which model does the current action run
binding_model_id: Bound model , The current action will appear in the view of the bound model
state: The type of server action , All in all 4 Two optional types , Namely code( perform Python Code ),object_create( Create a new record ),object_write( Update record ),multi( Perform multiple actions )
code: Corresponding state The type of code, Is what the current action will execute when it runs Python Code
You should have noticed that an attribute appears in the above definition ref, If I don't get it wrong , It should be reference Abbreviation , Its value is an external ID(external id), The exterior of the action we defined above ID It is added when defining id The value of the property action_mark_todo_task_done, It points to a specific record ( It's like Many2one The fields are the same ).
All models we define will be in ir.model.data There are corresponding records in the corresponding table , The exterior of these models ID Form like model_model_name, among model_name Is the model name model.name Of . Replace with _, For example, our todo.task Outside the model ID It's the prefix model add todo_task Composed of model_todo_task 了 .
Next we will see the fields code What's in it , We have some variables that can be used directly :
env:Odoo Operating environment
model: Corresponding when the action is triggered Odoo Model examples
record: The corresponding single record when the action is triggered ( For example, run the record corresponding to the current form in the form view ), It could be empty
records: The corresponding record set when the action is triggered ( If you check multiple records in the list view, trigger , The recordset points to these selected records ), It could be empty
Python library :time, datetime, dateutil, timezone Time related Python library
log: Used to record log information
Warning: adopt raise Warning('xxxxx') Throw a warning message

async function doAction(actionRequest, options = {
}) {
const actionProm = _loadAction(actionRequest, options.additionalContext);
let action = await keepLast.add(actionProm);
action = _preprocessAction(action, options.additionalContext);
switch (action.type) {
case "ir.actions.act_url":
return _executeActURLAction(action, options);
case "ir.actions.act_window":
if (action.target !== "new") {
await clearUncommittedChanges(env);
}
return _executeActWindowAction(action, options);
case "ir.actions.act_window_close":
return _executeCloseAction({
onClose: options.onClose, onCloseInfo: action.infos });
case "ir.actions.client":
return _executeClientAction(action, options);
case "ir.actions.report":
return _executeReportAction(action, options);
case "ir.actions.server":
return _executeServerAction(action, options);
default: {
let handler = actionHandlersRegistry.get(action.type, null);
if (handler !== null) {
return handler({
env, action, options });
}
throw new Error(
`The ActionManager service can't handle actions of type ${
action.type}`
);
}
}
}
边栏推荐
- Number of palindromes in Li Kou question
- Prototype inheritance
- 29. Right view of binary tree
- 基于boost库的搜索引擎
- Introduction to encryption technology
- The second batch of projects of Shenzhen Metro Line 12 passed the acceptance and is expected to be put into trial operation on July 28
- [datasheet] PHY ksz9031 gigabit network chip interpretation
- Wang Ping, co-founder of Denglin Technology: Innovation + self research "dual core" drive, gpu+ enabling AI takes root | quantum bit · viewpoint sharing review
- Two stacks implement one queue
- Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
猜你喜欢

20201127 use markdown to draw UML diagrams, graphviz installation experience hematemesis finishing

Win10 log in with Microsoft account and open all programs by default with administrator privileges: 2020-12-14

Go deadlock problem

Wang Ping, co-founder of Denglin Technology: Innovation + self research "dual core" drive, gpu+ enabling AI takes root | quantum bit · viewpoint sharing review

Teach you how to use power Bi to realize four kinds of visual charts

Activity start (launchactivity/startactivity)_ (1)_ WMS of flow chart

LeadTools 22 kit LeadTools super set

3. Realize snake and basic game interface

Roller_ Block default behavior_ Zero roll event compatible

34. Add two numbers
随机推荐
setAttribute、getAttribute、removeAttribute
AtCoder Beginner Contest 261 F // 树状数组
The core capability of accelerating enterprise data application innovation flexibility
Generator and async solve asynchronous programming
31. Climb stairs
Data + AI Summit 2022 PPT 下载
34. Add two numbers
如何画 贝赛尔曲线 以及 样条曲线?
25. Middle order traversal of binary tree
Usage of swipemenurecyclerview
How to render millions of 2D objects smoothly with webgpu?
EAS approval process related table
Pointer advanced part (1)
35.8. string conversion integer (ATOI)
[C language] dynamic memory management
Localstorage
Basic operation of file
有好用的免费的redis客户端工具推荐么?
Constraintlayout learn from 0 to 0.n
Windivert:可抓包,修改包