简体   繁体   English

有没有办法从 python ZC1C425268E68385D1AB5074C17A94 中的 python ZC1C425268E68385D1AB5074C17A94

[英]Is there a way to call a javascript function from python function in Odoo

Here is the issue I have right?这是我的问题吗?

[NOTE] this is on odoo14 [注意] 这是在odoo14

I have a js file that calls a function in python using rpc and it receives the return object;我有一个使用 rpc 在 python 中调用 function 的 js 文件,它收到返回 object; which is perfect.这是完美的。

Snippet of the JS function: JS function 的片段:

               this.rpc({
                  model: 'atm.transaction',
                  method: 'do_payment_transaction',
                  args: [customer_id],
                }).then(function (data)
                    {
                    console.log("Response of payment",data)
                });

The python function on the other hand initiates a request to a third party API;另一方面,python function 向第三方发起请求 API; This third party API does its stuff and calls my route which I created under controllers.这个第三方 API 完成它的工作并调用我在控制器下创建的路由。

I want my function that is inside my route in the controller to call a js function.[This is my main problem].我希望我的 function 在 controller 的路线内调用 js function。[这是我的主要问题]。

Any insights will be much appreciated.任何见解将不胜感激。

Yes its totally possible.是的,它完全有可能。 This is how for example odoo displays channel messages in front end.这就是例如 odoo 在前端显示频道消息的方式。 Its done through longpooling.它通过长池完成。 Here are the step这是步骤

  1. In your python function, send a notification message在您的 python function 中,发送通知消息
self.env['bus.bus'].sendone('your_channel','your_notification_type',dict_parameters)
  1. In Javascript implement a notification listener and perform your desired action在 Javascript 中实现通知侦听器并执行您想要的操作
    this.call('bus_service', 'onNotification', this, this._onLongpollingNotifications);
    /**
         * @private
         * @param {Object[]} notifications
         * @param {string} [notifications[i].type]
         * @param {string} [notifications[i].payload]
         */
        async _onLongpollingNotifications(notifications) {
// your code processed here
}

For more info check here: https://github.com/odoo/odoo/blob/ea481271f8f477d1cdcbb94826111955ed9a6a4f/addons/mail/models/mail_message.py#L750有关更多信息,请在此处查看: https://github.com/odoo/odoo/blob/ea481271f8f477d1cdcbb94826111955ed9a6a4f/addons/mail/models/mail_message.py#L750

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM