3

Here is the issue I have right?

[NOTE] this is on odoo14

I have a js file that calls a function in python using rpc and it receives the return object; which is perfect.

Snippet of the 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; This third party API does its stuff and calls my route which I created under controllers.

I want my function that is inside my route in the controller to call a js function.[This is my main problem].

Any insights will be much appreciated.

3
  • 2
    Does this help: How to Run Javascript from Python. Commented Jun 10, 2022 at 12:39
  • Nice @bloodyKnuckles, I will definitely check and see if it works on the framework Odoo uses. Commented Jun 10, 2022 at 17:53
  • 1
    hey @bloodyKnuckles Your answer seems to technically work on a pure python and js setup but is not best practice on Odoo. Commented Jul 10, 2022 at 15:30

1 Answer 1

1

Yes its totally possible. This is how for example odoo displays channel messages in front end. Its done through longpooling. Here are the step

  1. In your python function, send a notification message
self.env['bus.bus'].sendone('your_channel','your_notification_type',dict_parameters)
  1. In Javascript implement a notification listener and perform your desired action
    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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.