当前位置:网站首页>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}`
);
}
}
}
边栏推荐
- SSM在线租房售房平台多城市版本
- I realize large top stack with C I
- EAS environment structure directory
- Handler learning
- C代码规范
- Writing browser plug-ins
- Modern data architecture selection: Data fabric, data mesh
- Data + AI Summit 2022 PPT 下载
- Implementation of dynamic columns in EAS BOS doc list
- The core capability of accelerating enterprise data application innovation flexibility
猜你喜欢

Vscode configuration user code snippet (including deletion method)

SSM在线校园相册管理平台

SSM医院住院管理系统

On node embedding

How to quickly learn Embedded

Search engine based on boost library

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

Step of product switching to domestic chips, stm32f4 switching to gd32

SSM在线考试系统含文档

About thread (3) thread synchronization
随机推荐
flinksql 在yarn上面怎么 以 perjob 模式跑啊,我在sqlclient 提交任务之
An example of how to save various data types by using esp32 EEPROM library functions under Arduino framework
登临科技联合创始人王平:创新+自研“双核”驱动,GPU+赋能AI落地生根|量子位·视点分享回顾...
Use of PageHelper
binary search
2022.07.21
Windivert: capture and modify packages
How to draw Bezier curve and spline curve?
On node embedding
Roller_ Block default behavior_ Zero roll event compatible
Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
cookie
深入浅出边缘云 | 2. 架构
SSM在线考试系统含文档
LEADTOOLS 22 套件 LEADTOOLS 超级套
Sorting method: bubble sorting (use an array to arrange a string of numbers in order (from large to small or from small to large))
Queue (stack)
【C语言】动态内存管理
有好用的免费的redis客户端工具推荐么?
Introduction to the use of thread (2) thread