Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.vscode/launch.js
26 changes: 26 additions & 0 deletions .vscode/launch.json
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": {},
},
]
}
1 change: 1 addition & 0 deletions awesome_dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import models
7 changes: 6 additions & 1 deletion awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
'version': '0.1',
'application': True,
'installable': True,
'depends': ['base', 'web', 'mail', 'crm'],
'depends': ['base', 'web', 'mail', 'crm', 'sale'],

'data': [
'views/views.xml',
],
'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
2 changes: 1 addition & 1 deletion awesome_dashboard/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
1 change: 1 addition & 0 deletions awesome_dashboard/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_users_settings
10 changes: 10 additions & 0 deletions awesome_dashboard/models/res_users_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# models/res_users.py
from odoo import models, fields


class ResUsersSettings(models.Model):
_inherit = ["res.users.settings"]

disabled_items = fields.Char(
string="Awesome Dashboard Disabled Items",
)
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";


export class ConfigDialog extends Component {
static template = "awesome_dashboard.ConfigDialog";
static components = { Dialog, CheckBox };
static props = ["close", "items", "disabledItems", "onUpdateConfigs"];
setup() {

this.items = useState(this.props.items.map((item) => {
return {
...item,
enabled: !this.props.disabledItems.includes(item.id),
}
}));

}

onChange(checkedItems, Item) {
Item.enabled = checkedItems;

const updatedDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id);

this.props.onUpdateConfigs(updatedDisabledItems);
}

done() {
this.props.close();
}

}

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

<t t-name="awesome_dashboard.ConfigDialog" >
<Dialog title="'Dashboard items configuration'">
Which cards do you whish to see ?
<t t-foreach="items" t-as="item" t-key="item.id">
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
<t t-esc="item.description"/>
</CheckBox>
</t>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="done">
Done
</button>
</t>
</Dialog>
</t>

</templates>

11 changes: 11 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.o_dashboard {
background-color: #f0f0f0;
}
@media (max-width: 767.98px) {
.o_dashboard .card {
width: 100% !important; /* force full width */
max-width: 100% !important;
display: block !important; /* no inline-block on mobile */
}
}

52 changes: 52 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, 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 { ConfigDialog } from "./config_dialog/config_dialog";
import { _t } from "@web/core/l10n/translation";
import { user } from "@web/core/user";

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

this.state = useState({
disabledItems: user.settings.disabled_items || [],
});
}
openCustomers() {
this.action.doAction("base.action_partner_form");
}
openConfigs() {
this.dialog.add(ConfigDialog, {
items: this.items,
disabledItems: this.state.disabledItems,
onUpdateConfigs: this.updateConfigs.bind(this),
});
}

updateConfigs(newDisabledItems) {
this.state.disabledItems = newDisabledItems;
user.setUserSettings("disabled_items", this.state.disabledItems)
}

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);

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

<t t-name="awesome_dashboard.AwesomeDashboard" >
<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>
<button t-on-click="openConfigs" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</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 t-if="!state.disabledItems.includes(item.id)" 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.DashboardItem";
static defaultProps = { size: 1};
static props = {
size: {
type: Number,
optional: true,
},
slots: {
type: Object,
},
};
get itemWidth() {
return 18*this.props.size
}
}

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.DashboardItem">
<div class="card d-inline-block m-2" t-attf-style="width: {{itemWidth}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

</templates>

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

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

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

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

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

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

{
id: "orders_pie_chart",
description: _t("Shirt order by size"),
Component: PieChartCard,
props: (data) => ({
title: _t("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" >
<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>

Loading