This question has been flagged
3 Replies
14745 Views

I'm trying to create a task from the notification popup and then redirect to that task. The problem is that I'm bad at javascript. I've created a controller that creates a task and returns its ID. Now I want to get an action by xml ID, append the task ID as res_id to it and redirect to it. The controller creates the task and returns the task ID, but when I call the next controller I get an error "TypeError: this.rpc is not a function".


this.rpc("/calls/create/task", {
call_id: eid,
}).then(function(r) {
this.task_id = r;
console.log('pride v drugi rpc')
return this.rpc("/web/action/load", {action_id: "tabla_asterisk_calls.action_show_call_ticket"});
}).then(function(a){
a.res_id = self.task_id;
return self.do_action(a);
});
Avatar
Discard
Best Answer


var rpc = require('web.rpc')

rpc.query(

     model: //your model,

     method: //your method,

      args: [{

          'arg1': value1,

      }]

 }).then(function (result) { 

            // your code 

  });


on model.py

@api.model
def your_method(self):
     ...


Avatar
Discard
Best Answer

save reference of `this` in self and use it while callback of rpc call 

var self = this;

this.rpc("/calls/create/task", {
call_id: eid,
}).then(function(r) {
this.task_id = r;
console.log('pride v drugi rpc')
return self.rpc("/web/action/load", {action_id: "tabla_asterisk_calls.action_show_call_ticket"});
}).then(function(a){
a.res_id = self.task_id;
return self.do_action(a);
});


Avatar
Discard
Author

nope... because I already do that, just didn't include it and it doesn't work. I think that this then is from odoos rpc method and not like a promise. At least so its written in odoo10 javascript documentation. The problem is that rps calls are async so I just cant use only one then. If I put any code after the first rpc call it's executed before the rpc call is compleated.

hey is it solved? then what was the issue?

Author

found a work around.