Making RPC calls to the server
Sooner or later, your widget will need to look up some data from the server. This recipe shows you how to do that. We’ll replace the hard-coded list of users in the many2one_buttons
widget with a list queried from the server, depending on the field’s domain.
Getting ready
This recipe is just a modified version of the previous recipe, Using client-side QWeb templates code, so grab a copy of it and use it to create the r3_rpc_calls
addon.
How to do it...
We just have to adapt some JavaScript code at the right place:
Delete the init
function and replace it with an implementation of willStart
:
willStart: function() { var deferred = new jQuery.Deferred(), self = this; self.user_list = {}; this._rpc({ model: this.field.relation, method: 'search_read', fields: ['display_name'], domain: this.field.domain, }) .then(function(records) { _.each(records...