-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[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
zadh-odoo
wants to merge
11
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-zadh
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3f513ae
[ADD] estate: initial module for real estate properties
zadh-odoo b1b4605
[IMP] estate: implement security, UI actions, and basic views
zadh-odoo 74f6cce
[IMP] esatate: added relations, computed fields, and actions
zadh-odoo 7b8e99d
[IMP] estate: add data constraints and UI Changes
zadh-odoo 6f78c66
[ADD] estate_account: added estate_account module
zadh-odoo b92ab47
[IMP] estate, estate_account: implement data access restrictions and …
zadh-odoo f4747d4
[IMP] estate, estate_account: implement and extend PDF property reports
zadh-odoo c135766
[ADD] estate: add unit tests for property business logic
zadh-odoo f61c66b
[IMP] awesome_owl: add basic Owl components as part of JS framework t…
zadh-odoo f093f18
[ADD] awesome_dashboard: implement dashboard module using owl
zadh-odoo 112b3af
[FIX] estate,estate_estate,awesome_owl,awesome_dashboard: fix issues …
zadh-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
9 changes: 9 additions & 0 deletions
9
awesome_dashboard/static/src/dashboard/components/number_card/number_card.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
awesome_dashboard/static/src/dashboard/components/number_card/number_card.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
43 changes: 43 additions & 0 deletions
43
awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
30 changes: 30 additions & 0 deletions
30
awesome_dashboard/static/src/dashboard/components/services/statistics_service.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
zadh-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.