[FIX] rpc: fix code examples for tutorial and service

closes odoo/documentation#13235

X-original-commit: 2712116544
Signed-off-by: Florent Dardenne (dafl) <dafl@odoo.com>
This commit is contained in:
Leo Leclerc
2025-04-30 15:14:21 +00:00
parent 8122da1c51
commit 7c0b0226d4
2 changed files with 15 additions and 17 deletions

View File

@@ -199,22 +199,23 @@ Let's improve the dashboard by adding a few dashboard items to display *real* bu
The `awesome_dashboard` addon provides a `/awesome_dashboard/statistics` route that is meant
to return some interesting information.
To call a specific controller, we need to use the :ref:`rpc service <frontend/services/rpc>`.
To call a specific controller, we need to use the :ref:`rpc <frontend/services/rpc>` function.
It only exports a single function that perform the request: :code:`rpc(route, params, settings)`.
A basic request could look like this:
.. code-block:: js
import { rpc } from "@web/core/network/rpc";
// ...
setup() {
this.rpc = useService("rpc");
onWillStart(async () => {
const result = await this.rpc("/my/controller", {a: 1, b: 2});
// ...
});
onWillStart(async () => {
const result = await rpc("/my/controller", {a: 1, b: 2});
})
// ...
}
#. Update `Dashboard` so that it uses the `rpc` service.
#. Call the statistics route `/awesome_dashboard/statistics` in the `onWillStart` hook.
#. Update `Dashboard` so that it uses the `rpc` function and call the statistics route `/awesome_dashboard/statistics`.
#. Display a few cards in the dashboard containing:
- Number of new orders this month
@@ -227,7 +228,7 @@ A basic request could look like this:
:align: center
.. seealso::
`Code: rpc service <{GITHUB_PATH}/addons/web/static/src/core/network/rpc_service.js>`_
`Code: rpc <{GITHUB_PATH}/addons/web/static/src/core/network/rpc.js>`_
5. Cache network calls, create a service
========================================