diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index 6ace3f8..c7f7d8a 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { Component, onWillStart } from "@odoo/owl"; +import { Component, onWillStart, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks" @@ -18,10 +18,7 @@ class AwesomeDashboard extends Component { this.action = useService("action"); - this.stats = useService('awesome_dashboard.statistics'); - onWillStart(async () => { - this.stats = await this.stats.loadStatistics(); - }); + this.stats = useState(useService('awesome_dashboard.statistics')); } openCustomers() { diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index fd3586f..1bb3e3a 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -7,7 +7,7 @@ -
+
Number of new orders this month
diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js index 1ee547b..ae4fee3 100644 --- a/awesome_dashboard/static/src/statistics_service.js +++ b/awesome_dashboard/static/src/statistics_service.js @@ -1,15 +1,19 @@ /** @odoo-module **/ import { registry } from "@web/core/registry"; -import { memoize } from "@web/core/utils/functions" +import { reactive } from "@odoo/owl"; const statisticsService = { dependencies: ["rpc"], - async: ["loadStatistics"], start(env, { rpc }) { - return { - loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), - }; + const statistics = reactive({ isReady: false }); + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + setInterval(loadData, 10*60*1000); + loadData(); + return statistics; }, };