Skip to content

Commit 6056586

Browse files
committed
[IMP] awesome_dashboard: added some statistics and caching
1 parent 0aa3756 commit 6056586

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

awesome_dashboard/static/src/dashboard.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @odoo-module **/
22

3-
import { Component } from "@odoo/owl";
3+
import { Component, onWillStart } from "@odoo/owl";
44
import { registry } from "@web/core/registry";
55
import { Layout } from "@web/search/layout";
66
import { useService } from "@web/core/utils/hooks";
@@ -20,7 +20,12 @@ class AwesomeDashboard extends Component {
2020
}
2121

2222
setup() {
23-
this.action = useService("action");
23+
this.action = useService("action");
24+
const statsService = useService("awesome_dashboard.getStats");
25+
26+
onWillStart(async () => {
27+
this.result = await statsService.loadStatistics();
28+
});
2429
}
2530

2631
openCustomerKanban() {

awesome_dashboard/static/src/dashboard.xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,33 @@
66
<Layout className="'o_dashboard h-100'" display="props.display">
77
<button class="btn btn-primary myBtnChange" t-on-click="openCustomerKanban"> Open customer kanban </button>
88
<button class="btn btn-primary myBtnChange" t-on-click="openActivity"> Leads </button>
9-
<DashboardItem > long content </DashboardItem>
10-
<DashboardItem size="2"> very very very very long content </DashboardItem>
9+
<div style="margin-left: 1rem;">
10+
<DashboardItem size="2"> Average quantity sold is :
11+
<span style="color: green; font-weight: bolder; font-size: 27px;">
12+
<t t-esc="result.average_quantity"/>
13+
</span>
14+
</DashboardItem>
15+
<DashboardItem size="2"> Number of new orders this month :
16+
<span style="color: green; font-weight: bolder; font-size: 27px;">
17+
<t t-esc="result.nb_new_orders"/>
18+
</span>
19+
</DashboardItem>
20+
<DashboardItem size="2"> Total amount of new orders this month :
21+
<span style="color: green; font-weight: bolder; font-size: 27px;">
22+
<t t-esc="result.total_amount"/>
23+
</span>
24+
</DashboardItem>
25+
<DashboardItem size="2"> Number of cancelled orders this month :
26+
<span style="color: green; font-weight: bolder; font-size: 27px;">
27+
<t t-esc="result.nb_cancelled_orders"/>
28+
</span>
29+
</DashboardItem>
30+
<DashboardItem size="2"> Average time for an order :
31+
<span style="color: green; font-weight: bolder; font-size: 27px;">
32+
<t t-esc="result.average_time"/>
33+
</span>
34+
</DashboardItem>
35+
</div>
1136
</Layout>
1237

1338
</div>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.box {
2-
border: 3px;
2+
border: 30px black;
3+
// border-color: black;
4+
border-radius: 10px;
35
background-color: white;
6+
margin: 1rem;
47
}

awesome_dashboard/static/src/dashboard_item/dashboard_item.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_dashboard.DashboardItem">
5-
<div class="p-3 box" t-att-style="'width: ' + 18 * props.size + 'rem;'">
5+
<span class="p-3 box" t-att-style="'width: ' + 18 * props.size + 'rem;'">
66
<t t-slot="default" />
7-
</div>
7+
</span>
88
</t>
99

1010
</templates>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { registry } from "@web/core/registry";
2+
import { rpc } from "@web/core/network/rpc";
3+
import { memoize } from "@web/core/utils/functions";
4+
5+
export const getStatistics = {
6+
async start() {
7+
return {
8+
loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")),
9+
};
10+
},
11+
};
12+
13+
registry.category("services").add("awesome_dashboard.getStats", getStatistics);

0 commit comments

Comments
 (0)