Skip to content

Commit 5c55b4f

Browse files
committed
[ADD] awesome_dashboard: implement base dashboard with layout, items, and stats
Implemented the first set of dashboard features in the `awesome_dashboard` module using the Odoo JavaScript framework. This commit reflects the progress of building a functional dashboard step by step. Work done: - Updated AwesomeDashboard to use Layout with control panel and content zone - Added dashboard.scss and applied custom background color - Added navigation buttons in control panel: * Customers → opens kanban view of res.partner * Leads → opens list and form views of crm.lead - Created reusable DashboardItem component with size prop and slot content - Displayed cards in dashboard with flexible sizing - Integrated rpc call to /awesome_dashboard/statistics to fetch data - Displayed statistics cards for orders, amounts, and processing time - Registered new statistics service to cache results with memoize - Updated Dashboard to use statistics service instead of repeated rpc calls
1 parent 1e91a59 commit 5c55b4f

File tree

7 files changed

+120
-3
lines changed

7 files changed

+120
-3
lines changed
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
/** @odoo-module **/
22

3-
import { Component } from "@odoo/owl";
3+
import { Component, onWillStart } from "@odoo/owl";
44
import { registry } from "@web/core/registry";
5+
import { Layout } from "@web/search/layout";
6+
import { useService } from "@web/core/utils/hooks";
7+
import { DashboardItem } from "./dashboard_item";
58

69
class AwesomeDashboard extends Component {
710
static template = "awesome_dashboard.AwesomeDashboard";
11+
static components = { Layout, DashboardItem } ;
12+
13+
setup(){
14+
this.actions = useService("action");
15+
this.statisticsService = useService("awesome_dashboard.statistics");
16+
this.display = { controlPanel: {} };
17+
18+
onWillStart(async () => {
19+
this.statistics = await this.statisticsService.loadStatistics();
20+
})
21+
}
22+
23+
openCustomersView(){
24+
this.actions.doAction("base.action_partner_form");
25+
}
26+
27+
openAllLeads(){
28+
this.actions.doAction({
29+
type: "ir.actions.act_window",
30+
name: "All leads",
31+
res_model: "crm.lead",
32+
views: [
33+
[false, "list"],
34+
[false, "form"]
35+
]
36+
});
37+
}
838
}
939

10-
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
40+
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard{
2+
background-color: grey;
3+
}

awesome_dashboard/static/src/dashboard.xml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,44 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
hello dashboard
5+
<Layout display="display" className="'o_dashboard h-100'">
6+
<t t-set-slot="layout-buttons">
7+
<button class="btn btn-primary" t-on-click="openCustomersView">Customers</button>
8+
<button class="btn btn-primary" t-on-click="openAllLeads">Leads</button>
9+
</t>
10+
<div class="d-flex flex-wrap">
11+
<DashboardItem>
12+
Average amount of t-shirt by order this month
13+
<div class="fs-1 fw-bold text-success text-center">
14+
<t t-esc="statistics.average_quantity"/>
15+
</div>
16+
</DashboardItem>
17+
<DashboardItem size="2">
18+
Average time for an order to go from 'new' to 'sent' or 'cancelled'
19+
<div class="fs-1 fw-bold text-success text-center">
20+
<t t-esc="statistics.average_time"/>
21+
</div>
22+
</DashboardItem>
23+
<DashboardItem>
24+
Number of new orders this month
25+
<div class="fs-1 fw-bold text-success text-center">
26+
<t t-esc="statistics.nb_new_orders"/>
27+
</div>
28+
</DashboardItem>
29+
<DashboardItem>
30+
Number of cancelled orders this month
31+
<div class="fs-1 fw-bold text-success text-center">
32+
<t t-esc="statistics.nb_cancelled_orders"/>
33+
</div>
34+
</DashboardItem>
35+
<DashboardItem>
36+
Total amount of new orders this month
37+
<div class="fs-1 fw-bold text-success text-center">
38+
<t t-esc="statistics.total_amount"/>
39+
</div>
40+
</DashboardItem>
41+
</div>
42+
</Layout>
643
</t>
744

845
</templates>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component{
4+
static template = "awesome_dashboard.DashboardItem"
5+
static props = {
6+
slots: {
7+
type: Object,
8+
shape: {
9+
default: Object
10+
},
11+
},
12+
size: {
13+
type: Number,
14+
default: 1,
15+
optional: true,
16+
},
17+
};
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_dashboard.DashboardItem">
5+
<div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;">
6+
<div class="card-body">
7+
<t t-slot="default"/>
8+
</div>
9+
</div>
10+
</t>
11+
12+
</templates>

awesome_dashboard/static/src/piechart.js

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @odoo-module **/
2+
3+
import { registry } from "@web/core/registry";
4+
import { memoize } from "@web/core/utils/functions";
5+
import { rpc } from "@web/core/network/rpc";
6+
7+
const statisticsService = {
8+
async: ["loadStatistics"],
9+
start() {
10+
return {
11+
loadStatistics : memoize(()=>rpc("/awesome_dashboard/statistics"))
12+
};
13+
},
14+
};
15+
16+
// Register the service
17+
registry.category("services").add("awesome_dashboard.statistics", statisticsService);

0 commit comments

Comments
 (0)