Skip to content

[ADD] estate,*: added real estate, estate_account, and OWL dashboard modules #846

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

Draft
wants to merge 11 commits into
base: 18.0
Choose a base branch
from
Draft
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
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,9 @@
import { Component } from "@odoo/owl"

export class DashboardItem extends Component {
static template = "awesome_dashboard.dashboard_item"
static props = {
slots: { type: Object, shape: { default: Object } },
size: { type: Number, default: 1, optional: true }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.dashboard_item">
<div class="card m-2 border-dark pie-chart-card" t-attf-style="width: {{18 * this.props.size}}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,9 @@
import { Component } from "@odoo/owl";

export class NumberCard extends Component {
static template = "awesome_dashboard.number_card"
static props = {
title: { type: String },
value: { type: [Number, String] }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.number_card">
<h4><t t-out="props.title"/></h4>
<div class="fs-1 fw-bold text-success text-center"><t t-out="props.value"/>
</div>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, onWillStart, onMounted, useRef, onWillUpdateProps } from "@odoo/owl";
import { loadJS } from "@web/core/assets";
import { _t } from "@web/core/l10n/translation";


export class PieChartCard extends Component {
static template = "awesome_dashboard.pie_chart"

setup() {
this.canvasRef = useRef("canvas")

onWillStart(async () => {
await loadJS("/web/static/lib/Chart/Chart.js")
})
onMounted(() => {
this.renderChart();
});
onWillUpdateProps((nextProps) => {
if (this.chart) {
this.chart.destroy();
}
this.renderChart(nextProps.data);
});
}

renderChart() {
this.chart = new Chart(this.canvasRef.el.getContext("2d"), {
type: "pie",
data: {
labels: Object.keys(this.props.data),
datasets: [{
label: this.props.title,
data: Object.values(this.props.data),
backgroundColor: ["#007BFF", "#FFA500", "#808090"]
}]
},
options: {
responsive: true,
maintainAspectRatio: false
},
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.pie_chart">
<h4><t t-out="props.title"/></h4>
<div><canvas t-ref="canvas"/></div>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

const statisticsService = {
start() {
const stats = reactive({
nb_new_orders: 0,
total_amount: 0,
average_quantity: 0,
nb_cancelled_orders: 0,
average_time: 0,
orders_by_size: { m: 0, s: 0, xl: 0 }
});
const loadStatistics = async () => {
const result = await rpc("/awesome_dashboard/statistics");
if (result) {
Object.assign(stats, result);
}
};
loadStatistics();
setInterval(() => {
loadStatistics();
}, 10 * 60 * 1000);

return { data: stats };
}
}

registry.category("services").add("awesome_dashboard.statistics", statisticsService);
94 changes: 94 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Component, useState, onWillStart } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";
import { DashboardItem } from "@awesome_dashboard/dashboard/components/dashboard_item/dashboard_item";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem }

setup() {
this.action = useService("action")
this.dialog = useService("dialog")
this.statisticsService = useService("awesome_dashboard.statistics");
this.statistics = useState(this.statisticsService.data);
this.display = { controlPanel: {} }
this.items = registry.category("awesome_dashboard").getAll();
this.state = useState({
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
})
}

openCustomersKanban() {
this.action.doAction("base.action_partner_form")
}

openLeads() {
this.action.doAction({
type: "ir.actions.act_window",
name: "Leads",
res_model: "crm.lead",
views: [
[false, "list"],
[false, "form"]
]
})
}

openConfigDialog() {
this.dialog.add(ConfigurationDialog, {
items: this.items,
disabledItems: this.state.disabledItems,
onUpdateConfiguration: this.updateConfiguration.bind(this),
})
}

updateConfiguration(newDisabledItems) {
this.state.disabledItems = newDisabledItems;
}

}

class ConfigurationDialog extends Component {
static template = "awesome_dashboard.ConfigurationDialog";
static components = { CheckBox, Dialog };
static props = {
items: { type: Array },
disabledItems: { type: Array },
onUpdateConfiguration: { type: Function },
close: { type: Function }
};

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

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

onChange(checked, changedItem) {
changedItem.enabled = checked;
const newDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id)

browser.localStorage.setItem(
"disabledDashboardItems",
newDisabledItems,
);

this.props.onUpdateConfiguration(newDisabledItems);
}
}

registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
6 changes: 6 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@media (max-width: 767px) {
.pie-chart-card {
width: 100% !important;
margin-bottom: 16px;
}
}
39 changes: 39 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout display="display" class="bg-secondary">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="() => this.openCustomersKanban()">Customers</button>
<button class="btn btn-primary" t-on-click="() => this.openLeads()">Leads</button>
</t>
<t t-set-slot="control-panel-additional-actions">
<button t-on-click="() => this.openConfigDialog()" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog" />
</button>
</t>
<div class="d-flex flex-wrap">
<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(statistics) : {'data' : statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>
</t>
<t t-name="awesome_dashboard.ConfigurationDialog">
<Dialog title="'Items configuration'">
Which cards do you want to see?
<t t-foreach="items" t-as="item" t-key="item.id">
<CheckBox value="item.enabled" onChange="(e) => this.onChange(e, item)">
<t t-out="item.description"/>
</CheckBox>
</t>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="() => this.done()">
Done
</button>
</t>
</Dialog>
</t>
</templates>
65 changes: 65 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { NumberCard } from "@awesome_dashboard/dashboard/components/number_card/number_card";
import { registry } from "@web/core/registry";
import { PieChartCard } from "@awesome_dashboard/dashboard/components/pie_chart_card/pie_chart_card";
import { _t } from "@web/core/l10n/translation";


const items = [
{
id: "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: "amount_new_orders",
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: "average_quantity",
description: _t("Average amount of t-shirt by order this month"),
Component: NumberCard,
props: (data) => ({
title: _t("Average amount of t-shirt by order this month"),
value: data.average_quantity
})
},
{
id: "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: "average_time",
description: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"),
Component: NumberCard,
props: (data) => ({
title: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"),
value: data.average_time
})
},
{
id: "pie_chart",
description: _t("Shirt orders by size"),
Component: PieChartCard,
size: 2,
props: (data) => ({
title: _t("Shirt orders by size"),
data: data.orders_by_size
})
}
]

items.forEach((item) => { registry.category("awesome_dashboard").add(item.id, item) })
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component, xml } from "@odoo/owl";
import { LazyComponent } from "@web/core/assets";
import { registry } from "@web/core/registry";

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

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardAction);
2 changes: 1 addition & 1 deletion awesome_gallery/models/ir_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class ActWindowView(models.Model):

view_mode = fields.Selection(selection_add=[
('gallery', "Awesome Gallery")
], ondelete={'gallery': 'cascade'})
], ondelete={'gallery': 'cascade'})
1 change: 1 addition & 0 deletions awesome_owl/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'web/static/lib/bootstrap/scss/_variables.scss',
'web/static/lib/bootstrap/scss/_maps.scss',
('include', 'web._assets_bootstrap'),
("include", "web._assets_bootstrap_backend"),
('include', 'web._assets_core'),
'web/static/src/libs/fontawesome/css/font-awesome.css',
'awesome_owl/static/src/**/*',
Expand Down
15 changes: 15 additions & 0 deletions awesome_owl/static/src/components/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, useState } from "@odoo/owl"

export class Card extends Component {
static template = "awsome_owl123.Card";
static props = {
title: { type: String },
slots: { type: Object, optional: true },
};
setup() {
this.state = useState({ open: true });
}
toggle() {
this.state.open = !this.state.open;
}
}
Loading