Odoo自动服务器动作触发另一个服务器动作 [英] Odoo automated server action to trigger another server action

查看:296
本文介绍了Odoo自动服务器动作触发另一个服务器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我在stock.inventory模型上设置了服务器操作A.该操作仅记录一个值,然后调用服务器操作B(数据库ID为366).动作中的python代码就是:

Let's say I set up Server Action A on the stock.inventory model. This action simply logs a value and then calls Sever Action B (which has a database ID of 366). The python code in the action is just:

log('running server action a')
value = {
  "type": "ir.actions.server",
   "id": 366,
}

然后,在product.product模型上的服务器操作B中,python代码就是:

Then, in Server Action B, which is on the product.product model, the python code is just:

log('running server aciton b')

现在,当我将服务器操作A"添加到更多"菜单中并在浏览器中的stock.inventory对象上手动触发它时,两个操作均成功运行.换句话说,我在日志中同时看到正在运行服务器操作a"和正在运行服务器操作b".

Now, when I add Server Action A to the "More" menu, and manually trigger it from the browser on a stock.inventory object, both actions successfully run. In other words, I see both 'running server action a' and 'running server action b' in the logs.

现在,我创建一个自动动作以在stock.inventory对象的更新或创建时触发服务器动作A.完成此操作并通过UI更新或创建stock.inventory对象后,我在日志中仅看到正在运行服务器操作a".换句话说,服务器操作B永远不会像我从更多"菜单中手动运行相同实验时那样触发.

Now, I create an Automated Action to trigger Server Action A on Update or Create of a stock.inventory object. After doing this, and updating or creating a stock.inventory object via the UI, I only see 'running server action a' in the logs. In other words, Server Action B never gets triggered like it did when I ran the same experiment manually from the "More" menu.

所以,我的问题是,如果第一个服务器动作是由自动动作触发的,那么是否有可能从第一个服务器动作触发第二个服务器动作.

So, my question is whether or not it is possible to trigger a second server action from the first server action if the first server action is triggered by an automated action.

推荐答案

我能够使它正常工作,并且解决方案非常简单.对于Odoo Online用户而言,这似乎是一种非常酷的方式,它将服务器操作视为可以将值返回给调用服务器操作的函数.

I was able to get this working and the solution is very simple. This seems like a pretty cool way for Odoo Online users to treat server actions as functions that can return values to the calling server action.

这是一个例子.

服务器操作A

a = env['ir.actions.server'].browse(409)
ctx = dict(env.context or {})
ctx.update({'active_id': 169, 'active_model': 'purchase.order'})
a.with_context(ctx).run()

服务器操作B(ID = 409)

raise Warning(record)

触发第一个操作时,将获得字符串purchase.order(169,)作为输出.

When you trigger the first action, you'll get the string purchase.order(169,) as output.

即使是冷却器,如果第二台服务器将值分配给action,它也会返回到第一个操作.例如:

Even cooler, if the second server assigns a value to action, it is returned to the first action. For example:

服务器操作A

a = env['ir.actions.server'].browse(409)
ctx = dict(env.context or {})
ctx.update({'active_id': 169, 'active_model': 'purchase.order'})
resp = a.with_context(ctx).run()
raise Warning(resp)

服务器操作B(ID = 409)

action = record.id

触发第一个服务器操作时,您将看到169作为响应.

When you trigger the first server action, you'll see 169 as the response.

这篇关于Odoo自动服务器动作触发另一个服务器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆