diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index c178ee2..5d03968 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -17,9 +17,9 @@ class AwesomeDashboard extends Component { this.action = useService("action"); - this.rpc = useService('rpc'); + this.stats = useService('awesome_dashboard.statistics'); onWillStart(async () => { - this.stats = await this.rpc("/awesome_dashboard/statistics"); + this.stats = await this.stats.loadStatistics(); }); } diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js new file mode 100644 index 0000000..1ee547b --- /dev/null +++ b/awesome_dashboard/static/src/statistics_service.js @@ -0,0 +1,17 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { memoize } from "@web/core/utils/functions" + +const statisticsService = { + dependencies: ["rpc"], + async: ["loadStatistics"], + start(env, { rpc }) { + return { + loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), + }; + }, +}; + + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); \ No newline at end of file