10000 [ADD] estate, estate_account, awesome_owl, awesome_dashboard: tutorial modules by pavy-odoo · Pull Request #761 · odoo/tutorials · GitHub
[go: up one dir, main page]

Skip to content

[ADD] estate, estate_account, awesome_owl, awesome_dashboard: tutorial modules #761

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 29 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
29 commits
Select commit Hold shift + click to select a range
25cc118
[ADD] estate: initialize module with manifest file
pavy-odoo Apr 23, 2025
f28831d
[ADD] estate: implement models for estate properties
pavy-odoo Apr 23, 2025
a7342c6
[ADD] estate: expand estate property model with additional fields
pavy-odoo Apr 23, 2025
ef3744e
[ADD] estate: add access control for estate property model
pavy-odoo Apr 23, 2025
82e69fb
[IMP] estate: update module version and enhance manifest details
pavy-odoo Apr 23, 2025
3ef3a1b
[IMP] estate: rename module and add estate property views
pavy-odoo Apr 24, 2025
88da444
[ADD] estate: enhance property model with additional fields and defau…
pavy-odoo Apr 24, 2025
8b64fcc
[IMP] estate: enhance property views with additional fields and impro…
pavy-odoo Apr 24, 2025
326f856
[ADD] estate: add state field to property form and enhance search vie…
pavy-odoo Apr 24, 2025
4d1c849
[ADD] estate: add estate property type model and views; update menus …
pavy-odoo Apr 24, 2025
25545e5
[IMP] estate: implement property offers and tags; enhance property mo…
pavy-odoo Apr 25, 2025
cc9ac0b
[IMP] estate: format code for consistency; following standard code st…
pavy-odoo Apr 28, 2025
0b54412
[IMP] estate: enhance property and offer models with new fields and m…
pavy-odoo Apr 29, 2025
94b71d0
[IMP] estate: add SQL constraints for expected and selling prices in …
pavy-odoo Apr 29, 2025
77a7e86
[IMP] estate: update views and models; add ordering, new fields, and …
pavy-odoo May 1, 2025
8523b10
[IMP] estate: add inheritance for res.users to link properties; updat…
pavy-odoo May 2, 2025
f07e781
[IMP] estate: update manifest and views; enhance res.users model with…
pavy-odoo May 2, 2025
d4c35a8
[IMP] estate_account: initialize module with manifest and model impor…
pavy-odoo May 5, 2025
bc0753a
[IMP] estate: add kanban view for properties
pavy-odoo May 5, 2025
e24aeaa
[IMP] estate_account: remove debug print statements
pavy-odoo May 5, 2025
ac70966
[IMP] awesome_owl: implement playground, card, counter, todo list com…
pavy-odoo May 7, 2025
8d9c143
[IMP] awesome_dashboard: complete awesome dashboard module
pavy-odoo May 8, 2025
4793d26
[IMP] estate: remove vscode launch config; LF line endings
pavy-odoo May 11, 2025
4a0c1a8
[IMP] awesome_owl: adding missing newline
pavy-odoo May 11, 2025
d9842d2
[IMP] estate: add demo data and security groups
pavy-odoo May 12, 2025
304fe57
[IMP] estate: add images to static assets
pavy-odoo May 12, 2025
7962039
[IMP] estate: add image field to estate property model
pavy-odoo May 12, 2025
2484058
[IMP] estate: standardize state terminology from 'cancelled' to 'canc…
pavy-odoo May 12, 2025
e032fb4
[IMP] estate: add report templates and security rules
pavy-odoo May 13, 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
4 changes: 4 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
'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'
}
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.

88 changes: 88 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 "./dashboarditem/dashboarditem"
import { PieChart } from "./pie_chart/pie_chart";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";

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

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

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

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

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

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

class ConfigurationDialog extends Component {
static template = "awesome_dashboard.ConfigurationDialog";
static components = { Dialog, CheckBox };
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];

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);
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: rgb(255, 240, 254);
}
40 changes: 40 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout display="display" className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="openCustomerView">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</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>
</t>
<div class="d-flex flex-wrap" t-if="statistics.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(statistics) : {'data': statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>
</t>
<t t-name="awesome_dashboard.ConfigurationDialog">
<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>
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 "./number_card/number_card";
import { PieChartCard } from "./pie_chart_card/pie_chart_card";
import { registry } from "@web/core/registry";

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

items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
});
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 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.DashboardItem">
<div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component } from "@odoo/owl";

export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: {
type: String,
},
value: {
type: Number,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.NumberCard" owl="1">
<t t-esc="props.title"/>
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</t>
</templates>
41 changes: 41 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,41 @@
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @odoo-module */

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

export class PieChartCard extends Component {
static template = "awesome_dashboard.PieChartCard";
static components = { PieChart }
static props = {
title: {
type: String,
},
values: {
type: Object,
},
}
}
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.PieChartCard" owl="1">
<t t-esc="props.title"/>
<PieChart data="props.values" label="''"/>
</t>
</templates>
21 changes: 21 additions & 0 deletions awesome_dashboard/static/src/dashboard/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

const statisticsService = {
start() {
const statistics = reactive({ isReady: false });

async function loadData() {
const updates = await rpc("/awesome_dashboard/statistics");
Object.assign(statistics, updates, { isReady: true });
}

setInterval(loadData, 10*60*1000);
loadData();

return statistics;
}
}

registry.category("services").add("awesome_dashboard.statistics", statisticsService);
Loading
0