Skip to content

Created estate module for technical training #345

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 28 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
129eddc
[ADD] estate: Completed exercies and task upto Chapter 5
mebh-odoo Feb 5, 2025
ba18491
[IMP] estate: Solved all the warnings and added licence in manifest file
mebh-odoo Feb 5, 2025
b2a6d4f
[IMP] estate: Completed with chapter 8 and added required models and …
mebh-odoo Feb 6, 2025
511cf79
[IMP] estate: added onchanges, model object and action and sql constr…
mebh-odoo Feb 9, 2025
0258160
[IMP] estate: added inline views, list order, attributes and option(i…
mebh-odoo Feb 10, 2025
f0028b0
[IMP] estate: added offers stat button, created offers list view, pyt…
mebh-odoo Feb 11, 2025
cc23df1
[ADD] estate_account: added estate_account module and done with linki…
mebh-odoo Feb 12, 2025
9aa04c0
[IMP] estate: Made changes according to coding guidelines and complet…
mebh-odoo Feb 14, 2025
5527349
[IMP] estate: completed restrict access to data and made changes to t…
mebh-odoo Feb 17, 2025
827fba2
[IMP] estate: removed errors.
mebh-odoo Feb 17, 2025
0644106
[IMP] estate: added demo data, chatter and completed till qweb.
mebh-odoo Feb 18, 2025
de66e75
[IMP] estate: added pdf report and web controllers
mebh-odoo Feb 19, 2025
963f54b
[IMP] estate: added unit test and completed wizard exercise
mebh-odoo Feb 20, 2025
49b452f
[IMP] estate: added webcontroller for website to show list of propert…
mebh-odoo Feb 20, 2025
ca0ca3f
[IMP] awesome_owl: added counter, props, props validation and todo list.
mebh-odoo Feb 21, 2025
6333cd5
[IMP] awesome_owl: added dynamic todo-list, generic cards with slots.
mebh-odoo Feb 24, 2025
d6f8507
[IMP] awesome_dashboard: added new layout and buttons.
mebh-odoo Feb 24, 2025
e9f1e7d
[IMP] awesome_dashboard: added dashboard item, api call, pie chart, c…
mebh-odoo Feb 25, 2025
f776574
[IMP] awesome_dashboard: added dashboard item, api call, pie chart
mebh-odoo Feb 25, 2025
9e4d05c
[IMP] awesome_dashboard: added reactive states
mebh-odoo Feb 26, 2025
8416555
[IMP] awesome_dashboard: remove unnecessary comment lines
mebh-odoo Feb 26, 2025
e1f4cdb
[IMP] awesome_dashboard: remove unnecessary comment lines
mebh-odoo Feb 26, 2025
e83e63d
[IMP] awesome_dashboard: updated dashboard for generic and extensive …
mebh-odoo Feb 26, 2025
d205704
[IMP] awesome_dashboard: added the required changes.
mebh-odoo Feb 26, 2025
38d4865
[ADD] owl_tutorials: added owl_tutorials module for owl practice.
mebh-odoo Apr 14, 2025
e894474
[IMP] owl_tutorials: added lifecycle methods for the fucntioning of c…
mebh-odoo Apr 14, 2025
57b3280
[IMP] owl_tutorials: added search functionality, on-click event handl…
mebh-odoo Apr 15, 2025
38bf690
[IMP] owl_tutorials: added view inheritance for list and kanban view.
mebh-odoo Apr 17, 2025
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_assets': [
'awesome_dashboard/static/src/dashboard/**/*',
],
},
'license': 'AGPL-3'
}
4 changes: 3 additions & 1 deletion awesome_dashboard/controllers/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

logger = logging.getLogger(__name__)


class AwesomeDashboard(http.Controller):
_name = "awesome.dashboard"

@http.route('/awesome_dashboard/statistics', type='json', auth='user')
def get_statistics(self):
"""
Expand All @@ -33,4 +36,3 @@ def get_statistics(self):
},
'total_amount': random.randint(100, 1000)
}

14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/cards/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @odoo-module **/

import { Component, xml } from "@odoo/owl";

export class NumberCard extends Component {
static template = xml`
<div class="card p-3 text-center">
<h6 class="fw-bold text-primary"> <t t-esc="props.title"/> </h6>
<div class="fs-1 fw-bold text-success">
<t t-esc="props.value"/>
</div>
</div>
`;
}
14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/cards/pie_chart_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @odoo-module **/

import { Component, xml } from "@odoo/owl";
import { PieChart } from "../dashboard/pie_chart/pie_chart";

export class PieChartCard extends Component {
static template = xml`
<div class="d-flex flex-column align-items-center">
<div class="fw-bold"><t t-esc="props.title"/></div>
<PieChart data="props.data"/>
</div>
`;
static components = { PieChart };
}
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.

38 changes: 38 additions & 0 deletions awesome_dashboard/static/src/dashboard/dailog/Dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";

export class DashboardConfigDialog extends Component {
static template = "awesome_dashboard.DashboardConfigDialog";
static components = { Dialog };
static props = ["title", "items", "disabledItems", "close"];

setup() {
const savedConfig = JSON.parse(localStorage.getItem("dashboard_config")) || [];
this.state = useState({
disabledItems: new Set(savedConfig.length ? savedConfig : this.props.disabledItems || [])
});
}

toggleItem = (itemId) => {
this.state.disabledItems = new Set(this.state.disabledItems);
if (this.state.disabledItems.has(itemId)) {
this.state.disabledItems.delete(itemId);
} else {
this.state.disabledItems.add(itemId);
}
};

saveConfig() {
const disabledItemsArray = [...this.state.disabledItems];
localStorage.setItem("dashboard_hidden_items", JSON.stringify(disabledItemsArray));

if (this.props.onSave) {
this.props.onSave(disabledItemsArray);
}

this.props.close();
}
}

18 changes: 18 additions & 0 deletions awesome_dashboard/static/src/dashboard/dailog/Dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<t t-name="awesome_dashboard.DashboardConfigDialog">
<Dialog title="'Dashboard Configuration'">
<div class="p-3">
<t t-foreach="props.items" t-as="item" t-key="item.id">
<div class="form-check">
<input type="checkbox" id="item-{{ item.id }}" class="form-check-input" t-att-checked="!state.disabledItems.has(item.id)" t-on-change="() => toggleItem(item.id)"/>
<label class="form-check-label" t-att-for="'item-' + item.id">
<t t-esc="item.description or 'Unnamed Item'"/>
</label>
</div>
</t>
</div>
<footer class="d-flex justify-content-end p-3">
<button class="btn btn-primary" t-on-click="saveConfig">Apply</button>
</footer>
</Dialog>
</t>
63 changes: 63 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/** @odoo-module **/

import { Component, onWillStart, useState, useEffect, reactive } 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/dashboard_item";
import { rpc } from "@web/core/network/rpc";
import {PieChart} from "./pie_chart/pie_chart"
import { items } from "./dashboard_items";
import { Dialog } from "@web/core/dialog/dialog";
import { DashboardConfigDialog } from "./dailog/Dialog";

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

setup(){
this.action = useService("action");
this.statisticsService = useState(useService("awesome_dashboard.statistics"));
this.state = reactive({ statistics: {}, disabledItems: [] });
this.items = registry.category("awesome_dashboard").getAll();

onWillStart(async () => {
this.state.statistics = await this.statisticsService.loadStatistics();
this.loadConfig();
});

useEffect(() => {
this.state.statistics = this.statisticsService.statistics.data;
});
}

loadConfig() {
const config = localStorage.getItem("dashboard_hidden_items");
this.state.disabledItems = config ? JSON.parse(config) : [];
}

openConfiguration() {
this.env.services.dialog.add(DashboardConfigDialog, {
items: this.items,
disabledItems: [...this.state.disabledItems],
onSave: (hiddenItems) => {
localStorage.setItem("dashboard_hidden_items", JSON.stringify(hiddenItems));
this.state.disabledItems = hiddenItems;
},
});
}

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

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

registry.category("lazy_components").add("awesome_dashboard.dashboard", AwesomeDashboard);
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.o_dashboard {
background-color: #d3d3d3;
padding: 20px;
}
.dashboard-item {
background-color: white;
border: 1px solid #ddd;
}
28 changes: 28 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout classname="'o_dashboard h-100'" t-props="{'controlPanel': {}}">
<div class="d-flex align-items-center">
<button t-on-click="openCustomers" class="btn btn-primary">Customer</button>
<button t-on-click="openLeads" type="button" class="ms-2 btn btn-primary" title="Leads">Leads</button>
<h4 class="ms-3">Dashboard</h4>
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
<t t-set-slot="control-panel-additional-actions">
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
</t>
</div>
<div class="d-flex gap-3 pt-3 ms-3" t-if="state.statistics">
<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(state.statistics) : {'data': 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,15 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";
static props = {
slot: { type: Object, optional: true },
size: { type: Number, optional: true },
};

static defaultProps = {
size: 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.DashboardItem">
<div class="dashboard-item p-3 shadow-sm rounded" t-att-style="'width:' + (18 * props.size) + 'rem;'">
<h5>
<t t-esc="props.title"/>
</h5>
<t t-slot="default" />
</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 @@
/** @odoo-module **/

import { PieChartCard } from "../cards/pie_chart_card";
import { NumberCard } from "../cards/number_card";
import { registry } from "@web/core/registry";

const items = [
{
id: "average_quantity",
description: "Average amount of t-shirts per order this month",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "Average amount of t-shirts per order this month",
value: data.average_quantity,
}),
},
{
id: "average_time",
description: "Average time for an order to go from 'new' to 'sent' or 'cancelled'",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "Avg. time from 'new' to 'sent/cancelled'",
value: data.average_time,
}),
},
{
id: "nb_new_orders",
description: "Number of new orders this month",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "New orders this month",
value: data.nb_new_orders,
}),
},
{
id: "nb_cancelled_orders",
description: "Number of cancelled orders this month",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "Cancelled orders this month",
value: data.nb_cancelled_orders,
}),
},
{
id: "total_amount",
description: "Total amount of new orders this month",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "Total amount of new orders",
value: data.total_amount,
}),
},
{
id: "orders_by_size",
description: "Shirt orders by size",
Component: PieChartCard,
size: 2,
props: (data) => ({
title: "Shirt orders by size",
data: data.orders_by_size,
}),
},
];

items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
});
43 changes: 43 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @odoo-module */

import { loadJS } from "@web/core/assets";
import { getColor } from "@web/core/colors/colors";
import { Component, onWillStart, useRef, onMounted, onWillUnmount } from "@odoo/owl";

export class PieChart extends Component {
static template = "awesome_dashboard.PieChart";
static props = {
label: String,
data: Object,
};

setup() {
this.canvasRef = useRef("canvas");
onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"]));
onMounted(() => {
this.renderChart();
});
onWillUnmount(() => {
this.chart.destroy();
});
}

renderChart() {
const labels = Object.keys(this.props.data);
const data = Object.values(this.props.data);
const color = labels.map((_, index) => getColor(index));
this.chart = new Chart(this.canvasRef.el, {
type: "pie",
data: {
labels: labels,
datasets: [
{
label: this.props.label,
data: data,
backgroundColor: color,
},
],
},
});
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml
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.PieChart">
<div t-att-class="'h-100 ' + props.class" t-ref="root">
<div class="h-100 position-relative" t-ref="container">
<canvas t-ref="canvas" />
</div>
</div>
</t>
</templates>
Loading