Skip to content

[ADD] estate: Real Estate Property Management Module #889

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 12 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
3 changes: 3 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
],
'awesome_dashboard.dashboard:': [
'awesome_dashboard/static/src/dashboard/**/*'
],
},
'license': 'AGPL-3'
}
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.

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 components = {}
static props = {
title: {
type: String
},
value: {
type: Number | String
}
}
}
11 changes: 11 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,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="awesome_dashboard.numberCard">
<h2 class="text-lg-center">
<t t-esc="props.title"/>
</h2>
<div class="text-success text-bold text-lg-center" style="font-size: 38px; font-weight: bold">
<t t-esc="props.value"/>
</div>
</t>
</templates>
53 changes: 53 additions & 0 deletions awesome_dashboard/static/src/dashboard/PieChartCard/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/** @odoo-module **/

import { Component, onWillStart, useRef, useEffect } from "@odoo/owl";
import { loadJS } from '@web/core/assets';

export class PieChart extends Component {
static template = "awesome_dashboard.PieChart";

static props = {
title: {
type: String,
},
value: {
type: String | Number,
}
}

setup() {
this.canvasRef = useRef("canvas");
onWillStart(async () => {
await loadJS("/web/static/lib/Chart/Chart.js")
});

useEffect(() => {
this.createChart();
return () => this.chart?.destroy();
});
}

getChartConfig() {
if (!this.props.value) return {};
return {
type: 'pie',
data: {
labels: Object.keys(this.props.value),
datasets: [{
data: Object.values(this.props.value),
}]
},
options: {
aspectRatio: 2,
}
}
}

createChart() {
if (this.chart) {
this.chart.destroy();
}
const config = this.getChartConfig();
this.chart = new Chart(this.canvasRef.el, config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChart">
<canvas height="500" width="500" t-ref="canvas"/>
</t>
</templates>
79 changes: 79 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/** @odoo-module **/

import { _t } from "@web/core/l10n/translation";
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 "./PieChartCard/pie_chart";
import { Component, useState } from "@odoo/owl";
import { DashboardDialog } from "../dashboard_dialog/dashboard_dialog";
import { browser } from "@web/core/browser/browser";

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

setup() {
this.action = useService("action");
this.dialog = useService("dialog");
this.statistics = useService("awesome_dashboard.statistics");
this.result = useState(this.statistics.stats);
this.state = useState({ metricConfigs: {} });
this.items = registry.category("awesome_dashboard_cards").get("awesome_dashboard.Cards");
this.getBrowserCookie();
}

openDialog() {
this.dialog.add(DashboardDialog, {
metrics: this.items,
metricConfigs: this.state.metricConfigs,
closeDialog: this.closeDialog.bind(this),
updateMetricConfigCallback: this.updateMetricConfig.bind(this)
});
}

closeDialog() {
this.getBrowserCookie();
}

updateMetricConfig(updated_metricConfig) {
this.state.metricConfigs = updated_metricConfig;
this.setBrowserCookie();
}

setBrowserCookie() {
browser.localStorage.setItem(
"awesome_dashboard.metric_configs", JSON.stringify(this.state.metricConfigs)
);
}

getBrowserCookie() {
const metric_cookie_data = browser.localStorage.getItem("awesome_dashboard.metric_configs");
if (metric_cookie_data) {
this.state.metricConfigs = JSON.parse(metric_cookie_data);
} else {
const initialMetricState = {};
for (const metric of this.items) {
initialMetricState[metric.id] = true;
}
this.state.metricConfigs = initialMetricState;
}
}

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

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

registry.category("lazy_components").add("awesome_dashboard.LazyComponent", AwesomeDashboard);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: white;
}
31 changes: 31 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout display="{ controlPanel: {} }" className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button type="button" class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button type="button" class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<t t-set-slot="control-panel-additional-actions">
<button class="d-print-none btn p-0 border-0" data-hotkey="u" t-on-click="openDialog" data-tooltip="Actions">
<i class="fa fa-fw fa-cog"/>
</button>
</t>

<div class="d-flex flex-wrap gap-3 m-3">
<div class="d-flex flex-wrap gap-3">
<t t-foreach="items" t-as="item" t-key="item.id">
<t t-if="state.metricConfigs[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>
</t>
</div>
</div>
</Layout>
</t>

</templates>
69 changes: 69 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import { NumberCard } from "./NumberCard/number_card";
import { PieChart } from "./PieChartCard/pie_chart";
import { registry } from "@web/core/registry";

export const dashboardCards = [
{
id: "nb_new_orders",
description: "New t-shirt orders this month.",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Number of new orders this month",
value: data.nb_new_orders,
}),
},
{
id: "total_amount",
description: "New orders this month.",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Total amount of new order this month",
value: data.total_amount,
}),
},
{
id: "average_quantity",
description: "Average amount of t-shirt.",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Average amount of t-shirt by order this month",
value: data.average_quantity,
}),
},
{
id: "nb_cancelled_orders",
description: "Cancelled orders this month.",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders,
}),
},
{
id: "average_time",
description: "Average time for an order to reach conclusion (sent or cancelled).",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'",
value: data.average_time,
}),
},
{
id: "orders_by_size",
description: "T-shirt orders grouped by their size.",
Component: PieChart,
size: 2,
props: (data) => ({
title: "T-shirt order by size",
value: data.orders_by_size,
}),
}
]

registry.category("awesome_dashboard_cards").add("awesome_dashboard.Cards", dashboardCards);
40 changes: 40 additions & 0 deletions awesome_dashboard/static/src/dashboard/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @odoo-module **/

import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

const statisticsObj = reactive({
nb_new_orders: 0,
total_amount: 0,
average_quantity: 0,
nb_cancelled_orders: 0,
average_time: 0,
orders_by_size: {}
});

const loadStatistics = async() => {
const result = await rpc("/awesome_dashboard/statistics");
statisticsObj.nb_new_orders = result.nb_new_orders;
statisticsObj.total_amount = result.total_amount;
statisticsObj.average_quantity = result.average_quantity;
statisticsObj.nb_cancelled_orders = result.nb_cancelled_orders;
statisticsObj.average_time = result.average_time;
statisticsObj.orders_by_size = result.orders_by_size;
}

export const loadStatService = {
dependencies: [],
start () {
loadStatistics();
setInterval(loadStatistics, 60 * 1000 * 10);

return {
get stats() {
return statisticsObj;
},
}
}
}

registry.category("services").add("awesome_dashboard.statistics", loadStatService);
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 { registry } from "@web/core/registry";
import { LazyComponent } from "@web/core/assets";

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

registry.category("actions").add("awesome_dashboard.dashboard", LazyDashboardLoader);
39 changes: 39 additions & 0 deletions awesome_dashboard/static/src/dashboard_dialog/dashboard_dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";

export class DashboardDialog extends Component {
static template = "awesome_dashboard.DashboardDialog";
static components = { Dialog, CheckBox }
static props = {
close: Function,
updateMetricConfigCallback: Function,
closeDialog: Function,
metrics: {
type: Object,
},
metricConfigs: {
type: Object,
}
}

setup() {
this.state = useState({
metricConfigs: this.props.metricConfigs
})
}

applyChanges() {
this.props.updateMetricConfigCallback(this.state.metricConfigs);
this.props.close();
}

toggleMetricConfig(itemID, checked) {
this.state.metricConfigs[itemID] = checked;
}

closeDialog() {
this.props.closeDialog();
this.props.close();
}
}
Loading