-
Notifications
You must be signed in to change notification settings - Fork 2.2k
18.0 tutorial nire #816
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
Open
nire-odoo
wants to merge
18
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorial-nire
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.
Open
18.0 tutorial nire #816
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
66b1c3a
[ADD] initial commit
nire-odoo 28bb608
[ADD] Chapter 3 super modifié
nire-odoo b9f198c
[ADD] chapter 4 and 5
nire-odoo a5deba5
[ADD] Chapter 6
nire-odoo 674da49
[ADD] Chapter 7
nire-odoo da60e72
[ADD] Chapter 7.1
nire-odoo 2e90538
[ADD] Chapter 8
nire-odoo 84a4fed
[ADD] Chapter 9
nire-odoo 32412bb
[ADD] Chapter 10
nire-odoo bc41f88
[ADD] Chapter 11: Add The Sprinkles
nire-odoo dd90eec
[ADD] Chapter 12 : Inheritance
nire-odoo 1286000
[ADD] Chapter 13 : Interact with other modules
nire-odoo 3901768
[ADD] Chapter 14 : Kanban !
nire-odoo 478bd11
[ADD] Chapter 1 : OWL Components
nire-odoo 347605d
[ADD] Chapter 2 (2.1->2.8) : Build a dashboard
nire-odoo 0a3f6d0
[ADD] Chapter 2 (2.8 -> 2.11)
nire-odoo e0c81e2
[FIX] Fixing ruff
nire-odoo d2bc9b0
[ADD] Unit test
nire-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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, onWillStart, useState } from "@odoo/owl"; | ||
import { registry } from "@web/core/registry"; | ||
import { Layout } from "@web/search/layout"; | ||
import { Dialog } from "@web/core/dialog/dialog"; | ||
import { AwesomeDashboardItem } from "./dashboard_item/dashboard_item" | ||
import { useService } from "@web/core/utils/hooks"; | ||
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, AwesomeDashboardItem} | ||
|
||
setup() { | ||
this.action = useService("action"); | ||
this.statistic = useState(useService("awesome_dashboard.statistics")) | ||
this.items = registry.category("awesome_dashboard").getAll(); | ||
this.dialog = useService("dialog"); | ||
this.display = { | ||
controlPanel: {}, | ||
}; | ||
this.state = useState({ | ||
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] | ||
}); | ||
} | ||
|
||
openCustomerView() { | ||
this.action.doAction("base.action_partner_form"); | ||
} | ||
|
||
openConfiguration() { | ||
this.dialog.add(ConfigurationDialog, { | ||
items: this.items, | ||
disabledItems: this.state.disabledItems, | ||
onUpdateConfiguration: this.updateConfiguration.bind(this), | ||
}) | ||
} | ||
|
||
updateConfiguration(newDisabledItems) { | ||
this.state.disabledItems = newDisabledItems; | ||
} | ||
|
||
openLeads() { | ||
this.action.doAction({ | ||
type: "ir.actions.act_window", | ||
name: "All leads", | ||
res_model: "crm.lead", | ||
views: [ | ||
[false, "list"], | ||
[false, "form"], | ||
], | ||
}); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
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); |
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,3 @@ | ||
.o_dashboard { | ||
background-color: grey; | ||
} |
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,42 @@ | ||
<?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 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 class="d-flex flex-wrap" t-if="statistic.isReady"> | ||
<t t-foreach="items" t-as="item" t-key="item.id"> | ||
<AwesomeDashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1"> | ||
<t t-set="itemProp" t-value="item.props ? item.props(statistic) : {'data': statistic}"/> | ||
<t t-component="item.Component" t-props="itemProp" /> | ||
</AwesomeDashboardItem> | ||
</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> |
22 changes: 22 additions & 0 deletions
22
awesome_dashboard/static/src/dashboard/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,22 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
|
||
export class AwesomeDashboardItem extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboardItem"; | ||
|
||
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/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.AwesomeDashboardItem"> | ||
<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> |
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,67 @@ | ||
/** @odoo-module **/ | ||
|
||
import { NumberCard } from "./number_card/number_card" | ||
import { PieChartCard } from "./pie_chart_card/pie_chart_card" | ||
import { registry } from "@web/core/registry"; | ||
|
||
export 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) | ||
}) |
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/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,11 @@ | ||
import { Component} from "@odoo/owl"; | ||
|
||
export class NumberCard extends Component { | ||
static template = "awesome_dashboard.NumberCard"; | ||
|
||
static props = { | ||
title: String, | ||
value: Number, | ||
}; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
awesome_dashboard/static/src/dashboard/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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
<t t-name="awesome_dashboard.NumberCard" owl="1"> | ||
<div class="card-body"> | ||
<t t-out="props.title"/> | ||
<div class="d-flex justify-content-center mt-3"> | ||
<h1><span class="badge text-bg-secondary text-success"><t t-out="props.value"/></span></h1> | ||
</div> | ||
</div> | ||
</t> | ||
</templates> |
45 changes: 45 additions & 0 deletions
45
awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.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,45 @@ | ||
import { loadJS } from "@web/core/assets"; | ||
import { getColor } from "@web/core/colors/colors"; | ||
import { Component, onWillStart, useRef, onMounted, onWillUnmount, onWillUpdateProps } 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(); | ||
}); | ||
onWillUpdateProps(() => { | ||
this.chart.destroy() | ||
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
10
awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.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.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> |
13 changes: 13 additions & 0 deletions
13
awesome_dashboard/static/src/dashboard/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,13 @@ | ||
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: String, | ||
values: Object, | ||
}; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_cards.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.PieChartCard" owl="1"> | ||
<t t-esc="props.title"/> | ||
<PieChart data="props.values" label="props.title"/> | ||
</t> | ||
</templates> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point,
this.props
still contains the old props. (Therefore the name "on WILL update")onWillUpdateProps((props) => {...})
receives the new props as parameter.You most likely want the render to use the most recent ones, instead of the old ones.