-
Notifications
You must be signed in to change notification settings - Fork 2.6k
18.0 onboarding owl hasaa #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from 17 commits
874a1e0
32c21b4
21928ba
f8be1b7
41e82cc
a4fc171
0ecf95d
a5fc2c2
abb7b5e
ef33a66
34ffcc5
abb94b6
8c7d448
3dbc265
3f92bd4
f4f128c
350d4cf
d1388b1
8262cb2
fff2bf5
8dd8fcc
bce32b6
3a7ac6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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": {}, | ||
}, | ||
] | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.o_dashboard { | ||
background-color: #f0f0f0; | ||
} | ||
|
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); | ||
|
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> | ||
|
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, | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
optional: true, | ||
}, | ||
slots: { | ||
type: Object, | ||
}, | ||
}; | ||
get Width() { | ||
return 18*this.props.size | ||
} | ||
|
||
} | ||
|
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> | ||
|
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", | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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); | ||
}) | ||
|
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, | ||
}, | ||
}; | ||
} | ||
|
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> | ||
|
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), | ||
}, | ||
], | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
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"; | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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'> | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<div t-att-class="'h-100 ' + props.class"> | ||
<div class="h-100 position-relative"> | ||
<t t-esc="props.title"/> | ||
<PieChart data="props.data" label = "''"/> | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> | ||
|
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); | ||
|
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); | ||
|
There was a problem hiding this comment.
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 💢