ch2.9 make is generic

This commit is contained in:
Matt Marcha 2024-09-27 12:10:06 -10:00
parent 7aa696f174
commit 089ac45df2
9 changed files with 114 additions and 36 deletions

View file

@ -5,11 +5,11 @@ import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks"
import { DashboardItem } from "./dashboard_item/dashboard_item";
import { Piechart } from "./piechart/piechart";
import { items } from "./dashboard_items";
class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, Piechart};
static components = { Layout, DashboardItem};
setup() {
this.display = {
@ -19,6 +19,8 @@ class AwesomeDashboard extends Component {
this.action = useService("action");
this.stats = useState(useService('awesome_dashboard.statistics'));
this.items = items;
}
openCustomers() {

View file

@ -8,40 +8,12 @@
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<div class="d-flex flex-wrap" t-if="stats.isReady">
<DashboardItem>
Number of new orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-out="stats.nb_new_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Total amount of new orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-out="stats.total_amount"/>
</div>
</DashboardItem>
<DashboardItem>
Average amount of t-shirt by order this month
<div class="fs-1 fw-bold text-success text-center">
<t t-out="stats.average_quantity"/>
</div>
</DashboardItem>
<DashboardItem>
Number of cancelled orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-out="stats.nb_cancelled_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Average time for an order to go from new to sent or cancelled
<div class="fs-1 fw-bold text-success text-center">
<t t-out="stats.average_time"/>
</div>
</DashboardItem>
<DashboardItem size='4'>
Shirt orders by size
<Piechart data="stats.orders_by_size" label="'Shirt orders by size'"/>
</DashboardItem>
<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(stats) : {'data': stats}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>
</t>

View file

@ -0,0 +1,60 @@
/** @odoo-module */
import { NumberCard } from "./number_card/number_card";
import { PieChartCard } from "./pie_chart_card/pie_chart_card";
export const items = [
{
id: "average_quantity",
description: "Average amount of t-shirt",
Component: NumberCard,
props: (data) => ({
title: "Average amount of t-shirt by order this month",
value: data.average_quantity,
})
},
{
id: "average_time",
description: "Average time for 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: "number_new_orders",
description: "New orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of new orders this month",
value: data.nb_new_orders,
})
},
{
id: "cancelled_orders",
description: "Cancelled orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders,
})
},
{
id: "amount_new_orders",
description: "amount orders this month",
Component: NumberCard,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.total_amount,
})
},
{
id: "pie_chart",
description: "Shirt orders by size",
Component: PieChartCard,
size: 2,
props: (data) => ({
title: "Shirt orders by size",
values: data.orders_by_size,
})
}
]

View file

@ -0,0 +1,13 @@
/** @odoo-module */
import { Component } from "@odoo/owl";
export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: {
type: String,
},
value: {
type: Number,
}
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.NumberCard" owl="1">
<t t-esc="props.title"/>
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</t>
</templates>

View file

@ -0,0 +1,15 @@
/** @odoo-module */
import { Component } from "@odoo/owl";
import { Piechart } from "../pie_chart/pie_chart";
export class PieChartCard extends Component {
static template = "awesome_dashboard.PieChartCard";
static components = { Piechart }
static props = {
title: {
type: String,
},
values: {
type: Object,
},
}
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChartCard" owl="1">
<t t-esc="props.title"/>
<Piechart data="props.values" label="''"/>
</t>
</templates>