Skip to content

[ADD] estate,*: implement real estate management with accounting integration #842

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 15 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.

55 changes: 55 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 "@awesome_dashboard/dashboard/dashboardItem/dashboarditem";
import { rpc } from "@web/core/network/rpc";
import { PieChart } from "@awesome_dashboard/dashboard/pieChart/piechart";

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

setup(){
const dashboardItemsRegistry = registry.category("awesome_dashboard");
this.items = dashboardItemsRegistry.getAll();
this.action = useService("action");
this.statisticsService = useService("awesome_dashboard.statistics");
this.state = useState({ statistics: this.statisticsService.statistics });
this.displayState = useState({
disabledItems: [],
isLoading: true,
});
onWillStart(async () => {
try {
const fetchedDisabledItems = await rpc("/web/dataset/call_kw/res.users/get_dashboard_settings", {
model: 'res.users',
method: 'get_dashboard_settings',
args: [],
kwargs: {},
});
this.displayState.disabledItems = fetchedDisabledItems;
} catch (error) {
console.error("Error loading initial dashboard settings from server:", error);
this.displayState.disabledItems = [];
} finally {
this.displayState.isLoading = false;
}
});
}

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

openLeadsView() {
this.action.doAction({
type: 'ir.actions.act_window',
target: 'current',
res_model: 'crm.lead',
views: [[false, 'list'], [false, 'form']]
})
}
}

registry.category("lazy_components").add("AwesomeDashboard", 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: gray;
}
21 changes: 21 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
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.AwesomeDashboard">
<Layout className="'o_dashboard h-100'" display="{controlPanel: {} }">
<t t-set-slot="control-panel-create-button">
<button type="button" class="btn btn-primary o-kanban-button-new" t-on-click="openCustomerView">Customer</button>
<button type="button" class="btn btn-primary o-kanban-button-new" t-on-click="openLeadsView">Leads</button>
</t>
<div class="dashboard-items">
<t t-foreach="this.items" t-as="item" t-key="item.id">
<DashboardItem size="item.size || 1"
t-if="!this.displayState.disabledItems.includes(item.id)">
<t t-set="itemProp" t-value="item.props ? item.props(this.state.statistics) : {'data': this.state.statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>
</t>
</templates>
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.DashboardItem"

static props = {
size: { type: Number, optional: true, default: 1 },
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<t t-name="awesome_dashboard.DashboardItem">
<t t-set="itemSize" t-value="props.size or 1"/>
<div class="card shadow-sm rounded border-secondary m-2"
t-attf-style="width: #{18 * itemSize}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/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";

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

}
registry.category("actions").add("awesome_dashboard.dashboard", DashboardComponentLoader);
72 changes: 72 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/** @odoo-module **/

import { NumberCard } from "@awesome_dashboard/dashboard/numbercard/numbercard";
import { PieChartCard } from "@awesome_dashboard/dashboard/pieChartCard/pie_chart_card";
import { registry } from "@web/core/registry";
import { _t } from "@web/core/l10n/translation";

const items = [
{
id: "nb_new_orders",
description: _t("The number of new orders, this month"),
Component: NumberCard,
size: 1,
props: (data) => ({
title: _t("New Orders This Month:"),
value: data.data.nb_new_orders
}),
Comment on lines +14 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make use of js esLint tool for proper linting the code available in the web/tools

},
{
id: "total_amount",
description: _t("The total amount of orders, this month"),
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Total Amount This Month:",
value: data.data.total_amount
}),
},
{
id: "average_quantity",
description: _t("The average number of t-shirts by order"),
Component: NumberCard,
size: 1,
props: (data) => ({
title: _t("Avg. T-Shirts per Order:"),
value: data.data.average_quantity
}),
},
{
id: "nb_cancelled_orders",
description: _t("The number of cancelled orders, this month"),
Component: NumberCard,
size: 1,
props: (data) => ({
title: _t("Cancelled Orders:"),
value: data.data.nb_cancelled_orders
}),
},
{
id: "average_time",
description: _t("The average time (in hours) elapsed between the moment an order is created, and the moment is it sent"),
Component: NumberCard,
size: 1,
props: (data) => ({
title: _t("Avg. Time New → Sent/Cancelled:"),
value: data.data.average_time
}),
},
{
id: "orders_by_size",
description: _t("Number of shirts ordered based on size"),
Component: PieChartCard,
size: 3,
props: (data) => ({
title: _t("Shirt orders by size:"),
value: data.data.orders_by_size
}),
}
]
items.forEach((item) => {
registry.category("awesome_dashboard").add(item.id, item)
});
15 changes: 15 additions & 0 deletions awesome_dashboard/static/src/dashboard/numbercard/numbercard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";

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

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

get translatedTitle() {
return _t(this.props.title);
}
}
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/numbercard/numbercard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<t t-name="awesome_dashboard.NumberCard">
<div class="card shadow-sm rounded border-0 m-2">
<div class="card-body text-center">
<span class="card-title d-block mb-1 fw-bold text-muted">
<t t-out="translatedTitle"/>
</span>
<span class="h2 mb-0 fw-semibold text-primary">
<t t-esc="props.value"/>
</span>
</div>
</div>
</t>
6 changes: 6 additions & 0 deletions awesome_dashboard/static/src/dashboard/pieChart/pieChart.xml
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 t-ref="pie_chart_canvas"/>
</t>
</templates>
63 changes: 63 additions & 0 deletions awesome_dashboard/static/src/dashboard/pieChart/piechart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Component, onWillStart, useRef, onMounted, useEffect, onWillUnmount } from "@odoo/owl";
import { loadJS } from "@web/core/assets"

export class PieChart extends Component {
static template = "awesome_dashboard.Piechart";
static props = {
data: { type: Object },
onSliceClick: { type: Function, optional: true },
};
setup() {
this.chart = null;
this.pieChartCanvasRef = useRef("pie_chart_canvas");

onWillStart(async () => {
await loadJS("/web/static/lib/Chart/Chart.js");
})

this.chartData = {
labels: Object.keys(this.props.data),
datasets: [{
data: Object.values(this.props.data)
}]
};

onMounted(() => {
this.makePieChart();
})

this.cleanupPieChart = () => {
if (this.chart) {
this.chart.destroy();
this.chart = null;
}
};

onWillUnmount(this.cleanupPieChart);

useEffect(() => {
this.cleanupPieChart();
if (this.pieChartCanvasRef.el) {
this.makePieChart();
}
}, () => [this.props.data])
}

makePieChart() {
this.chart = new Chart(this.pieChartCanvasRef.el, {
type: "pie",
data: this.chartData,
options: {
responsive: true,
maintainAspectRatio: false,
onClick: (event, elements) => {
if (elements.length > 0) {
if (this.props.onSliceClick) {
this.props.onSliceClick(this.chartData.labels[elements[0].index]);
}
}
}
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from "@odoo/owl";
import { PieChart } from "@awesome_dashboard/dashboard/pieChart/piechart";
import { useService } from "@web/core/utils/hooks";
import { _t } from "@web/core/l10n/translation";

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

static props = {
title: { type: String },
data: { type: Object }
}

setup() {
this.action = useService("action");
}

get translatedTitle() {
return _t(this.props.title);
}

get translatedValue() {
return _t(this.props.value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChartCard">
<div class="card m-2 border-0 shadow-sm rounded">
<span class="mb-0 fw-bold text-primary">
<strong>
<t t-esc="translatedTitle" />
</strong>
</span>
<span class="align-items-center">
<t t-if="this.props.value">
<PieChart data="translatedValue" />
</t>
<t t-else="">
<div>
<t t-out="_t('Loading Chart...')" />
</div>
</t>
</span>
</div>
</t>
</templates>
35 changes: 35 additions & 0 deletions awesome_dashboard/static/src/dashboard/statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { rpc } from "@web/core/network/rpc";
import { registry } from "@web/core/registry";
import { reactive } from "@odoo/owl";

const statisticsService = {
start() {
const statistics = reactive({ data: null, loading: true, error: null });

async function fetchStatistics() {
statistics.loading = true;
statistics.error = null;
try {
const response = await rpc("/awesome_dashboard/statistics");
statistics.data = response;
} catch (e) {
statistics.error = e;
} finally {
statistics.loading = false;
}
}

async function fetchStatisticsRecursively() {
await fetchStatistics();
setTimeout(fetchStatisticsRecursively, 600000);
}

fetchStatisticsRecursively();

return {
statistics,
reload: fetchStatistics
};
},
};
registry.category("services").add("awesome_dashboard.statistics", statisticsService);
Loading