-
Notifications
You must be signed in to change notification settings - Fork 3k
Tutorials #1202
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
andha-odoo
wants to merge
24
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorials-estate-andha
base: 19.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
Tutorials #1202
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
39c9e64
[ADD] Tutorial - Ch 1, 2, 3 - Add module, models, and basic fields
andha-odoo 9448e18
[IMP] Tutorial - Chapter 4 - Security
andha-odoo c8a3e91
[IMP] Tutorial - Chapter 5 - Actions and Menus
andha-odoo 077ffd7
[IMP] Tutorial - Chapter 5 - Fields, Attributes, View, Default Values
andha-odoo b266f26
[IMP] Tutorial - Chapter 6 - List, Form, and Search Views
andha-odoo 1d80309
[FIX] Datetime calculation as lambda and renaming values
andha-odoo e9e2d4c
[IMP] Tutorial - Chapter 7 - Relations Between Models
andha-odoo cde4aaf
[FIX] styling fixes
andha-odoo 5bc4790
[IMP] Tutorial - Chapter 8 - Computed Fields and Onchanges
andha-odoo f7a41c9
[IMP] Tutorial - Chapter 9 - Ready For Some Action?
andha-odoo a4e18a2
[IMP] Tutorial - Chapter 10 - Constraints
andha-odoo 6d77cf4
[IMP] Tutorial - Chapter 11 - Sprinkles
andha-odoo 0b90b2f
[FIX] Rename access record entries
andha-odoo f7402bc
[FIX] Rename access record entries (again)
andha-odoo d2011ff
[FIX] Rename access record entries (again x2)
andha-odoo 286105a
[FIX] Rename access record entries (again x3)
andha-odoo 80e0a16
[LINT] Cleaning up various .py and .xml files
andha-odoo c267b65
[IMP] Tutorial - Chapter 12 - Inheritance
andha-odoo aa77f29
[IMP] Tutorial - Chapter 13 - Invoicing
andha-odoo 9ce82fb
[IMP] Tutorial - Chapter 14 - Kanban View
andha-odoo dcdfb4c
[LINT] Remove unused variable declaration
andha-odoo 55b2bc5
[ADD] Web Framework Tutorial - Chapter 1
andha-odoo 0edbed8
[ADD] Web Framework Tutorial - Chapter 2 - Ch 1...8
andha-odoo b1bc98e
[IMP] Web Framework Tutorial - Chapter 2 - Ch 9, 10, 11
andha-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # Linting | ||
| pyproject.toml | ||
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,112 @@ | ||
| 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 { AwesomeDashboardItem } from "./dashboard_item"; | ||
| import { rpc } from "@web/core/network/rpc"; | ||
| 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 components = { AwesomeDashboardItem, PieChart, Layout }; | ||
| static template = "awesome_dashboard.AwesomeDashboard"; | ||
|
|
||
| setup() { | ||
| this.action = useService("action"); | ||
| this.stats = useState(useService("awesome_dashboard.statistics")); | ||
| this.items = registry.category("awesome_dashboard").getAll(); | ||
| this.dialog = useService("dialog"); | ||
|
|
||
| const hiddenItems = JSON.parse( | ||
| browser.localStorage | ||
| .getItem("disabled_dashboard_items") | ||
| ?.split(",") || '[]', | ||
| ); | ||
| this.state = useState({ disabledItems: hiddenItems }); | ||
|
|
||
| onWillStart(async () => { | ||
| const res = await rpc("/awesome_dashboard/statistics"); | ||
| console.log(res); | ||
| Object.assign(this.stats, res); | ||
| }); | ||
| } | ||
|
|
||
| openCustomers() { | ||
| this.action.doAction("base.action_partner_form"); | ||
| } | ||
|
|
||
| openLeads() { | ||
| this.action.doAction({ | ||
| type: "ir.actions.act_window", | ||
| name: "Leads", | ||
| res_model: "crm.lead", | ||
| views: [ | ||
| [false, "form"], | ||
| [false, "list"], | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| openConfig() { | ||
| this.dialog.add(ConfigDialog, { | ||
| items: this.items, | ||
| disabled: this.state.disabledItems, | ||
| onUpdate: (newDisabledItems) => { | ||
| this.state.disabledItems = newDisabledItems; | ||
| browser.localStorage.setItem( | ||
| "disabled_dashboard_items", | ||
| JSON.stringify(newDisabledItems), | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| class ConfigDialog extends Component { | ||
| static template = "awesome_dashboard.config"; | ||
| static components = { CheckBox, Dialog }; | ||
|
|
||
| static props = { | ||
| items: Array, | ||
| close: Function, | ||
| disabled: Array, | ||
| onUpdate: Function, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.items = useState( | ||
| this.props.items.map((item) => ({ | ||
| ...item, | ||
| isEnabled: !this.props.disabled.includes(item.id), | ||
| })), | ||
| ); | ||
| } | ||
|
|
||
| apply() { | ||
| const disabledIds = this.items | ||
| .filter((i) => !i.isEnabled) | ||
| .map((i) => i.id); | ||
|
|
||
| this.props.onUpdate(disabledIds); | ||
| this.props.close(); | ||
| } | ||
|
|
||
| onCheck(item, value) { | ||
| console.log(item, value) | ||
| item.isEnabled = value; | ||
| const updatedDisabledItemsList = Object.values(this.items) | ||
| .filter((item) => !item.isEnabled) | ||
| .map((item) => item.id); | ||
|
|
||
| browser.localStorage.setItem( | ||
| "disabled_dashboard_items", | ||
| updatedDisabledItemsList, | ||
| ); | ||
|
|
||
| this.props.onUpdate(updatedDisabledItemsList); | ||
| } | ||
| } | ||
|
|
||
| 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: gray; | ||
| } |
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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.AwesomeDashboard"> | ||
| <Layout display="{ controlPanel: {} }" className="'o_dashboard h-100'"> | ||
| <t t-set-slot="layout-buttons"> | ||
| <button class="btn btn-primary" t-on-click="openCustomers"> | ||
| Customers | ||
| </button> | ||
| <button class="btn btn-primary" t-on-click="openLeads"> | ||
| Leads | ||
| </button> | ||
| </t> | ||
| <t t-set-slot="control-panel-additional-actions"> | ||
| <button class="btn btn-primary" t-on-click="openConfig"> | ||
| Configuration <i class="fa fa-cog" /> | ||
| </button> | ||
| </t> | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <AwesomeDashboardItem size="item.size || 1"> | ||
| <t | ||
| t-set="itemProp" | ||
| t-value="item.props ? item.props(this.stats) : undefined" | ||
| /> | ||
| <t t-component="item.Component" t-props="itemProp" /> | ||
| </AwesomeDashboardItem> | ||
| </t> | ||
| </Layout> | ||
| </t> | ||
|
|
||
| <t t-name="awesome_dashboard.config"> | ||
| <Dialog title="'Dashboard items configuration'"> | ||
| <p>Which cards do you want to see?</p> | ||
| <t t-foreach="this.items" t-as="item" t-key="item.id"> | ||
| <CheckBox value="item.isEnabled" onChange="(val) => this.onCheck(item, val)"> | ||
| <t t-esc="item.description" /> | ||
| </CheckBox> | ||
| </t> | ||
| <t t-set-slot="footer"> | ||
| <button class="btn btn-primary" t-on-click="apply">Apply</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,21 @@ | ||
| import { Component } from "@odoo/owl"; | ||
| import { Layout } from "@web/search/layout"; | ||
|
|
||
| export class AwesomeDashboardItem extends Component { | ||
| static components = { Layout }; | ||
| static template = "awesome_dashboard.AwesomeDashboardItem"; | ||
|
|
||
| static defaultProps = { | ||
| size: 1, | ||
| }; | ||
|
|
||
| static props = { | ||
| size: { type: Number, optional: true }, | ||
| slots: { | ||
| type: Object, | ||
| shape: { | ||
| default: true, | ||
| }, | ||
| }, | ||
| }; | ||
| } |
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 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.AwesomeDashboardItem"> | ||
| <div | ||
| class="card border-dark" | ||
| t-attf-style="width: {{ 18 * props.size }}rem;" | ||
| > | ||
| <p class="card-text"> | ||
| <t t-slot="default" /> | ||
| </p> | ||
| </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,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 order processing time", | ||
| Component: NumberCard, | ||
| size: 2, | ||
| props: (data) => ({ | ||
| title: "Average time for an order to go from 'new' to 'sent' or 'cancelled' ", | ||
| value: data.average_time, | ||
| }), | ||
| }, | ||
| { | ||
| id: "nb_new_orders", | ||
| description: "Number of new orders", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Number of new orders this month", | ||
| value: data.nb_new_orders, | ||
| }), | ||
| }, | ||
| { | ||
| id: "nb_cancelled_orders", | ||
| description: "Number of cancelled orders", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Number of cancelled orders this month", | ||
| value: data.nb_cancelled_orders, | ||
| }), | ||
| }, | ||
| { | ||
| id: "total_amount", | ||
| description: "Total new orders", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Total amount of new orders this month", | ||
| value: data.total_amount, | ||
| }), | ||
| }, | ||
| { | ||
| id: "orders_by_size", | ||
| description: "Shirt orders by size", | ||
| Component: PieChartCard, | ||
| props: (data) => ({ | ||
| title: "Shirt orders by size", | ||
| data: data.orders_by_size, | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| items.forEach((item) => { | ||
| registry.category("awesome_dashboard").add(item.id, item); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class NumberCard extends Component { | ||
| static template = "awesome_dashboard.NumberCard"; | ||
| static props = { | ||
| title: String, | ||
| value: Number, | ||
| }; | ||
| } |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.NumberCard"> | ||
| <div class="o_number-card"> | ||
| <p class="text-primary" t-esc="props.title"></p> | ||
| <p class="text-center text-success" t-esc="props.value"></p> | ||
| </div> | ||
| </t> | ||
| </templates> |
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
| import { Component, useEffect, useRef, onWillStart } from "@odoo/owl"; | ||
| import { Layout } from "@web/search/layout"; | ||
| import { loadJS } from "@web/core/assets"; | ||
|
|
||
| const D3_COLORS = [ | ||
| "#1f77b4", | ||
| "#ff7f0e", | ||
| "#aec7e8", | ||
| "#ffbb78", | ||
| "#2ca02c", | ||
| "#98df8a", | ||
| "#d62728", | ||
| "#ff9896", | ||
| "#9467bd", | ||
| "#c5b0d5", | ||
| "#8c564b", | ||
| "#c49c94", | ||
| "#e377c2", | ||
| "#f7b6d2", | ||
| "#7f7f7f", | ||
| "#c7c7c7", | ||
| "#bcbd22", | ||
| "#dbdb8d", | ||
| "#17becf", | ||
| "#9edae5", | ||
| ]; | ||
|
|
||
| export class PieChart extends Component { | ||
| static components = { Layout }; | ||
| static template = "awesome_dashboard.PieChart"; | ||
|
|
||
| static defaultProps = { | ||
| s: 0, | ||
| m: 0, | ||
| l: 0, | ||
| xl: 0, | ||
| xxl: 0, | ||
| }; | ||
|
|
||
| setup() { | ||
| onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); | ||
| this.canvasRef = useRef("canvas"); | ||
| useEffect(() => this.renderChart()); | ||
| } | ||
|
|
||
| destroyChart() { | ||
| if (this.chart) { | ||
| this.chart.destroy(); | ||
| } | ||
| } | ||
|
|
||
| renderChart() { | ||
| this.destroyChart(); | ||
| const ctx = this.canvasRef.el.getContext("2d"); | ||
| this.chart = new Chart(ctx, this.getChartConfig()); | ||
| } | ||
|
|
||
| getChartConfig() { | ||
| const data = this.props.data || {}; | ||
| const labels = Object.keys(data); | ||
| const counts = Object.values(data); | ||
|
|
||
| return { | ||
| type: "pie", | ||
| data: { | ||
| labels: labels, | ||
| datasets: [ | ||
| { | ||
| data: counts, | ||
| backgroundColor: labels.map((_, index) => D3_COLORS[index % 20]), | ||
| hoverOffset: 4 | ||
| }, | ||
| ], | ||
| }, | ||
| options: { | ||
| responsive: true, | ||
| maintainAspectRatio: false, | ||
| plugins: { | ||
| legend: { | ||
| position: 'bottom', | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
| } |
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.
You should not push this