How it works...

The willStart function is called before rendering, and, more importantly, it returns a deferred object that must be resolved before the rendering starts. So, in a case like ours, where we need to run an asynchronous action before rendering can occur, this is the right function to do this.

When dealing with data access, we rely on the _rpc function provided by the ServicesMixin class, as we explained earlier. This function allows you to call any public function on models such as search, read, write, or, in this case, read_group.

In step 1, we made an RPC call and invoked the read_group method on the current model, which is library.book, in our case. We grouped data based on the color field, so that the RPC call will return book data that was grouped by color and add an aggregate in the color_count key. We also mapped the color_count and color index in the colorGroupData so that we could use it in the QWeb template. In the last line of the function, we resolved willStart with super and our RPC call using $.when. Because of this, rendering only occurs after the values are fetched and after whatever asynchronous action super was busy with has finished, too.

Step 2 is nothing special. We just initialized the bootstrap tooltip.

In step 3, we used colorGroupData to set the attributes that are needed to display the tooltip. In the willStart method, we assigned a color map via this.colorGroupData, so that you can access them in the QWeb template via widget.colorGroupData. This is because we passed the widget reference; this is the qweb.render method.

You can use _rpc anywhere in the widget. Note that it is an asynchronous call, and you need to manage a deferred object properly to get the desired result.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset