Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/launch.json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't push anything inside .vscode 💢

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run (Update)",
"type": "debugpy",
"request": "launch",
"python": "/usr/bin/python3",
"program": "/home/odoo/odoo/odoo-bin",
"console": "integratedTerminal",
"args": [
"--database", "rd-demo",
"--dev", "xml",
// "-u", "we_guarantee",
"--addons-path", "/home/odoo/enterprise,/home/odoo/odoo/addons,/home/odoo/tutorials",
"--log-level", "info",
"--limit-time-real=0",
"--limit-time-cpu=0",
],
"variablePresentation": {},
},
]
}
5 changes: 5 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
('remove', 'awesome_dashboard/static/src/dashboard/**/*'),

],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/**/*',
],
},
'license': 'AGPL-3'
Expand Down
10 changes: 0 additions & 10 deletions awesome_dashboard/static/src/dashboard.js

This file was deleted.

8 changes: 0 additions & 8 deletions awesome_dashboard/static/src/dashboard.xml

This file was deleted.

4 changes: 4 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.o_dashboard {
background-color: #f0f0f0;
}

35 changes: 35 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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";
import { DashboardItem } from "./dashboard_item";
import { PieChart } from "./pie_chart/pie_chart";
import { items } from "./dashboard_items";
import { _t } from "@web/core/l10n/translation";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, PieChart }
setup() {
this.action = useService("action");
this.result = useState(useService("awesome_dashboard.statistics"));
this.items = registry.category("awesome_dashboard").getAll();

}
openCustomers() {
this.action.doAction("base.action_partner_form");
}
openLeads() {

this.action.doAction({
type: 'ir.actions.act_window',
name: _t('CRM Leads'),
target: 'current',
res_model: 'crm.lead',
views: [[false,'list'],[false, 'form']],
});
}
}

registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);

24 changes: 24 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard" owl="1">
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button class="btn btn-secondary" t-on-click="openLeads">Leads</button>
</t>
<t t-set-slot="default">
<div class="o-awesome-dashboard-content" t-if="result.isReady">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem size="item.size || 1">
<t t-set="itemProp" t-value="item.props ? item.props(result) : {'data': result}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</t>
</Layout>
</t>

</templates>

19 changes: 19 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.dashboard_item";
static props = {
size: {
type: Number,
defaultProps: 1,
optional: true,
},
slots: {
type: Object,
},
};
get Width() {
return 18*this.props.size
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this in the xml. But I actually quite like it. Not sure about the capitalized variable name though 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i capitalized it so it can be destinguished from "width" inside "t-aff-style" in the corresponding xml file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should maybe name it something like itemWidth

}

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.dashboard_item" owl='1'>
<div class="card d-inline-block m-2" t-attf-style="width: {{Width}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

</templates>

71 changes: 71 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { NumberCard } from "./numbercard/number_card";
import { PieChartCard } from "./piechartcard/pirchart_card";
import { registry } from "@web/core/registry";

export const items = [
{
id: "average_quantity",
description: "Average amount of t-shirt",
Component: NumberCard,
props: (data) => ({
title: "Average amount of tees ordered this month",
value: data.average_quantity,
})
},

{
id: "average_time",
description: "Average time of an order",
Component: NumberCard,
props: (data) => ({
title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'",
value: data.average_time,
})
},

{
id: "nb_new_orders",
description: "Number of new orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of new orders this month",
value: data.nb_new_orders,
})
},

{
id: "nb_cancelled_orders",
description: "Number of cancelled orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders,
})
},

{
id: "total_amount",
description: "Total amount of new orders this month",
Component: NumberCard,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.total_amount,
})
},

{
id: "orders_pir_chart",
description: "Shirt order by size",
Component: PieChartCard,
props: (data) => ({
title: "Shirt order by size",
data: data.orders_by_size,
})
},

]

items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
})

14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/dashboard/numbercard/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from "@odoo/owl";

export class NumberCard extends Component {
static template = "awesome_dashboard.numbercard";
static props = {
title: {
type: String,
},
value: {
type: Number,
},
};
}

14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/dashboard/numbercard/number_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.numbercard" owl='1'>
<div class="d-flex flex-wrap">
<t t-esc="props.title"/>
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</div>
</t>

</templates>

40 changes: 40 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Component, onWillStart,useRef, onMounted, onWillUnmount } from "@odoo/owl";
import { loadJS } from "@web/core/assets";


export class PieChart extends Component {
static template = "awesome_dashboard.pie_chart";
static props = {
label: String,
data : Object,
}
setup(){
this.canvasRef = useRef("canvas_pie");
onWillStart(async () => loadJS("/web/static/lib/Chart/Chart.js"));
onMounted(()=> {
this.renderChart();
});

onWillUnmount(()=> {
this.chart?.destroy();
});

}

renderChart(){
this.chart = new Chart(this.canvasRef.el,{
type: 'pie',
data : {
labels : Object.keys(this.props.data),
datasets:[
{
label: this.props.label,
data : Object.values(this.props.data),
},
],
}
})

}
}

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.pie_chart" owl='1'>
<div t-att-class="'h-100 ' + props.class">
<div class="h-100 position-relative">
<canvas t-ref="canvas_pie" />
</div>
</div>
</t>

</templates>

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from "@odoo/owl";
import { PieChart } from "../pie_chart/pie_chart";

export class PieChartCard extends Component {
static components = { PieChart }
static template = "awesome_dashboard.piechartcard";
static props = {
title: {
type: String,
},
data: {
type: Object,
},
};
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.piechartcard" owl='1'>
<div t-att-class="'h-100 ' + props.class">
<div class="h-100 position-relative">
<t t-esc="props.title"/>
<PieChart data="props.data" label = "''"/>
</div>
</div>
</t>

</templates>

24 changes: 24 additions & 0 deletions awesome_dashboard/static/src/dashboard/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl"


const statisticsService = {
start() {

const statistics = reactive({isReady : false});

async function loadingData() {
const data = await rpc("/awesome_dashboard/statistics");
Object.assign(statistics,data,{isReady : true});

}

loadingData();
setInterval(loadingData, 10*60*1000);
return statistics;
},
};

registry.category("services").add("awesome_dashboard.statistics", statisticsService);

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, xml } from "@odoo/owl";
import {LazyComponent } from "@web/core/assets";
import { registry } from "@web/core/registry";

export class AwesomeDashboardLoader extends Component {
static components = { LazyComponent };
static template = xml `
<LazyComponent bundle="'awesome_dashboard.dashboard'" Component="'AwesomeDashboard'" props="props"/>
`;
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader);

Loading