diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..7105d960c13 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -25,6 +25,9 @@ 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', ], + 'awesome_dashboard.dashboard': [ + 'awesome_dashboard/static/src/dashboard/**/*' + ] }, '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..cd75d4eefb3 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,87 @@ +/** @odoo-module **/ + +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 { DashboardItem } from "@awesome_dashboard/dashboard/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.display = { + controlPanel: {}, + }; + this.items = registry.category("awesome_dashboard").getAll(); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); + 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), + }); + } + openCustomers() { + this.action.doAction("base.action_partner_form"); + } + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } + openLeads() { + this.action.doAction({ + type: "ir.actions.act_window", + name: "Leads", + res_model: "crm.lead", + views: [ + [false, "list"], + [false, "form"], + ], + target: "current", + }); + } +} + +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..6be5e0f83c9 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: gray; +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..d7a1fbf27bb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + some content + +
+ + + + + + +
+
+
+ + + 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..fe6d3860e03 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,20 @@ +/** @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..73702c5ee4e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,70 @@ +/** @odoo-module **/ + +import { NumberCard } from "./number_card/number_card"; +import { PieChartCard } from "./pie_chart_card/pie_chart_card"; +import { registry } from "@web/core/registry"; +import { _t } from "@web/core/l10n/translation"; + +const items = [ + { + id: "average_quantity", + description: _t("Average amount of t-shirt"), + Component: NumberCard, + props: (data) => ({ + title: _t("Average amount of t-shirt by order this month"), + value: data.average_quantity, + }), + }, + { + id: "average_time", + description: _t("Average time for an order"), + Component: NumberCard, + props: (data) => ({ + title: _t( + "Average time for an order to go from 'new' to 'sent' or 'cancelled'" + ), + value: data.average_time, + }), + }, + { + id: "number_new_orders", + description: _t("New orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Number of new orders this month"), + value: data.nb_new_orders, + }), + }, + { + id: "cancelled_orders", + description: _t("Cancelled orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Number of cancelled orders this month"), + value: data.nb_cancelled_orders, + }), + }, + { + id: "amount_new_orders", + description: _t("Amount orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Total amount of new orders this month"), + value: data.total_amount, + }), + }, + { + id: "pie_chart", + description: _t("Shirt orders by size"), + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: _t("Shirt orders by size"), + values: data.orders_by_size, + }), + }, +]; + +items.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..966c77e2314 --- /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..ee259956902 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,49 @@ +/** @odoo-module */ + +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +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 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, + }, + ], + }, + }); + } +} 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..9bd37485f55 --- /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 "@awesome_dashboard/dashboard/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..85e7ae6bc2d --- /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/statistics.js b/awesome_dashboard/static/src/dashboard/statistics.js new file mode 100644 index 00000000000..b7feaa61d2a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics.js @@ -0,0 +1,25 @@ +/** @odoo-module */ + +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + dependencies: [], + start() { + const statistics = reactive({ isReady: false }); + + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + setTimeout(loadData, 10 * 60 * 1000); + } + loadData(); + + return statistics; + }, +}; + +registry + .category("services") + .add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..8a87687b2b4 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,16 @@ +/** @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_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..c68667485d2 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,19 @@ +/** @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 }, + slots: {}, + }; + + setup() { + this.state = useState({ isOpen: true }); + } + + toggle() { + 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..746dfcc64b1 --- /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..dc973b0faa5 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,22 @@ +/** @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++; + if (this.props.onChange) { + this.props.onChange(this.state.value); + } + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..fe6fd903bcc --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,10 @@ + + + + +
+

Counter:

+ +
+
+
diff --git a/awesome_owl/static/src/main.js b/awesome_owl/static/src/main.js index 1af6c827e0b..0b17bcbddb4 100644 --- a/awesome_owl/static/src/main.js +++ b/awesome_owl/static/src/main.js @@ -1,6 +1,6 @@ import { whenReady } from "@odoo/owl"; import { mountComponent } from "@web/env"; -import { Playground } from "./playground"; +import { Playground } from "@awesome_owl/playground"; const config = { dev: true, diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..7f06c913b47 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,27 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; +import { Counter } from "@awesome_owl/counter/counter"; +import { Card } from "@awesome_owl/card/card"; +import { TodoList } from "@awesome_owl/todo_list/todo_list"; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + + setup() { + this.state = useState({ + sum: 2, + }); + + this.counterValues = [1, 1]; + } + updateCounterValue(index, newValue) { + this.counterValues[index] = newValue; + this.state.sum = this.counterValues.reduce((a, b) => a + b, 0); + } + + handleCounterChange = (index) => { + return (val) => this.updateCounterValue(index, val); + }; } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..b0c700e10f8 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,25 @@ - + - -
- hello world +
+ + +
+
+
Total Sum:
+
+
+ + +

This paragraph is passed through the default slot.

+
+
+ + + +
+
+
- - + \ No newline at end of file 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..80ab3808255 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.js @@ -0,0 +1,16 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.todoitem"; + static props = { + todo: Object, + toggleState: Function, + removeTodo: Function, + }; + onToggle(ev) { + 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..89340a9383b --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_item.xml @@ -0,0 +1,13 @@ + + + +
+ + + : + + + +
+
+
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..acdb6597cf0 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,44 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "@awesome_owl/todo_list/todo_item"; +import { useAutofocus } from "@awesome_owl/utils"; + +export class TodoList extends Component { + static template = "awesome_owl.todolist"; + static components = { TodoItem }; + + setup() { + this.state = useState({ + newTaskDescription: "", + todos: [], + nextId: 1, + }); + this.toggleTodo = this.toggleTodo.bind(this); + useAutofocus("input"); + this.removeTodo = this.removeTodo.bind(this); + } + + addTodo(ev) { + if (ev.keyCode === 13 && this.state.newTaskDescription.trim() !== "") { + this.state.todos.push({ + id: this.state.nextId, + description: this.state.newTaskDescription.trim(), + isCompleted: false, + }); + this.state.newTaskDescription = ""; + this.state.nextId += 1; + } + } + + toggleTodo(id) { + const todo = this.state.todos.find((t) => t.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + removeTodo(id) { + const index = this.state.todos.findIndex((t) => t.id === id); + if (index >= 0) { + this.state.todos.splice(index, 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..66e204a9371 --- /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..a9b70206b9f --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +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..e2a45c00076 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,10 @@ +{ + 'name': "Account", + 'version': '1.0', + 'depends': ['real_estate', 'account'], + 'author': "gasa", + 'category': 'Category', + "license": "LGPL-3", + "application": True, + "sequence": 1 +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..ee0a6a651de --- /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_account diff --git a/estate_account/models/estate_account.py b/estate_account/models/estate_account.py new file mode 100644 index 00000000000..00a6086fd4d --- /dev/null +++ b/estate_account/models/estate_account.py @@ -0,0 +1,41 @@ +from odoo import models, Command +from odoo.exceptions import ValidationError + + +class EstateAccount(models.Model): + _inherit = 'estate.property' + + def _raise_invoice_data_missing(self): + raise ValidationError("Please set a Buyer and Selling Price before generating an invoice.") + + def action_mark_sold(self): + self.check_access('write') + res = super().action_mark_sold() + + for record in self: + if not record.buyer or not record.selling_price: + record._raise_invoice_data_missing() + + try: + invoice_vals = { + "partner_id": record.buyer.id, + "move_type": "out_invoice", + "invoice_line_ids": [ + Command.create({ + "name": "6% Commission", + "quantity": 1, + "price_unit": 0.06 * record.selling_price, + }), + Command.create({ + "name": "Administrative Fees", + "quantity": 1, + "price_unit": 100.0, + }), + ] + } + self.env["account.move"].sudo().create(invoice_vals) + + except Exception: # noqa: BLE001 + raise ValidationError("An error occurred during invoice generation.") + + return res 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..aac360c32f0 --- /dev/null +++ b/real_estate/__manifest__.py @@ -0,0 +1,27 @@ +{ + 'name': "estate", + 'version': '1.0', + 'depends': ['base'], + 'author': "gasa", + 'category': 'Real Estate/Brokerage', + "license": "LGPL-3", + "application": True, + "sequence": 1, + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + 'security/estate_property_rules.xml', + 'data/estate.property.type.csv', + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_tag_views.xml', + 'views/inherited_model.xml', + 'views/estate_menus.xml', + 'report/estate_property_offers_report_templates.xml', + 'report/estate_property_reports.xml' + ], + "demo": [ + 'demo/estate_property_demo_data.xml', + ] +} diff --git a/real_estate/data/estate.property.type.csv b/real_estate/data/estate.property.type.csv new file mode 100644 index 00000000000..23b45d983a3 --- /dev/null +++ b/real_estate/data/estate.property.type.csv @@ -0,0 +1,5 @@ +id,name +estate_property_type_residential,Residential +estate_property_type_commercial,Commercial +estate_property_type_industrial,Industrial +estate_property_type_land,Land diff --git a/real_estate/demo/estate_property_demo_data.xml b/real_estate/demo/estate_property_demo_data.xml new file mode 100644 index 00000000000..69260a1acdc --- /dev/null +++ b/real_estate/demo/estate_property_demo_data.xml @@ -0,0 +1,98 @@ + + + + Big Villa + new + A nice and big villa + 12345 + 2025-07-10 + 97000 + 97000 + 6 + 100 + 4 + True + True + 100 + south + + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 2025-07-10 + 1000 + 1000 + 2 + 100 + 4 + True + True + south + + + + + + + 90000 + 14 + + + + + + + 1500000 + 14 + + + + + + + 1500001 + 14 + + + + + + + + + + + + + + + + Estate with Inline Offers + new + 44444 + 120000 + 2025-07-15 + True + True + 3 + 95 + + + + diff --git a/real_estate/models/__init__.py b/real_estate/models/__init__.py new file mode 100644 index 00000000000..35928a71f7e --- /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_type +from . import estate_property_tag +from . import estate_property_offer +from . import inherited_model diff --git a/real_estate/models/estate_property.py b/real_estate/models/estate_property.py new file mode 100644 index 00000000000..4d84114a2a6 --- /dev/null +++ b/real_estate/models/estate_property.py @@ -0,0 +1,139 @@ +from odoo import api, fields, models +from datetime import date, timedelta +from odoo.exceptions import UserError +from odoo.exceptions import ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property" + _order = "id desc" + + _sql_constraints = [ + ('check_expected_price_positive', 'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'), + ('check_selling_price_positive', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'), + ] + + name = fields.Char(required=True, string="Property name") + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + expected_price = fields.Float() + bedrooms = fields.Integer(default=2) + last_seen = fields.Datetime("Last Seen", default=fields.Date.today) + date_availability = fields.Date(default=lambda self: date.today() + timedelta(days=90), copy=False) + active = fields.Boolean(default=True) + living_area = fields.Integer(string="Living Area") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area") + garden_orientation = fields.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') + ], + default='new', + required=True, + copy=False + ) + property_type = fields.Many2one("estate.property.type", string="Property Type") + buyer = fields.Many2one( + "res.partner", + string="Buyer", + copy=False + ) + seller = fields.Many2one( + "res.users", + string="Salesperson", + default=lambda self: self.env.user + ) + tag_ids = fields.Many2many("estate.property.tag", string="Tags") + offer_ids = fields.One2many( + "estate.property.offer", "property_id", string="Offers" + ) + total_area = fields.Integer( + string="Total Area", + compute="_compute_total_area", + store=True + ) + + best_price = fields.Float( + string="Best Offer", + compute="_compute_best_price" + ) + + selling_price = fields.Float(copy=False) + company_id = fields.Many2one( + 'res.company', + string='Company', + required=True, + default=lambda self: self.env.company + ) + + @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("offer_ids.price") + def _compute_best_price(self): + for record in self: + prices = record.offer_ids.mapped("price") + record.best_price = max(prices) if prices else 0.0 + + def action_mark_sold(self): + for record in self: + if not any(offer.status == 'accepted' for offer in record.offer_ids): + raise UserError("You cannot sell a property without an accepted offer.") + if record.state == 'cancelled': + raise UserError("Canceled properties cannot be sold.") + record.state = 'sold' + + def action_mark_cancelled(self): + for record in self: + if record.state == 'sold': + raise UserError("Sold properties cannot be canceled.") + record.state = 'cancelled' + + @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 + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price_threshold(self): + for record in self: + if float_is_zero(record.selling_price, precision_digits=2): + continue + + minimum_allowed = record.expected_price * 0.9 + + if float_compare(record.selling_price, minimum_allowed, precision_digits=2) < 0: + raise ValidationError( + ("The selling price cannot be lower than 90%% of the expected price.\n" + "Expected Price: %.2f, Selling Price: %.2f (Minimum allowed: %.2f)") % + (record.expected_price, record.selling_price, minimum_allowed) + ) + + @api.ondelete(at_uninstall=False) + def _check_property_state_before_delete(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("You can only delete properties that are in 'New' or 'Cancelled' state.") diff --git a/real_estate/models/estate_property_offer.py b/real_estate/models/estate_property_offer.py new file mode 100644 index 00000000000..0c53b2db5a2 --- /dev/null +++ b/real_estate/models/estate_property_offer.py @@ -0,0 +1,85 @@ +from odoo import api, models, fields +from odoo.exceptions import UserError, ValidationError +from datetime import timedelta + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Property Offer" + _order = "price desc" + + _sql_constraints = [ + ('check_offer_price_positive', 'CHECK(price > 0)', + 'The offer price must be strictly positive.'), + ] + + price = fields.Float() + status = fields.Selection([ + ('accepted', 'Accepted'), + ('refused', 'Refused') + ], + copy=False + ) + + partner_id = fields.Many2one("res.partner", string="Customer", required=True) + property_id = fields.Many2one("estate.property", string="Property", required=True) + + property_type_id = fields.Many2one( + related='property_id.property_type', + string="Property Type", + store=True + ) + + validity = fields.Integer(default=7) + date_deadline = fields.Date( + compute="_compute_date_deadline", + inverse="_inverse_date_deadline", + store=True + ) + + @api.depends("validity", "create_date") + def _compute_date_deadline(self): + for record in self: + create_date = record.create_date or fields.Datetime.now() + record.date_deadline = create_date.date() + timedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + create_date = record.create_date or fields.Datetime.now() + record.validity = (record.date_deadline - create_date.date()).days + + def action_accept(self): + for offer in self: + if offer.property_id.state == 'sold': + raise UserError("Cannot accept an offer for a sold property.") + other_offers = offer.property_id.offer_ids.filtered(lambda o: o.id != offer.id) + other_offers.write({'status': 'refused'}) + + offer.status = 'accepted' + offer.property_id.selling_price = offer.price + offer.property_id.buyer = offer.partner_id + offer.property_id.state = 'offer_accepted' + + def action_refuse(self): + for offer in self: + offer.status = 'refused' + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_id = vals.get('property_id') + amount = vals.get('price') + property = self.env['estate.property'].browse(property_id) + existing_offers = property.offer_ids.filtered(lambda o: o.price is not None and amount is not None and o.price >= amount) + + if property_id and amount: + if property.state == 'sold': + raise UserError("Cannot create offer for a sold property.") + + if existing_offers: + raise ValidationError("An offer with a higher or equal price already exists.") + + if property.state == 'new': + property.state = 'offer_received' + + return super().create(vals_list) diff --git a/real_estate/models/estate_property_tag.py b/real_estate/models/estate_property_tag.py new file mode 100644 index 00000000000..711f2f7cd11 --- /dev/null +++ b/real_estate/models/estate_property_tag.py @@ -0,0 +1,16 @@ +from odoo import models, fields + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Real Estate Property Tag" + _order = "name" + + _sql_constraints = [ + ('unique_tag_name', 'UNIQUE(name)', + 'Tag name must be unique.'), + ] + + name = fields.Char(required=True) + color = fields.Integer(string="Color") + sequence = fields.Integer(string="Sequence", default=10) diff --git a/real_estate/models/estate_property_type.py b/real_estate/models/estate_property_type.py new file mode 100644 index 00000000000..7e89767d737 --- /dev/null +++ b/real_estate/models/estate_property_type.py @@ -0,0 +1,23 @@ +from odoo import api, models, fields + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Property Type" + _order = "sequence, name" + + _sql_constraints = [ + ('unique_property_type_name', 'UNIQUE(name)', + 'Property type name must be unique.'), + ] + + name = fields.Char(required=True) + sequence = fields.Integer(string="Sequence", default=10) + property_ids = fields.One2many("estate.property", "property_type", string="Properties") + offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string="Offers") + offer_count = fields.Integer(compute='_compute_offer_count') + + @api.depends('offer_ids') + def _compute_offer_count(self): + for rec in self: + rec.offer_count = len(rec.offer_ids) diff --git a/real_estate/models/inherited_model.py b/real_estate/models/inherited_model.py new file mode 100644 index 00000000000..01f6e9433e7 --- /dev/null +++ b/real_estate/models/inherited_model.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class InheritedModel(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", + "seller", + string="Properties", + domain=[('state', '!=', 'cancelled')] + ) diff --git a/real_estate/report/estate_property_offers_report_templates.xml b/real_estate/report/estate_property_offers_report_templates.xml new file mode 100644 index 00000000000..49067bc0267 --- /dev/null +++ b/real_estate/report/estate_property_offers_report_templates.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + diff --git a/real_estate/report/estate_property_reports.xml b/real_estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..8654b13bc88 --- /dev/null +++ b/real_estate/report/estate_property_reports.xml @@ -0,0 +1,22 @@ + + + + Print Offers + estate.property + qweb-pdf + real_estate.report_estate_property_offers + real_estate.report_estate_property_offers + 'Property Offers - %s' % (object.name).replace('/','') + + + + + Print Properties + res.users + qweb-pdf + real_estate.report_salesman_properties + real_estate.report_salesman_properties + 'Properties - %s' % (object.name).replace('/','') + + + diff --git a/real_estate/security/estate_property_rules.xml b/real_estate/security/estate_property_rules.xml new file mode 100644 index 00000000000..3a244109a09 --- /dev/null +++ b/real_estate/security/estate_property_rules.xml @@ -0,0 +1,35 @@ + + + Agents: Own or Unassigned Properties Only + + + [ + '|', + ('seller', '=', user.id), + ('seller', '=', False) + ] + + + + + + + Managers: Full Access to Properties + + + [(1, '=', 1)] + + + + + + + Estate Property Multi-company + + [ + ('company_id', 'in', company_ids) + ] + + + + diff --git a/real_estate/security/ir.model.access.csv b/real_estate/security/ir.model.access.csv new file mode 100644 index 00000000000..81140b8f75e --- /dev/null +++ b/real_estate/security/ir.model.access.csv @@ -0,0 +1,9 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property_manager,access_estate_property_manager,model_estate_property,estate_group_manager,1,1,1,0 +access_estate_property_type_manager,access_estate_property_type_manager,model_estate_property_type,estate_group_manager,1,1,1,1 +access_estate_property_tag_manager,access_estate_property_tag_manager,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_offer_manager,access_estate_offer_manager,model_estate_property_offer,estate_group_manager,1,1,1,1 + +access_estate_property_user,access_estate_property_user,model_estate_property,estate_group_user,1,1,1,0 +access_estate_property_type_user,access_estate_property_type_user,model_estate_property_type,estate_group_user,1,0,0,0 +access_estate_property_tag_user,access_estate_property_tag_user,model_estate_property_tag,estate_group_user,1,0,0,0 diff --git a/real_estate/security/security.xml b/real_estate/security/security.xml new file mode 100644 index 00000000000..4ec7d9a4e01 --- /dev/null +++ b/real_estate/security/security.xml @@ -0,0 +1,13 @@ + + + + Agent + + + + + Manager + + + + diff --git a/real_estate/tests/__init__.py b/real_estate/tests/__init__.py new file mode 100644 index 00000000000..27788f94d44 --- /dev/null +++ b/real_estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_property_offer diff --git a/real_estate/tests/test_property_offer.py b/real_estate/tests/test_property_offer.py new file mode 100644 index 00000000000..f88aa223bba --- /dev/null +++ b/real_estate/tests/test_property_offer.py @@ -0,0 +1,67 @@ +from odoo.tests.common import TransactionCase +from odoo.tests import Form +from odoo.exceptions import UserError +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestEstatePropertyLogic(TransactionCase): + def setUp(self): + super().setUp() + Property = self.env['estate.property'] + Offer = self.env['estate.property.offer'] + + self.partner = self.env['res.partner'].create({ + 'name': 'Test Buyer', + 'email': 'buyer@example.com' + }) + + self.property = Property.create({ + 'name': 'Test Property', + 'state': 'new', + 'expected_price': 150000, + 'garden': True, + 'garden_area': 100, + 'garden_orientation': 'north', + }) + + self.offer = Offer.create({ + 'property_id': self.property.id, + 'partner_id': self.partner.id, + 'price': 160000, + }) + + def test_cannot_create_offer_on_sold_property(self): + self.property.state = 'sold' + with self.assertRaises(UserError): + self.env['estate.property.offer'].create({ + 'property_id': self.property.id, + 'partner_id': self.partner.id, + 'price': 170000 + }) + + def test_cannot_sell_property_without_accepted_offer(self): + self.property.offer_ids.unlink() + with self.assertRaises(UserError): + self.property.action_mark_sold() + + def test_can_sell_property_with_accepted_offer(self): + self.offer.action_accept() + self.property.action_mark_sold() + self.assertEqual(self.property.selling_price, self.offer.price) + self.assertEqual(self.property.buyer, self.partner) + + def test_reset_garden_fields_when_unchecked(self): + form = Form(self.env['estate.property']) + form.name = 'Garden Test' + form.garden = True + form.expected_price = 15000 + form.garden_area = 50 + form.garden_orientation = 'east' + prop = form.save() + + prop.garden = False + prop._onchange_garden() + + self.assertEqual(prop.garden_area, 0) + self.assertFalse(prop.garden_orientation) diff --git a/real_estate/views/estate_menus.xml b/real_estate/views/estate_menus.xml new file mode 100644 index 00000000000..3ec765e4dc4 --- /dev/null +++ b/real_estate/views/estate_menus.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + 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..d19cb776387 --- /dev/null +++ b/real_estate/views/estate_property_offer_views.xml @@ -0,0 +1,38 @@ + + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + +
+
+
+ + Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + +
diff --git a/real_estate/views/estate_property_type_views.xml b/real_estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..5dc67dd130b --- /dev/null +++ b/real_estate/views/estate_property_type_views.xml @@ -0,0 +1,43 @@ + + + estate.property.type.form + estate.property.type + +
+ + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + Property Types + estate.property.type + list,form + + +
diff --git a/real_estate/views/estate_property_views.xml b/real_estate/views/estate_property_views.xml new file mode 100644 index 00000000000..f82b902a401 --- /dev/null +++ b/real_estate/views/estate_property_views.xml @@ -0,0 +1,147 @@ + + + + estate.property.form + estate.property + +
+
+
+ +
+
+

+ +

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +