How it works...

The RPC utility is available at the web.rpc namespace. In step 1, we imported the RPC utility through require('web.rpc').

In step 2, we defined an action button to fetch and display order information for the selected customer. Before going into the technical details, let's understand what we wanted to accomplish with this action button. Once clicked, we want to display information for the last five orders for the selected customer. There are a few cases where the customer is not selected or customers have no previous orders. In such cases, we want to show a popup with an appropriate message.

Let's get back to the technical details for step 2. Here, we created and registered the action button. If you want to learn more about the action button, refer to the Adding an action button on the keyboard recipe. In the step 3, we added the click-handler function. On clicking the action button, the click-handler function will be called. This function will make the RPC call the server to fetch the order information. We used the rpc.query() method to make RPC calls. The following is a list of the parameters you can pass in the rpc.query() method:

  • model: The name of the model on which you want to perform the operation
  • method: The name of the method you want to invoke
  • args: A list of compulsory positional arguments accepted by the method
  • kwargs: The dictionary of the optional arguments accepted by the method

In this recipe, we used the search_read method to fetch data through RPC. We passed the customer domain to filter the orders. We also passed limit keyword arguments to fetch only five orders. rpc.query() is an asynchronous method and returns a JQuery Deferred object, so to handle the result, you will need to use the then() method.

In step 4, we created the show_order_list and show_error methods in the lastOrders button. These will be used to display order information and warnings in the popup. To display the popup, we used the show_popup() method of gui. If you want to learn more about gui methods, explore the addons/point_of_sale/static/src/js/gui.js file.

In step 5, we added the QWeb template for the action button. The Point of Sale application will render this template to display action button.

The RPC call does not work in offline mode. If you have a good internet connection and you do not use offline mode frequently, you can use the RPCs. Though the Odoo Point of Sale application works offline, a few operations, such as creating or updating a customer, need an internet connection, as those features are use RPC to call internally.
..................Content has been hidden....................

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