Skip to content

Commit 1cb7a42

Browse files
committed
[IMP] awesome_dashboard: added DashboardItem component.
added DashboardItem component. added slot props in DashboardItem and created a dynamic card in xml. added rpc call in onWillStart(). render all return values in it's separate card in dashboard.xml. added state as 'badge' widget in kanban view in estate module. refined garden onchange logic.
1 parent 8c73677 commit 1cb7a42

File tree

8 files changed

+87
-13
lines changed

8 files changed

+87
-13
lines changed

awesome_dashboard/static/src/dashboard.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, onWillStart } from "@odoo/owl";
22
import { registry } from "@web/core/registry";
33
import { Layout } from "@web/search/layout";
44
import { useService } from "@web/core/utils/hooks";
5+
import { DashboardItem } from "./dashboarditem/dashboarditem";
6+
import { rpc } from "@web/core/network/rpc";
57

68
class AwesomeDashboard extends Component {
79
static template = "awesome_dashboard.AwesomeDashboard";
8-
static components = { Layout }
10+
static components = { Layout, DashboardItem }
911

1012
setup() {
1113
this.action = useService("action");
14+
onWillStart(async () => {
15+
this.result = await rpc("/awesome_dashboard/statistics");
16+
})
1217
}
1318

1419
openCustomers() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.o_dashboard {
2-
background-color: gray;
2+
background-color:rgb(27, 29, 38)
33
}

awesome_dashboard/static/src/dashboard.xml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,38 @@
1010
Leads
1111
</button>
1212
</t>
13-
<h1 style="color: black;">Hello World</h1>
13+
<div class="d-flex flex-wrap mt-1">
14+
<DashboardItem>
15+
<div class="text-center">
16+
Number of new orders this month
17+
<p t-out="this.result.nb_new_orders" class="fs-1 fw-bold text-success"/>
18+
</div>
19+
</DashboardItem>
20+
<DashboardItem>
21+
<div class="text-center">
22+
Total amount of new orders this month
23+
<p t-out="this.result.total_amount" class="fs-1 fw-bold text-success"/>
24+
</div>
25+
</DashboardItem>
26+
<DashboardItem>
27+
<div class="text-center">
28+
Average amount of t-shirt by order this month
29+
<p t-out="this.result.average_quantity" class="fs-1 fw-bold text-success"/>
30+
</div>
31+
</DashboardItem>
32+
<DashboardItem>
33+
<div class="text-center">
34+
Number of cancelled orders this month
35+
<p t-out="this.result.nb_cancelled_orders" class="fs-1 fw-bold text-success"/>
36+
</div>
37+
</DashboardItem>
38+
<DashboardItem>
39+
<div class="text-center">
40+
Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’
41+
<p t-out="this.result.average_time" class="fs-1 fw-bold text-success"/>
42+
</div>
43+
</DashboardItem>
44+
</div>
1445
</Layout>
1546
</t>
1647
</templates>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
6+
static props = {
7+
slots: {
8+
type: Object,
9+
shape: {
10+
default: Object,
11+
},
12+
},
13+
size: {
14+
type: Number,
15+
default: 1,
16+
optional: true,
17+
},
18+
};
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.DashboardItem">
4+
<div class="card m-2" t-attf-style="width: {{ 18 * props.size }}rem; border-radius: 16px;">
5+
<div class="card-body">
6+
<t t-slot="default"/>
7+
</div>
8+
</div>
9+
</t>
10+
</templates>

estate/models/estate_property.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ def _compute_best_price(self):
7979

8080
@api.onchange("garden")
8181
def _onchange_garden(self):
82-
if self.garden:
83-
self.garden_area = 10
84-
self.garden_orientation = "north"
85-
else:
82+
self.garden_area = 10
83+
self.garden_orientation = "north"
84+
if not self.garden:
8685
self.garden_area = 0
8786
self.garden_orientation = None
8887

estate/views/estate_property_type_views.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
<list>
3535
<field name="name" string="Title"/>
3636
<field name="expected_price"/>
37-
<field name="state"/>
37+
<field name="state" widget="badge"
38+
decoration-success="state == 'new'"
39+
decoration-danger="state in ('sold','offer_accepted')"
40+
decoration-muted="state == 'cancelled'"
41+
decoration-warning="state == 'offer_received'" />
3842
</list>
3943
</field>
4044
</page>

estate/views/estate_property_views.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</group>
3636
<group>
3737
<field name="property_type_id" options="{'no_create': true}"/>
38-
<field name="expected_price" options="{'type': 'number', 'step': 100}"/>
38+
<field name="expected_price"/>
3939
<field name="selling_price"/>
4040
<field name="best_price" string="Best Offer"/>
4141
</group>
@@ -98,8 +98,14 @@
9898
<templates>
9999
<t t-name="card">
100100
<div>
101-
<div>
102-
<field class="fw-bold fs-4" name="name"/>
101+
<div class="d-flex justify-content-between align-items-center">
102+
<field class="fw-bold fs-3" name="name"/>
103+
<field name="state" class="fs-5"
104+
widget="badge"
105+
decoration-success="state == 'new'"
106+
decoration-danger="state in ('sold','offer_accepted')"
107+
decoration-muted="state == 'cancelled'"
108+
decoration-warning="state == 'offer_received'"/>
103109
</div>
104110
<div>
105111
<span>Expected Price: </span>
@@ -109,7 +115,7 @@
109115
<span>Best Offer: </span>
110116
<field name="best_price"/>
111117
</div>
112-
<div t-if="record.state.raw_value == 'offer_accepted'">
118+
<div t-if="record.state.raw_value == 'offer_accepted' or record.state.raw_value == 'sold' ">
113119
<span>Selling Price: </span>
114120
<field name="selling_price"/>
115121
</div>

0 commit comments

Comments
 (0)