In Odoo 17 (JavaScript), the traditional rpc method used in previous versions is no longer available. Instead, only AJAX RPC can be used.
In Odoo 17 (JavaScript), the traditional rpc method used in previous versions is no longer available. Instead, only AJAX RPC can be used.
1 Answer
In Odoo 17, the traditional rpc method (which was commonly used in older versions of Odoo, such as Odoo 13 or earlier) has indeed been deprecated and replaced by a more modern approach. However, it's not entirely accurate to say that only AJAX RPC can be used. Instead, Odoo 17 uses the useService hook and the rpc service provided by the OWL (Odoo Web Library) framework, which is the default frontend framework for Odoo as of version 15.
In older versions of Odoo, you could use the rpc method directly, like this:
this._rpc({
model: 'model.name',
method: 'method_name',
args: [args],
}).then(function (result) {
// Handle result
});
In Odoo 17, you should use the rpc service provided by the OWL framework. Here’s how it works:
const { useService } = owl.hooks;
class MyComponent extends owl.Component {
setup() {
this.rpc = useService("rpc");
}
async someMethod() {
const result = await this.rpc("/web/dataset/call_kw", {
model: 'model.name',
method: 'method_name',
args: [args],
kwargs: {},
});
// Handle result
}
}