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 templates: QWeb code, so grab a copy of it and use it to create addon ch15_r03.

How to do it...

We just have to adapt some JavaScript code at the right places:

  1. Require the data and model packages in static/src/js/ch15_r03.js:
    odoo.define('ch15_r01', function(require) { var core = require('web.core'), data = require('web.data'), model = require('web.Model'), form_common = ...

Get Odoo Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.