diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..c50b9e0c067 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -1,30 +1,28 @@ # -*- coding: utf-8 -*- { - 'name': "Awesome Dashboard", - - 'summary': """ + "name": "Awesome Dashboard", + "summary": """ Starting module for "Discover the JS framework, chapter 2: Build a dashboard" """, - - 'description': """ + "description": """ Starting module for "Discover the JS framework, chapter 2: Build a dashboard" """, - - 'author': "Odoo", - 'website': "https://www.odoo.com/", - 'category': 'Tutorials/AwesomeDashboard', - 'version': '0.1', - 'application': True, - 'installable': True, - 'depends': ['base', 'web', 'mail', 'crm'], - - 'data': [ - 'views/views.xml', + "author": "Odoo", + "website": "https://www.odoo.com/", + "category": "Tutorials/AwesomeDashboard", + "version": "0.1", + "application": True, + "installable": True, + "depends": ["base", "web", "mail", "crm"], + "data": [ + "views/views.xml", ], - 'assets': { - 'web.assets_backend': [ - 'awesome_dashboard/static/src/**/*', + "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' + "license": "AGPL-3", } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..0d64f66e246 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,88 @@ +/** @odoo-module **/ + +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 "./dashboard_item/dashboard_item"; +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 }; + + setup() { + this.action = useService("action"); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); + this.display = { + controlPanel: {}, + }; + // this.items = DashboardItems; + 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; + } + openCustomers() { + 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, "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); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..ad914a9b7e4 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: #2c0f36; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..a04ad0a2a28 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + +
+ + + + + + +
+
+
+ + + Which cards do you whish to see ? + + + + + + + + + + +
diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..b270ec577a2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +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, + }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..6b3d2923fb2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..55c64f814d8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,66 @@ +/** @odoo-module */ + +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; + +const DashboardItems = [ + { + 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, + }) + } +] +DashboardItems.forEach(item => { + registry.category("awesome_dashboard").add(item.id, item); +}); diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/number_card/number_card.js new file mode 100644 index 00000000000..98513d0f4e0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,15 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + } + } +} diff --git a/awesome_dashboard/static/src/dashboard/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml new file mode 100644 index 00000000000..09ac7342875 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js new file mode 100644 index 00000000000..62c13e93bdf --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,50 @@ +/** @odoo-module **/ + +import { loadJS } from "@web/core/assets"; +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 colorPalette = [ + "#FF6384", + "#36A2EB", + "#4BC0C0", + "#9966FF", + "#FF9F40", + ]; + const color = labels.map((_, index) => colorPalette[index % colorPalette.length]); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + backgroundColor: color, + }, + ], + }, + }); + } +} +// registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml new file mode 100644 index 00000000000..7003e2aa5f9 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..a28c2f48c6f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -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, + }, + } +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..459a9be8d48 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..8cebe4d9328 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,14 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; + +} +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); diff --git a/awesome_dashboard/static/src/statistics.js b/awesome_dashboard/static/src/statistics.js new file mode 100644 index 00000000000..c76886c6050 --- /dev/null +++ b/awesome_dashboard/static/src/statistics.js @@ -0,0 +1,22 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; + +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); diff --git a/awesome_owl/__manifest__.py b/awesome_owl/__manifest__.py index 77abad510ef..d4bf6aa30e2 100644 --- a/awesome_owl/__manifest__.py +++ b/awesome_owl/__manifest__.py @@ -36,6 +36,10 @@ ('include', 'web._assets_core'), 'web/static/src/libs/fontawesome/css/font-awesome.css', 'awesome_owl/static/src/**/*', + # "awesome_owl/static/src/components/playground.js", + # "awesome_owl/static/src/components/playground.xml", + # "awesome_owl/static/src/counter/counter.js", + # "awesome_owl/static/src/counter/counter.xml", ], }, 'license': 'AGPL-3' diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..fc3a629a992 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,22 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + + static props = { + title: { type: String, optional: true }, + content: { type: String, optional: true }, + heading: { type: String, optional: true }, + describtion: { type: String, optional: true }, + slots: {type: Object, optional: true, shape: { default: true }}, + }; + setup() { + this.state = useState({ isOpen: true }); + } + + toggleContent() { + this.state.isOpen = !this.state.isOpen; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..0f0632c167f --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,19 @@ + + + +
+
+
+ + +
+

+

+

+
+

+

+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..be6509af0e8 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,19 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.counter"; + static props = { + onChange: { type: Function, optional: true } + }; + setup() { + this.state = useState({ value: 1 }); + } + increment() { + this.state.value = this.state.value + 1; + if (this.props.onChange) { + this.props.onChange(); + } + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..696b1cb4595 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,23 @@ + + + +
+

Counter:

+ +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..9ab177a239f 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,24 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + static props = { + onChange: { type: Function, optional: true } + }; + static components = { Counter, Card, TodoList }; + + setup() { + this.str1 = "
some content
"; + this.str2 = markup("
some content
"); + this.sum = useState({ value: 2 }); + } + + incrementSum() { + this.sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..33889a14a96 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,83 @@ - + - - -
- hello world -
+ +

Counters

+
+ hello world + + +
+

Cards

+
+ + +
+

Cards with Markup

+
+ + +
+

Sum of counters

+
+
The sum is:
+ + +
+

Todo List

+
+ +
+

Generic card with slots and toggle

+
+ +
-
diff --git a/awesome_owl/static/src/todo_list/todo_item.js b/awesome_owl/static/src/todo_list/todo_item.js new file mode 100644 index 00000000000..073b6f2b06b --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + static props = { + todo: { + type: Object, + shape: { id: Number, description: String, isCompleted: Boolean } + }, + toggleState: Function, + removeTodo: Function, + }; + onChange() { + this.props.toggleState(this.props.todo.id); + } + onRemove() { + this.props.removeTodo(this.props.todo.id); + } +} diff --git a/awesome_owl/static/src/todo_list/todo_item.xml b/awesome_owl/static/src/todo_list/todo_item.xml new file mode 100644 index 00000000000..600bbd45cef --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,20 @@ + + + +
+ + + +
+
+
diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js new file mode 100644 index 00000000000..bfe4bb6d157 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,38 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item"; +import { useAutofocus } from "../utils"; + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.nextId = 0; + this.newtodo = useState([]); + useAutofocus("input") + } + addTodo(ev) { + if (ev.keyCode === 13 && ev.target.value != "") { + this.newtodo.push({ + id: this.nextId++, + description: ev.target.value, + isCompleted: false + }); + ev.target.value = ""; + } + } + toggleTodo(todoId) { + const todo = this.newtodo.find((todo) => todo.id === todoId); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + removeTodo(todoId) { + const todoIndex = this.newtodo.findIndex((todo) => todo.id === todoId); + if (todoIndex >= 0) { + this.newtodo.splice(todoIndex, 1); + } + } +} diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml new file mode 100644 index 00000000000..337d219408d --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,11 @@ + + + +
+ + + + +
+
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..d2b59535288 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,10 @@ +/** @odoo-module **/ + +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(refName) { + const ref = useRef(refName); + onMounted(() => { + ref.el.focus(); + }); +} diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..d6210b1285d --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..f18f9ad425c --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,17 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + "name": "Estate Account", + "version": "1.0", + "depends": ["real_estate", "account"], + "category": "Accounts for Estate", + "description": """ + This is the link module that helps generating invoices when marking the property as sold. + """, + "license": "LGPL-3", + "installable": True, + "application": True, + "data": [ + "reports/estate_property_reports.xml", + ] +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..cd90e327ddb --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import estate_property_account diff --git a/estate_account/models/estate_property_account.py b/estate_account/models/estate_property_account.py new file mode 100644 index 00000000000..7b7d4a09995 --- /dev/null +++ b/estate_account/models/estate_property_account.py @@ -0,0 +1,54 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import Command, models +from odoo.exceptions import AccessError, UserError + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + self.ensure_one() + try: + self.check_access("write") + except AccessError: + raise UserError(f"You do not have write access to sell the property '{self.name}'.") + + invoice_lines = [ + Command.create({ + "name": f"self: {self.name}", + "quantity": 1, + "price_unit": self.selling_price, + } + ), + Command.create( + { + "name": "6% Commission", + "quantity": 1, + "price_unit": self.selling_price * 0.06, + } + ), + Command.create( + { + "name": "Administrative Fees", + "quantity": 1, + "price_unit": 100.00, + } + ), + Command.create( + { + "name": "Discount", + "quantity": 1, + "price_unit": -self.selling_price * 0.05, + } + ), + ] + invoice_vals = { + "partner_id": self.buyer_id.id, + "move_type": "out_invoice", + "invoice_line_ids": invoice_lines, + "invoice_origin": f"self: {self.name}", + "narration": f"Invoice related to self '{self.name}'", + } + self.env["account.move"].sudo().create(invoice_vals) + return super().action_sold() diff --git a/estate_account/reports/estate_property_reports.xml b/estate_account/reports/estate_property_reports.xml new file mode 100644 index 00000000000..618d22b781d --- /dev/null +++ b/estate_account/reports/estate_property_reports.xml @@ -0,0 +1,13 @@ + + + + diff --git a/real_estate/__init__.py b/real_estate/__init__.py new file mode 100644 index 00000000000..d6210b1285d --- /dev/null +++ b/real_estate/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/real_estate/__manifest__.py b/real_estate/__manifest__.py new file mode 100644 index 00000000000..3fd149edf80 --- /dev/null +++ b/real_estate/__manifest__.py @@ -0,0 +1,27 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + "name": "Dream Homes", + "version": "1.0", + "depends": ["base", "mail"], + "category": "Real Estate/Brokerage", + "data": [ + "security/estate_property_security.xml", + "security/ir.model.access.csv", + "views/estate_property_views.xml", + "views/estate_property_offer_views.xml", + "views/estate_property_type_views.xml", + "views/estate_property_tag_views.xml", + "views/estate_property_menus.xml", + "views/res_users_views.xml", + "data/estate.property.types.csv", + "report/estate_property_reports.xml", + "report/estate_property_templates.xml", + ], + "demo": [ + "demo/estate_property_demo.xml", + ], + "license": "LGPL-3", + "installable": True, + "application": True, +} diff --git a/real_estate/data/estate.property.types.csv b/real_estate/data/estate.property.types.csv new file mode 100644 index 00000000000..4752fac676e --- /dev/null +++ b/real_estate/data/estate.property.types.csv @@ -0,0 +1,5 @@ +id,name +property_type_1,Residential +property_type_2,Commercial +property_type_3,Industrial +property_type_4,Land diff --git a/real_estate/demo/estate_property_demo.xml b/real_estate/demo/estate_property_demo.xml new file mode 100644 index 00000000000..01123bd180a --- /dev/null +++ b/real_estate/demo/estate_property_demo.xml @@ -0,0 +1,122 @@ + + + + + Big Villa + new + A nice and big villa + 12345 + 2020-02-02 + 1600000 + 1500000 + 6 + 100 + 4 + True + True + 100000 + south + + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 1 + 10 + 4 + False + False + + + + + International Space Station + new + Aliens sometimes come visit + ---- + 2030-12-31 + 45890000 + + + + + + Cozy Cabin + sold + Small cabin by lake + 10000 + 2020-01-01 + 80000 + 1 + 10 + 4 + False + True + + + + + + + + 1550000 + 14 + + + + + + + 1560000 + 14 + + + + + + + 1570001 + 14 + + + + + + + + + + + + + + + + + House with Inline Offers + new + 500000 + + + + + diff --git a/real_estate/models/__init__.py b/real_estate/models/__init__.py new file mode 100644 index 00000000000..7d1b1c46ec3 --- /dev/null +++ b/real_estate/models/__init__.py @@ -0,0 +1,7 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import estate_property +from . import estate_property_offers +from . import estate_property_tags +from . import estate_property_types +from . import res_users diff --git a/real_estate/models/estate_property.py b/real_estate/models/estate_property.py new file mode 100644 index 00000000000..79792f71901 --- /dev/null +++ b/real_estate/models/estate_property.py @@ -0,0 +1,143 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from dateutil.relativedelta import relativedelta +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "This is a real estate module" + _order = "id desc" + _inherit = "mail.thread" + + name = fields.Char(string="Property Name", required=True, tracking=True) + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(string="Selling Price", readonly=True, copy=False) + bedrooms = fields.Integer(string="Total Bedrooms", default=2) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") + active = fields.Boolean(string="Is Active", default=True) + buyer_id = fields.Many2one(comodel_name="res.partner", string="Buyer", copy=False) + total_area = fields.Float(compute="_compute_total_area", string="Total Area") + best_offer = fields.Float(compute="_compute_best_price", string="Best Offer") + date_availability = fields.Date( + string="Availability From", + default=lambda self: fields.Date.today() + relativedelta(months=3), + copy=False, + ) + estate_property_offer_ids = fields.One2many( + comodel_name="estate.property.offers", + inverse_name="property_id", + string="Offers", + tracking=True, + ) + seller_id = fields.Many2one( + comodel_name="res.users", + string="SalesPerson", + default=lambda self: self.env.user, + ) + estate_property_type_id = fields.Many2one( + comodel_name="estate.property.types", + string="Property Type", + tracking=True, + ) + estate_property_tag_ids = fields.Many2many( + comodel_name="estate.property.tags", + string="Tags", + tracking=True, + ) + garden_orientation = fields.Selection( + selection=[ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West"), + ], + string="Garden Orientation", + ) + state = fields.Selection( + selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + copy=False, + required=True, + default="new", + string="State", + ) + company_id = fields.Many2one( + comodel_name="res.company", + string="Company", + required=True, + default=lambda self: self.env.company, + ) + _sql_constraints = [ + ( + "check_expected_price_positive", + "CHECK(expected_price > 0)", + "Expected price must be strictly positive.", + ), + ] + + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends("estate_property_offer_ids") + def _compute_best_price(self): + for record in self: + prices = record.estate_property_offer_ids.mapped("price") + record.best_offer = max(prices) if prices else 0.0 + + @api.onchange("garden") + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = "north" + else: + self.garden_area = 0 + self.garden_orientation = False + + def action_sold(self): + for record in self: + if not record.state == "offer_accepted": + raise UserError("Accept an offer first") + if record.state == "cancelled": + raise UserError("You cannot mark a cancelled property as sold.") + record.state = "sold" + + def action_cancel(self): + for record in self: + if record.state == "sold": + raise UserError("You cannot mark a sold property as cancelled.") + record.state = "cancelled" + + @api.constrains("expected_price", "selling_price") + def _check_selling_price(self): + for record in self: + if float_is_zero(record.selling_price, precision_digits=2): + continue + min_price = record.expected_price * 0.9 + if float_compare(record.selling_price, min_price, precision_digits=2) < 0: + raise ValidationError( + "Selling price must be at least 90% of the expected price." + ) + + @api.ondelete(at_uninstall=False) + def _check_deletion_state(self): + for rec in self: + if rec.state not in ["new", "cancelled"]: + raise UserError( + "Only properties in 'New' or 'Cancelled' state can be deleted." + ) diff --git a/real_estate/models/estate_property_offers.py b/real_estate/models/estate_property_offers.py new file mode 100644 index 00000000000..f8e246deb42 --- /dev/null +++ b/real_estate/models/estate_property_offers.py @@ -0,0 +1,80 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class EstatePropertyOffers(models.Model): + _name = "estate.property.offers" + _description = "Estate Property Offers" + _order = "price desc" + + price = fields.Float() + partner_id = fields.Many2one(comodel_name="res.partner", required=True) + property_id = fields.Many2one(comodel_name="estate.property", required=True) + validity = fields.Integer(default="7") + property_type_id = fields.Many2one( + related="property_id.estate_property_type_id", store=True + ) + offer_deadline = fields.Date( + compute="_compute_date_deadline", inverse="_inverse_date_deadline" + ) + status = fields.Selection( + selection=[("accepted", "Accepted"), ("refused", "Refused")] + ) + + _sql_constraints = [ + ( + "check_offer_price_positive", + "CHECK(price > 0)", + "Offer price must be strictly positive.", + ) + ] + + @api.depends("create_date", "validity") + def _compute_date_deadline(self): + for record in self: + if record.create_date and record.validity: + record.offer_deadline = fields.Date.add(record.create_date, days=record.validity) + else: + record.offer_deadline = fields.Date.add(fields.Date.today(), days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + if record.create_date and record.offer_deadline: + record.validity = ( + record.offer_deadline - fields.Date.to_date(record.create_date) + ).days + + def action_accept_offer(self): + for offer in self: + accepted_offer = offer.property_id.estate_property_offer_ids.filtered( + lambda o: o.status == "accepted" + ) + if accepted_offer: + raise UserError("Only one offer can be accepted per property.") + offer.status = "accepted" + offer.property_id.selling_price = offer.price + offer.property_id.buyer_id = offer.partner_id + offer.property_id.state = "offer_accepted" + + def action_refuse_offer(self): + for offer in self: + offer.status = "refused" + + @api.model_create_multi + def create(self, vals): + for val in vals: + property_id = self.env["estate.property"].browse(val["property_id"]) + + if property_id.state == "sold": + raise UserError("Cannot create an offer on a sold property.") + + if property_id.state == "new": + property_id.state = "offer_received" + + if val["price"] <= property_id.best_offer: + raise UserError( + f"The offer must be higher than {property_id.best_offer}" + ) + return super().create(vals) diff --git a/real_estate/models/estate_property_tags.py b/real_estate/models/estate_property_tags.py new file mode 100644 index 00000000000..56705345b6a --- /dev/null +++ b/real_estate/models/estate_property_tags.py @@ -0,0 +1,16 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class EstatePropertyTags(models.Model): + _name = "estate.property.tags" + _description = "Estate Property Tags" + _order = "name" + + name = fields.Char(required=True) + color = fields.Integer() + + _sql_constraints = [ + ("unique_tag_name", "UNIQUE(name)", "This property tag already exits, create a unique one.") + ] diff --git a/real_estate/models/estate_property_types.py b/real_estate/models/estate_property_types.py new file mode 100644 index 00000000000..a1cb85c483b --- /dev/null +++ b/real_estate/models/estate_property_types.py @@ -0,0 +1,28 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class EstatePropertyTypes(models.Model): + _name = "estate.property.types" + _description = "Estate Property Types" + _order = "sequence, name" + + name = fields.Char(required=True) + sequence = fields.Integer(default=1) + offer_ids = fields.One2many(comodel_name="estate.property.offers", inverse_name="property_type_id") + offer_count = fields.Integer(string="Number of Offers", compute="_compute_offer_count") + property_ids = fields.One2many("estate.property", "estate_property_type_id", string="Properties") + + _sql_constraints = [ + ( + "unique_type_name", + "UNIQUE(name)", + "This property type already exits, create a unique one.", + ) + ] + + @api.depends("offer_ids") + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/real_estate/models/res_users.py b/real_estate/models/res_users.py new file mode 100644 index 00000000000..cade946f04b --- /dev/null +++ b/real_estate/models/res_users.py @@ -0,0 +1,13 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + comodel_name="estate.property", + inverse_name="seller_id", + domain="[('state', 'in', ('new','offer_received'))]", + ) diff --git a/real_estate/report/estate_property_reports.xml b/real_estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..9a9d2a28fdc --- /dev/null +++ b/real_estate/report/estate_property_reports.xml @@ -0,0 +1,22 @@ + + + + Print Offers + estate.property + qweb-html + real_estate.report_property_offers + real_estate.report_property_offers + 'Property Offers - %s' % (object.name).replace('/','') + + + + + Print Properties + res.users + qweb-html + real_estate.report_salesman_properties + real_estate.report_salesman_properties + 'Properties - %s' % (object.name).replace('/','') + + + diff --git a/real_estate/report/estate_property_templates.xml b/real_estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..388552a3975 --- /dev/null +++ b/real_estate/report/estate_property_templates.xml @@ -0,0 +1,93 @@ + + + + + + + + diff --git a/real_estate/security/estate_property_security.xml b/real_estate/security/estate_property_security.xml new file mode 100644 index 00000000000..4b00abc28da --- /dev/null +++ b/real_estate/security/estate_property_security.xml @@ -0,0 +1,39 @@ + + + + + Agent + + + + + Manager + + + + + + + + Limit agents to only being able to see or modify properties which have no + salesperson, or + for which they are the salesperson. + + + + + + [ + '|', ('seller_id', '=', user.id), + ('seller_id', '=', False), '|', ('company_id', '=', user.company_id.id), + ('company_id', '=', False)] + + + + + Managers can see all properties + + + + + diff --git a/real_estate/security/ir.model.access.csv b/real_estate/security/ir.model.access.csv new file mode 100644 index 00000000000..7a362e1a818 --- /dev/null +++ b/real_estate/security/ir.model.access.csv @@ -0,0 +1,10 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +real_estate.access_estate_property_manager,access_estate_property,real_estate.model_estate_property,real_estate.estate_group_manager,1,1,1,0 +real_estate.access_estate_property_type_manager,access_estate_property_type,real_estate.model_estate_property_types,real_estate.estate_group_manager,1,1,1,1 +real_estate.access_estate_property_tag_manager,access_estate_property_tag,real_estate.model_estate_property_tags,real_estate.estate_group_manager,1,1,1,1 +real_estate.access_estate_property_offer_manager,access_estate_property_offer,real_estate.model_estate_property_offers,real_estate.estate_group_manager,1,1,1,1 + +real_estate.access_estate_property_user,access_estate_property,real_estate.model_estate_property,real_estate.estate_group_user,1,1,1,0 +real_estate.access_estate_property_type_user,access_estate_property_type,real_estate.model_estate_property_types,real_estate.estate_group_user,1,0,0,0 +real_estate.access_estate_property_tag_user,access_estate_property_tag,real_estate.model_estate_property_tags,real_estate.estate_group_user,1,0,0,0 +real_estate.access_estate_property_offer_user,access_estate_property_offer,real_estate.model_estate_property_offers,real_estate.estate_group_user,1,1,1,1 diff --git a/real_estate/static/description/icon.png b/real_estate/static/description/icon.png new file mode 100644 index 00000000000..8342f39e95a Binary files /dev/null and b/real_estate/static/description/icon.png differ diff --git a/real_estate/tests/__init__.py b/real_estate/tests/__init__.py new file mode 100644 index 00000000000..31411e95055 --- /dev/null +++ b/real_estate/tests/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_real_estate diff --git a/real_estate/tests/test_real_estate.py b/real_estate/tests/test_real_estate.py new file mode 100644 index 00000000000..0f0cc397404 --- /dev/null +++ b/real_estate/tests/test_real_estate.py @@ -0,0 +1,62 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.exceptions import UserError +from odoo.tests import Form, tagged +from odoo.tests.common import TransactionCase + + +@tagged('post_install', '-at_install') +class TestEstateProperty(TransactionCase): + + def setUp(self): + super().setUp() + self.Property = self.env['estate.property'] + self.Offer = self.env['estate.property.offers'] + + def test_offer_cannot_be_created_on_sold_property(self): + """Offers cannot be created for sold properties""" + partner = self.env['res.partner'].create({ + 'name': 'Test Partner', + 'email': 'partner@example.com', + }) + prop = self.Property.create({ + 'name': 'Sold Property', + 'state': 'sold', + 'expected_price': 90000 + }) + with self.assertRaises(UserError): + self.Offer.create({ + 'price': 100000, + 'property_id': prop.id, + 'partner_id': partner.id, + }) + + def test_cannot_mark_as_sold_without_accepted_offer(self): + """Should raise error when trying to sell a property with no offers at all""" + prop = self.Property.create({ + 'name': 'No Offers Property', + 'expected_price': 120000, + }) + with self.assertRaises(UserError): + prop.action_sold() + + def test_onchange_garden_unchecked_resets_fields(self): + """Garden area and orientation should reset when garden is unchecked""" + form = Form(self.env['estate.property']) + form.name = "Reset Garden Test" + form.expected_price = 90000 + form.garden = True + prop = form.save() + + self.assertEqual(prop.garden_area, 10) + self.assertEqual(prop.garden_orientation, "north") + + form = Form(prop) + form.garden = False + self.assertEqual(form.garden_area, 0) + self.assertFalse(form.garden_orientation) + + prop = form.save() + self.assertFalse(prop.garden) + self.assertEqual(prop.garden_area, 0) + self.assertFalse(prop.garden_orientation) diff --git a/real_estate/views/estate_property_menus.xml b/real_estate/views/estate_property_menus.xml new file mode 100644 index 00000000000..3d69d3341f3 --- /dev/null +++ b/real_estate/views/estate_property_menus.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/real_estate/views/estate_property_offer_views.xml b/real_estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..8e4c6b85d15 --- /dev/null +++ b/real_estate/views/estate_property_offer_views.xml @@ -0,0 +1,44 @@ + + + + estate.property.offer.action + estate.property.offers + list,form + [('property_type_id', '=', active_id)] + + + + estate.property.offer.list + estate.property.offers + + + + + + + + + + +

+ +

+
+ + + + + + + + + + + + + +
+
+ + + estate.property.type.list + estate.property.types + + + + + + + +
diff --git a/real_estate/views/estate_property_views.xml b/real_estate/views/estate_property_views.xml new file mode 100644 index 00000000000..feeb8c48352 --- /dev/null +++ b/real_estate/views/estate_property_views.xml @@ -0,0 +1,131 @@ + + + + Estate Property + estate.property + list,form + {'search_default_available': True} + +

Define a new Property

+

Create a Propety to sell/Buy

+
+
+ + + real.estate.list + estate.property + + + + + + + + + + + + + + real.estate.form + estate.property + +
+ +
+
+ + +

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + real.estate.search + estate.property + + + + + + + + + + + + + + + + + +
diff --git a/real_estate/views/res_users_views.xml b/real_estate/views/res_users_views.xml new file mode 100644 index 00000000000..4147af6eb45 --- /dev/null +++ b/real_estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.view.form.inherit.property + res.users + + + + + + + + + +