-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[ADD] estate: add estate model for tutorials #1123
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
dianv-odoo
wants to merge
19
commits into
odoo:19.0
Choose a base branch
from
odoo-dev:19.0-tutorial-ch2-dianv
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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a138c78
[ADD] estate: create the estate module for Ch2 of the tutorial
dianv-odoo 96111b9
[IMP] estate: add estate_property model
dianv-odoo 64c4787
[IMP] estate: add access rights
dianv-odoo 7d946f0
[IMP] estate: add UI interaction by creating the form and adding menus
dianv-odoo 662b639
[IMP] estate: add basic views to real estate module (Ch 6)
dianv-odoo 46850b4
[IMP] estate: add property types, tags, and offers
dianv-odoo 95d3d2a
[IMP] estate: add computed fields and onchanges
dianv-odoo a21ad84
[IMP] estate: add buttons to accept and reject offers
dianv-odoo 2b6b91e
[IMP] estate: add constraints
dianv-odoo 2eef592
[IMP] add widgets, colors, and stat buttons
dianv-odoo a7a6b84
[FIX] applied suggested style fixes
dianv-odoo 17569cc
[IMP] add business logic to property state and inheritance to users
dianv-odoo 8710e71
[FIX] estate: fix style issues from last commit
dianv-odoo b5e704c
[ADD] estate_account: add link module estate_account
dianv-odoo 5a7fec3
[IMP] estate: added kanban view option
dianv-odoo 5cead40
[FIX] fix order of files in the manifest to load in correct order
dianv-odoo 32eb7a1
[FIX] estate: change the offer price requirement to be higher than al…
dianv-odoo 726bd9e
[ADD] awesome_owl: add counter, card, and todo list components
dianv-odoo de1ad8b
[ADD] awesome_dashboard: create dashboard for chapter 2
dianv-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.
30 changes: 30 additions & 0 deletions
30
awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.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 { Component, useState } from "@odoo/owl"; | ||
| import { Dialog } from "@web/core/dialog/dialog"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| export class ConfigDialog extends Component { | ||
| static template = "awesome_dashboard.ConfigDialog"; | ||
| static components = { Dialog }; | ||
|
|
||
| setup() { | ||
| this.items = registry.category("awesome_dashboard").get("DashboardItems"); | ||
| this.state = useState({ | ||
| hiddenIds: this.props.hiddenIds, | ||
| }); | ||
| } | ||
|
|
||
| toggleItem(id) { | ||
| console.log(this.state.hiddenIds); | ||
| const idIndex = this.state.hiddenIds.indexOf(id); | ||
| if (idIndex >= 0) { | ||
| this.state.hiddenIds.splice(idIndex, 1); | ||
| } else { | ||
| this.state.hiddenIds.push(id); | ||
| } | ||
| } | ||
|
|
||
| onApply() { | ||
| this.props.onApply(this.state.hiddenIds); | ||
| this.props.close(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
awesome_dashboard/static/src/dashboard/config_dialog/config_dialog.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,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.ConfigDialog"> | ||
| <Dialog title="'Dashboard Items Configuration'"> | ||
| <div>Which cards fo you wish to see?</div> | ||
| <div class="list-group"> | ||
| <t t-foreach="items" t-as="item" t-key="item.id"> | ||
| <label class="list-group-item d-flex align-items-center"> | ||
| <input type="checkbox" | ||
| class="form-check-input me-3" | ||
| t-att-checked="!state.hiddenIds.includes(item.id)" | ||
| t-on-change="() => this.toggleItem(item.id)"/> | ||
| <t t-esc="item.description"/> | ||
| </label> | ||
| </t> | ||
| </div> | ||
| <t t-set-slot="footer"> | ||
| <button class="btn btn-primary" t-on-click="onApply">Apply</button> | ||
| <button class="btn btn-secondary" t-on-click="props.close">Cancel</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,59 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { browser } from "@web/core/browser/browser"; | ||
| import { Layout } from "@web/search/layout"; | ||
| import { useService } from "@web/core/utils/hooks"; | ||
| import { _t } from "@web/core/l10n/translation"; | ||
| import { DashboardItem } from "./dashboard_item/dashboard_item"; | ||
| import { ConfigDialog } from "./config_dialog/config_dialog"; | ||
|
|
||
| class AwesomeDashboard extends Component { | ||
| static template = "awesome_dashboard.AwesomeDashboard"; | ||
|
|
||
| static components = { Layout, DashboardItem }; | ||
|
|
||
| setup() { | ||
| this.actionService = useService("action"); | ||
| this.statisticsService = useService("awesome_dashboard.statistics"); | ||
| this.statistics = useState(this.statisticsService.statistics); | ||
| this.items = registry.category("awesome_dashboard").get("DashboardItems"); | ||
| this.dialog = useService("dialog"); | ||
| this.state = useState({ | ||
| hiddenIds: browser.localStorage.getItem("dashboard_hidden_ids")?.split(",") || [], | ||
| }); | ||
| } | ||
|
|
||
| get displayedItems() { | ||
| return this.items.filter((item) => !this.state.hiddenIds.includes(item.id)); | ||
| } | ||
|
|
||
| openConfiguration() { | ||
| this.dialog.add(ConfigDialog, { | ||
| items: this.items, | ||
| hiddenIds: this.state.hiddenIds, | ||
| onApply: (newHiddenIds) => { | ||
| this.state.hiddenIds = newHiddenIds; | ||
| browser.localStorage.setItem("dashboard_hidden_ids", newHiddenIds); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| openCustomers() { | ||
| this.actionService.doAction("base.action_partner_form"); | ||
| } | ||
|
|
||
| openLeads() { | ||
| this.actionService.doAction({ | ||
| type: "ir.actions.act_window", | ||
| name: _t("Leads"), | ||
| target: "current", | ||
| res_model: "crm.lead", | ||
| views: [ | ||
| [false, "list"], | ||
| [false, "form"], | ||
| ], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| 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: pink; | ||
| } |
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,24 @@ | ||
| <?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="control-panel-create-button"> | ||
| <button class="btn btn-primary" t-on-click="openCustomers">Customer</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="row g-3"> | ||
| <t t-foreach="displayedItems" t-as="item" t-key="item.id"> | ||
| <DashboardItem 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> | ||
| </templates> |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
| import { Component } from "@odoo/owl"; | ||
|
|
||
| export class DashboardItem extends Component { | ||
| static template = "awesome_dashboard.DashboardItem"; | ||
|
|
||
| static props = { | ||
| size: { | ||
| type: Number, | ||
| }, | ||
| slots: { | ||
| type: Object, | ||
| optional: true, | ||
| }, | ||
| }; | ||
|
|
||
| static defaultProps = { | ||
| size: 1, | ||
| }; | ||
| } |
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.DashboardItem"> | ||
| <div class="card shadow-sm m-3 border" 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,63 @@ | ||
| 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 quantity", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Average amount of t-shirts by order this month", | ||
| value: data.average_quantity, | ||
| }), | ||
| }, | ||
| { | ||
| id: "average_time", | ||
| description: "Average time", | ||
| Component: NumberCard, | ||
| 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 orders", | ||
| Component: NumberCard, | ||
| props: (data) => ({ | ||
| title: "Total amount of new orders this month", | ||
| value: data.total_amount, | ||
| }), | ||
| }, | ||
| { | ||
| id: "tshirt_sizes", | ||
| description: "T-Shirt orders chart", | ||
| Component: PieChartCard, | ||
| size: 1, | ||
| props: (data) => ({ | ||
| title: "T-Shirt Sizes By Amount Sold", | ||
| data: data.orders_by_size, | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| registry.category("awesome_dashboard").add("DashboardItems", items); |
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="position-relative h-100"> | ||
| <h4><t t-esc="props.title"/></h4> | ||
| <div class="h3 text-success"><t t-esc="props.value"/></div> | ||
| </div> | ||
| </t> | ||
| </templates> |
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
| import { Component, onWillStart, useRef, onMounted } from "@odoo/owl"; | ||
| import { loadJS } from "@web/core/assets"; | ||
|
|
||
| export class PieChartCard extends Component { | ||
| static template = "awesome_dashboard.PieChartCard"; | ||
| static props = { | ||
| data: { type: Object }, | ||
| title: { type: String }, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.canvasRef = useRef("canvas"); | ||
|
|
||
| onWillStart(async () => { | ||
| await loadJS("/web/static/lib/Chart/Chart.js"); | ||
| }); | ||
|
|
||
| onMounted(() => { | ||
| this.drawChart(); | ||
| }); | ||
| } | ||
|
|
||
| drawChart() { | ||
| new Chart(this.canvasRef.el, { | ||
| type: "pie", | ||
| data: { | ||
| labels: Object.keys(this.props.data), | ||
| datasets: [ | ||
| { | ||
| label: this.props.title, | ||
| data: Object.values(this.props.data), | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
awesome_dashboard/static/src/dashboard/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,9 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
| <t t-name="awesome_dashboard.PieChartCard"> | ||
| <div class="position-relative h-100"> | ||
| <t t-esc="props.title"/> | ||
| <canvas t-ref="canvas"/> | ||
| </div> | ||
| </t> | ||
| </templates> |
24 changes: 24 additions & 0 deletions
24
awesome_dashboard/static/src/dashboard/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,24 @@ | ||
| import { registry } from "@web/core/registry"; | ||
| import { rpc } from "@web/core/network/rpc"; | ||
| import { reactive } from "@odoo/owl"; | ||
|
|
||
| export const statisticsService = { | ||
| start(env) { | ||
| const stats = reactive({ data: {} }); | ||
|
|
||
| async function fetch() { | ||
| const result = await rpc("/awesome_dashboard/statistics"); | ||
| Object.assign(stats.data, result); | ||
| } | ||
|
|
||
| fetch(); | ||
|
|
||
| setInterval(fetch, 10000); | ||
|
|
||
| return { | ||
| statistics: stats.data, | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| 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,15 @@ | ||
| import { Component, xml } from "@odoo/owl"; | ||
| import { LazyComponent } from "@web/core/assets"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| export class DashboardLoader extends Component { | ||
| static components = { LazyComponent }; | ||
| static template = xml` | ||
| <LazyComponent | ||
| bundle="'awesome_dashboard.dashboard'" | ||
| Component="'AwesomeDashboard'" | ||
| /> | ||
| `; | ||
| } | ||
|
|
||
| registry.category("actions").add("awesome_dashboard.dashboard", DashboardLoader); |
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,25 @@ | ||
| import { Component, useState } from "@odoo/owl"; | ||
|
|
||
|
|
||
| export class Card extends Component { | ||
| static template = "awesome_owl.Card"; | ||
|
|
||
| static props = { | ||
| title: { | ||
| type: String, | ||
| validate: val => (val.length > 0), | ||
| }, | ||
| slots: { | ||
| type: Object, | ||
| optional: true, | ||
| }, | ||
| }; | ||
|
|
||
| setup() { | ||
| this.state = useState({ isOpen: true }); | ||
| }; | ||
|
|
||
| toggleOpen() { | ||
| this.state.isOpen = !this.state.isOpen; | ||
| }; | ||
| } | ||
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.
The 2 lines before the class definition seems to be a Python only convention, no need to change it as it's not important but now you know