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..abbaff37165 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,78 @@ +/** @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 "./dashboardItem/dashboarditem"; +import { rpc } from "@web/core/network/rpc"; +import { DashboardSetting } from "./dashboardSetting/dashboardsetting"; +import { PieChart } from "./piechart/piechart"; + + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + + static components = { Layout, DashboardItem, PieChart }; + + setup() { + const dashboardItemsRegistry = registry.category("awesome_dashboard"); + this.items = dashboardItemsRegistry.getAll(); + this.dialogService = useService("dialog"); + + + this.action = useService("action"); + this.statisticsService = useService("awesome_dashboard.statistics"); + this.state = useState({ statistics: this.statisticsService.statistics }); + + + this.displayState = useState({ + disabledItems: [], + isLoading: true, + }); + onWillStart(async () => { + try { + const fetchedDisabledItems = await rpc("/web/dataset/call_kw/res.users/get_dashboard_settings", { + model: 'res.users', + method: 'get_dashboard_settings', + args: [], + kwargs: {}, + }); + this.displayState.disabledItems = fetchedDisabledItems; + } catch (error) { + console.error("Error loading initial dashboard settings from server:", error); + this.displayState.disabledItems = []; + } finally { + this.displayState.isLoading = false; + } + }); + } + + updateSettings(newUncheckedItems) { + this.displayState.disabledItems.length = 0; + this.displayState.disabledItems.push(...newUncheckedItems); + } + + openSettings() { + this.dialogService.add(DashboardSetting, { + items: this.items, + initialDisabledItems: this.displayState.disabledItems, + updateSettings: this.updateSettings.bind(this), + }); + } + + openCustomerView() { + this.action.doAction("base.action_partner_form") + } + + openLeadsView() { + this.action.doAction({ + type: 'ir.actions.act_window', + target: 'current', + res_model: 'crm.lead', + views: [[false, 'list'], [false, 'form']], + }) + } +} + +registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..bbf4b8fa7e0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,28 @@ + + + + + + + Customer + Leads + + + + + + + + + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.js b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.js new file mode 100644 index 00000000000..15e7c7404bd --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl" + +export class DashboardItem extends Component { + static template = "awesome_dashboard.DashboardItem" + + static props = { + size: { type: Number, optional: true, default: 1 }, + } +} diff --git a/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.xml b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.xml new file mode 100644 index 00000000000..cacdc48785b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboardItem/dashboarditem.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.js b/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.js new file mode 100644 index 00000000000..59c75cbd722 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.js @@ -0,0 +1,58 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { rpc } from "@web/core/network/rpc"; +import { _t } from "@web/core/l10n/translation"; + +export class DashboardSetting extends Component { + static template = "awesome_dashboard.setting"; + + static components = { Dialog }; + + static props = { + close: { type: Function } + }; + + setup() { + const items = this.props.items || {}; + const initialDisabledItems = this.props.initialDisabledItems || []; + this.settingDisplayItems = Object.values(items).map((item) => ({ + ...item, + checked: !initialDisabledItems.includes(item.id), + })) + } + + _t(...args) { + return _t(...args); + } + + onChange(checked, itemInDialog) { + const targetItem = this.settingDisplayItems.find(i => i.id === itemInDialog.id); + if (targetItem) { + targetItem.checked = checked; + } + } + + async confirmDone() { + const newDisableItems = this.settingDisplayItems.filter((item) => !item.checked).map((item) => item.id); + console.log("Items to disable:", newDisableItems); + + try { + const result = await rpc("/web/dataset/call_kw/res.users/set_dashboard_settings", { + model: 'res.users', + method: 'set_dashboard_settings', + args: [newDisableItems], + kwargs: {}, + }); + console.log("RPC call successful, result:", result); + } catch (error) { + console.error("RPC call failed:", error); + } + + if (this.props.updateSettings) { + this.props.updateSettings(newDisableItems); + } + this.props.close(); + } +} diff --git a/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.xml b/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.xml new file mode 100644 index 00000000000..c415c8d77a1 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboardSetting/dashboardsetting.xml @@ -0,0 +1,26 @@ + + + + + + Select items to display on your dashboard: + + + + + + + + + Done + Cancel + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashbord.scss b/awesome_dashboard/static/src/dashboard/dashbord.scss new file mode 100644 index 00000000000..22f0895fd7f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashbord.scss @@ -0,0 +1,40 @@ +.o_dashboard{ + background-color: gray; +} +.o_dashboard_stat_block { + text-align: center; + margin-bottom: 24px; +} + +.o_dashboard_stat_label { + font-weight: normal; + margin-bottom: 10px; + display: block; +} + +.o_dashboard_stat_value { + font-size: 48px; + color: #228B22; + font-weight: bold; +} +.o_dashboard_item { + background: #fff; + border-radius: 0.75rem; + box-shadow: 0 2px 8px rgba(0,0,0,0.07); + padding: 1rem; + margin: 1rem; + display: inline-flex; + justify-content: center; + vertical-align: top; + min-height: 3rem; +} + +@media (max-width: 426px) { + .o_dashboard_item { + width: 100% !important; + display: flex; + margin-left: 0.5rem; + margin-right: 0.5rem; + box-sizing: border-box; + } +} diff --git a/awesome_dashboard/static/src/dashboard/dashbord_item.js b/awesome_dashboard/static/src/dashboard/dashbord_item.js new file mode 100644 index 00000000000..f93c1720fd2 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashbord_item.js @@ -0,0 +1,70 @@ +import { NumberCard } from "./numbercard/numbercard"; +import { PieChartCard } from "./piechartcard/piechartcard"; +import { registry } from "@web/core/registry"; +import { _t } from "@web/core/l10n/translation"; + +const items = [ + { + id: "nb_new_orders", + description: _t("The number of new orders, this month"), + Component: NumberCard, + size: 1, + props: (data) => ({ + title: _t("New Orders This Month:"), + value: data.data.nb_new_orders + }), + }, + { + id: "total_amount", + description: _t("The total amount of orders, this month"), + Component: NumberCard, + size: 2, + props: (data) => ({ + title: "Total Amount This Month:", + value: data.data.total_amount + }), + }, + { + id: "average_quantity", + description: _t("The average number of t-shirts by order"), + Component: NumberCard, + size: 1, + props: (data) => ({ + title: _t("Avg. T-Shirts per Order:"), + value: data.data.average_quantity + }), + }, + { + id: "nb_cancelled_orders", + description: _t("The number of cancelled orders, this month"), + Component: NumberCard, + size: 1, + props: (data) => ({ + title: _t("Cancelled Orders:"), + value: data.data.nb_cancelled_orders + }), + }, + { + id: "average_time", + description: _t("The average time (in hours) elapsed between the moment an order is created, and the moment is it sent"), + Component: NumberCard, + size: 1, + props: (data) => ({ + title: _t("Avg. Time New → Sent/Cancelled:"), + value: data.data.average_time + }), + }, + { + id: "orders_by_size", + description: _t("Number of shirts ordered based on size"), + Component: PieChartCard, + size: 3, + props: (data) => ({ + title: _t("Shirt orders by size:"), + value: data.data.orders_by_size + }), + } +] +items.forEach((item) => { + registry.category("awesome_dashboard").add(item.id, item) +}); diff --git a/awesome_dashboard/static/src/dashboard/numbercard/numbercard.js b/awesome_dashboard/static/src/dashboard/numbercard/numbercard.js new file mode 100644 index 00000000000..d433197bec3 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/numbercard/numbercard.js @@ -0,0 +1,17 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; +import { _t } from "@web/core/l10n/translation"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + + static props = { + title: { type: String }, + value: { type: [String, Number] } + } + + setup() { + this._t = _t; + } +} diff --git a/awesome_dashboard/static/src/dashboard/numbercard/numbercard.xml b/awesome_dashboard/static/src/dashboard/numbercard/numbercard.xml new file mode 100644 index 00000000000..24fffbbf69f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/numbercard/numbercard.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/piechart/piechart.js b/awesome_dashboard/static/src/dashboard/piechart/piechart.js new file mode 100644 index 00000000000..be91ff81193 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart/piechart.js @@ -0,0 +1,69 @@ +/** @odoo-module **/ + +import { Component, onWillStart, useRef, onMounted, useEffect, onWillUnmount } from "@odoo/owl"; +import { loadJS } from "@web/core/assets" + +export class PieChart extends Component { + static template = "awesome_dashboard.Piechart"; + static props = { + data: { type: Object }, + onSliceClick: { type: Function, optional: true }, + }; + setup() { + this.chart = null; + this.pieChartCanvasRef = useRef("pie_chart_canvas"); + + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }) + + this.chartData = { + labels: Object.keys(this.props.data), + datasets: [{ + data: Object.values(this.props.data) + }] + }; + + onMounted(() => { + this.makePieChart(); + }) + + this.cleanupPieChart = () => { + if (this.chart) { + this.chart.destroy(); + this.chart = null; + } + }; + + onWillUnmount(this.cleanupPieChart); + + + useEffect(() => { + this.cleanupPieChart(); + if (this.pieChartCanvasRef.el) { + this.makePieChart(); + } + }, () => [this.props.data]) + } + + makePieChart() { + this.chart = new Chart(this.pieChartCanvasRef.el, { + type: "pie", + data: this.chartData, + options: { + responsive: true, + maintainAspectRatio: false, + onClick: (event, elements) => { + if (elements.length > 0) { + const clickedElementIndex = elements[0].index; + const label = this.chartData.labels[clickedElementIndex]; + if (this.props.onSliceClick) { + this.props.onSliceClick(label); + } + } + } + + } + }) + } +} diff --git a/awesome_dashboard/static/src/dashboard/piechart/piechart.xml b/awesome_dashboard/static/src/dashboard/piechart/piechart.xml new file mode 100644 index 00000000000..83b790ccf7a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechart/piechart.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.js b/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.js new file mode 100644 index 00000000000..57dc53a323b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.js @@ -0,0 +1,24 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; +import { PieChart } from "../piechart/piechart"; +import { useService } from "@web/core/utils/hooks"; +import { _t } from "@web/core/l10n/translation"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart }; + + static props = { + title: { type: String }, + data: { type: Object } + } + + setup() { + this.action = useService("action"); + } + + _t(...args) { + return _t(...args); + } +} diff --git a/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.xml b/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.xml new file mode 100644 index 00000000000..0d5e4e2eb34 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/piechartcard/piechartcard.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/statistics.js b/awesome_dashboard/static/src/dashboard/statistics.js new file mode 100644 index 00000000000..e97c4c37487 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics.js @@ -0,0 +1,38 @@ +/** @odoo-module **/ + +import { rpc } from "@web/core/network/rpc"; +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { memoize } from "@web/core/utils/functions"; // Import memoize + +const statisticsService = { + start() { + const statistics = reactive({ data: null, loading: true, error: null }); + + async function _fetchStatistics() { + statistics.loading = true; + statistics.error = null; + try { + const response = await rpc("/awesome_dashboard/statistics"); + statistics.data = response; + return response; + } catch (e) { + statistics.error = e; + throw e; + } finally { + statistics.loading = false; + } + } + + const loadStatistics = memoize(_fetchStatistics); + loadStatistics(); + setInterval(_fetchStatistics, 600000); + + + return { + statistics, + loadStatistics, + }; + }, +}; +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..6d27b2f12a9 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_action.js @@ -0,0 +1,12 @@ +import { Component, xml } from "@odoo/owl" +import { LazyComponent } from "@web/core/assets"; +import { registry } from "@web/core/registry"; + +export class DashboardComponentLoader extends Component { + static components = { LazyComponent } + static template = xml` + + `; + +} +registry.category("actions").add("awesome_dashboard.dashboard", DashboardComponentLoader); diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..38015b002d2 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,19 @@ +import { Component, useState } from '@odoo/owl'; + + +export class Card extends Component{ + static template = "awesome_owl.Card"; + static props = { + title: String, + slots: { + type: Object, + shape: { default: true }, + }, + }; + setup() { + this.state = useState({ isToggled: true }); + } + toggle() { + this.state.isToggled = !this.state.isToggled; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..159b54d64cc --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,16 @@ + + + + + + + + Toggle Button + + + + + + + + diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..88d13ae6aa6 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,21 @@ +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..17ce51491cf --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + + + Counter: + Increment + + + diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..a0284f0ac17 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,18 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { useState, markup, Component } from "@odoo/owl"; +import { Counter } from "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo/todolist"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = {Counter, Card, TodoList}; + setup() { + this.state = useState({ sum: 2 }); + } + + incrementSum() { + this.state.sum += 1; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..c28dae27241 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,24 @@ - - hello world + hello world + + + + + The Sum is: + + + + This is the content of Card 1. + + + + + + + - diff --git a/awesome_owl/static/src/todo/todoitem.js b/awesome_owl/static/src/todo/todoitem.js new file mode 100644 index 00000000000..b274f3726df --- /dev/null +++ b/awesome_owl/static/src/todo/todoitem.js @@ -0,0 +1,20 @@ +/** @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, + }, + optional: false, + }, + toggleState: Function, + removeTodo: Function, + }; +} diff --git a/awesome_owl/static/src/todo/todoitem.xml b/awesome_owl/static/src/todo/todoitem.xml new file mode 100644 index 00000000000..2a71f8bb27f --- /dev/null +++ b/awesome_owl/static/src/todo/todoitem.xml @@ -0,0 +1,15 @@ + + + + + + . + + + + + diff --git a/awesome_owl/static/src/todo/todolist.js b/awesome_owl/static/src/todo/todolist.js new file mode 100644 index 00000000000..8c8b93d2304 --- /dev/null +++ b/awesome_owl/static/src/todo/todolist.js @@ -0,0 +1,55 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todoitem"; +import { useAutofocus } from "../utils/utils"; + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.state = useState({ + text: "", + todos: [], + nextId: 1, + }); + this.inputRef = useAutofocus("input"); + this.toggleState = this.toggleState.bind(this); + this.removeTodo = this.removeTodo.bind(this); + + + } + + addTodo(ev) { + if (ev.key === "Enter") { + const description = this.state.text.trim(); + if (!description) return; + + this.state.todos.push({ + id: this.state.nextId++, + description: description, + isCompleted: false, + }); + this.state.text = ""; + } + } + + toggleState(todoId) { + const todo = this.state.todos.find((t) => t.id === todoId); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(todoId) { + const index = this.state.todos.findIndex((t) => t.id === todoId); + if (index >= 0) { + this.state.todos.splice(index, 1); + for (let i = index; i < this.state.todos.length; i++) { + this.state.todos[i].id = i + 1; + } + } + this.state.nextId = this.state.todos.length + 1; + } +} diff --git a/awesome_owl/static/src/todo/todolist.xml b/awesome_owl/static/src/todo/todolist.xml new file mode 100644 index 00000000000..2b1a0652421 --- /dev/null +++ b/awesome_owl/static/src/todo/todolist.xml @@ -0,0 +1,19 @@ + + + + + Todo List + + + + + + + diff --git a/awesome_owl/static/src/utils/utils.js b/awesome_owl/static/src/utils/utils.js new file mode 100644 index 00000000000..4ebcaa1a7e6 --- /dev/null +++ b/awesome_owl/static/src/utils/utils.js @@ -0,0 +1,13 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(input) { + const inputRef = useRef(input); + + onMounted(() => { + if (inputRef.el) { + inputRef.el.focus(); + } + }); + + return { inputRef }; +} diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..d6210b1285d --- /dev/null +++ b/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/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..40b72723937 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,24 @@ +{ + 'name': 'Estate', + "version": "1.0", + "category": "Real Estate/Brokerage", + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + 'report/estate_property_templates.xml', + 'report/estate_property_offer_reports.xml', + 'views/estate_property_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + 'data/estate_property_type.xml', + ], + 'demo': [ + 'demo/estate_property_demo.xml', + 'demo/estate_property_offer.xml' + ], + 'application': True, + 'installable': True, + 'license': 'LGPL-3', +} diff --git a/estate/data/estate_property_type.xml b/estate/data/estate_property_type.xml new file mode 100644 index 00000000000..f38dd784bcc --- /dev/null +++ b/estate/data/estate_property_type.xml @@ -0,0 +1,18 @@ + + + + Residential + + + + Commercial + + + + Industrial + + + + Land + + diff --git a/estate/demo/estate_property_demo.xml b/estate/demo/estate_property_demo.xml new file mode 100644 index 00000000000..c7248cc2d6a --- /dev/null +++ b/estate/demo/estate_property_demo.xml @@ -0,0 +1,50 @@ + + + + Big Villa + new + A nice and big villa + 12345 + 2020-02-02 + 1600000.0 + 6 + 100 + 4 + 1 + 1 + 100000 + south + + + + Trailer Home + cancelled + Home in trailer park. + 54321 + 1970-01-01 + 100000.00 + 120000.00 + 1 + 10 + 4 + 0 + + + diff --git a/estate/demo/estate_property_offer.xml b/estate/demo/estate_property_offer.xml new file mode 100644 index 00000000000..8d559dd9b1d --- /dev/null +++ b/estate/demo/estate_property_offer.xml @@ -0,0 +1,30 @@ + + + + 1000000000 + 14 + + + + + 1500000000000 + 14 + + + + + 15000000000001 + 11 + + + + + + + + + + + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..f7e4cc6f3dd --- /dev/null +++ b/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 res_users diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..cb37645a2bc --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,91 @@ +from datetime import date +from dateutil.relativedelta import relativedelta +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property is defined" + _order = "id desc" + _sql_constraints = [ + ('check_expected_price', 'CHECK(expected_price > 0 AND selling_price > 0)', + 'The Price must be positve.') + ] + + name = fields.Char(required=True) + description = fields.Text(string='Description') + postcode = fields.Char(string='Postcode') + date_avaiblity = fields.Date(copy=False, default=date.today() + relativedelta(months=3)) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + 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') + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + salesman_id = fields.Many2one('res.users', string='Salesman', index=True, default=lambda self: self.env.user) + buyer_id = fields.Many2one('res.partner', string='Buyer', index=True, default=lambda self: self.env.user.partner_id.id) + property_tag_ids = fields.Many2many("estate.property.tag") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + total_area = fields.Float(compute="_compute_total") + best_price = fields.Float(compute="_compute_best_price", string="Best Offer Price", readonly=True) + active = fields.Boolean(default=True) + company_id = fields.Many2one("res.company", required=True, default=lambda self: self.env.company) + + @api.depends("garden_area", "living_area") + def _compute_total(self): + for record in self: + record.total_area = record.garden_area + record.living_area + + @api.depends("offer_ids.price") + def _compute_best_price(self): + for record in self: + if record.offer_ids: + record.best_price = max(record.offer_ids.mapped('price')) + else: + record.best_price = 0.0 + + garden_orientation = fields.Selection( + string='Direction', + selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], + help="This is used to locate garden's direction" + ) + + state = fields.Selection( + selection=[('new', 'New'), ('offer received', 'Offer Received'), ('offer accepted', 'Offer Accepted'), ('sold', 'Sold'), ('cancelled', 'Cancelled')], + default='new', + required=True, + copy=False, + ) + + @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_cancel(self): + for record in self: + if record.state == 'sold': + raise UserError("Sold properties cannot be cancelled.") + record.state = 'cancelled' + + def action_sold(self): + for record in self: + if record.state == 'cancelled': + raise UserError("Cancelled properties cannot be marked as sold.") + elif record.state != 'offer accepted': + raise UserError("Atleast one offer should be accepted.") + record.state = 'sold' + + @api.ondelete(at_uninstall=False) + def _check_state_delete(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("Only properties in 'New' or 'Cancelled' state can be deleted.") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..e7728298f2a --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,71 @@ +from datetime import timedelta +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Offers related to property are made" + _order = "price desc" + _sql_constraints = [ + ('check_price', 'CHECK(price > 0)', 'The offer price must be greater than 0') + ] + + price = fields.Float() + partner_id = fields.Many2one("res.partner", string='Partner', index=True, default=lambda self: self.env.user.partner_id.id) + property_id = fields.Many2one("estate.property", index=True, required=True) + validity = fields.Integer(default=7) + date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + property_type_id = fields.Many2one('estate.property.type', index=True) + + @api.depends('create_date', 'validity') + def _compute_date_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.today() + record.date_deadline = create_date + timedelta(days=record.validity) + + def _inverse_date_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.today() + if record.date_deadline: + record.validity = (record.date_deadline.day - create_date.day) + + status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refuse')], copy=False) + + def action_confirm(self): + for record in self: + if any(offer.status == 'accepted' for offer in record.property_id.offer_ids): + raise UserError("Only one offer can be accepted per property.") + min_price = record.property_id.expected_price * 0.9 + if float_compare(record.price, min_price, precision_digits=2) < 0: + raise ValidationError("Offer must be at least 90% of the expected price to be accepted.") + record.write({'status': 'accepted'}) + record.property_id.write({ + 'state': 'offer accepted', + 'selling_price': record.price, + 'buyer_id': record.partner_id.id + }) + (record.property_id.offer_ids - record).write({'status': 'refused'}) + + def action_refuse(self): + for record in self: + record.status = 'refused' + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property_id = vals.get("property_id") + price = vals.get("price", 0.0) + if property_id: + property_obj = self.env["estate.property"].browse(property_id) + best_price = property_obj.best_price or 0.0 + if price < best_price: + raise UserError( + "Offer price must be greater than or equal to the best offer price." + ) + records = super().create(vals_list) + for record in records: + if record.partner_id: + record.property_id.state = "offer received" + return records diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..6e614219e10 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Tags of estate are defined" + _order = "name asc" + _sql_constraints = [ + ('check_unique_name', 'UNIQUE(name)', 'The name of the tag should be unique') + ] + + name = fields.Char(required=True) + color = fields.Integer(string='Color') diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..d19bb8d10da --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,21 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Type of estate is defined" + _order = "name asc" + _sql_constraints = [ + ('check_unique_property_type', 'UNIQUE(name)', 'The Property type should be unique') + ] + + name = fields.Char(required=True) + property_ids = fields.One2many('estate.property', 'property_type_id') + sequence = fields.Integer() + offer_ids = fields.One2many('estate.property.offer', 'property_type_id') + offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count") + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = sum(len(property.offer_ids) for property in record.property_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..aedc23284b0 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many('estate.property', 'salesman_id', domain=[('state', 'not in', ['sold', 'cancelled'])]) diff --git a/estate/report/estate_property_offer_reports.xml b/estate/report/estate_property_offer_reports.xml new file mode 100644 index 00000000000..46b81f96084 --- /dev/null +++ b/estate/report/estate_property_offer_reports.xml @@ -0,0 +1,41 @@ + + + + A4 low margin + + A4 + 0 + 0 + Portrait + 5 + 5 + 5 + 5 + + 0 + 80 + + + Property Offers + estate.property + qweb-pdf + estate.report_estate_property_offers + estate.report_estate_property_offers + '%s - Property Offers' % (object.name) + + + report + + + + Salesman Property + res.users + qweb-pdf + estate.report_estate_property_salesman + estate.report_estate_property_salesman + '%s - Property Offers' % (object.name) + + + report + + diff --git a/estate/report/estate_property_templates.xml b/estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..6c047935d9a --- /dev/null +++ b/estate/report/estate_property_templates.xml @@ -0,0 +1,143 @@ + + + + + + + + + Price + + + Partner + + + Validity (days) + + + Deadline + + + Status + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Salesman: + + + + Expected Price: + + + + Status: + + + + + !!! Invoice is already being created!!! + + + + + + + No offers available for this property. + + + + + + + + + + + + + + Salesman: + + + + + + + + + + Expected Price: + + + + Status: + + + + + + + No offers available for this property. + + + + + + No properties available for this salesman. + + + + + + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..617a07d1601 --- /dev/null +++ b/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 +access_property_manager,access_estate_property_manager,model_estate_property,estate_group_manager,1,1,1,1 +access_property_type_manager,access_estate_property_type_manager,model_estate_property_type,estate_group_manager,1,1,1,1 +access_property_tag_manager,access_estate_property_tag_manager,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_property_offer_manager,access_estate_property_offer_manager,model_estate_property_offer,estate_group_manager,1,1,1,1 +access_res_users_manager,access_res_users_manager,model_res_users,estate_group_manager,1,1,1,1 +access_property_agent,access_estate_property_agent,model_estate_property,estate_group_user,1,1,1,0 +access_property_offer_agent,access_estate_property_offer_agent,model_estate_property_offer,estate_group_user,1,1,1,0 +access_property_type_agent,access_estate_property_type_agent,model_estate_property_type,estate_group_user,1,0,0,0 +access_property_tag_agent,access_estate_property_tag_agent,model_estate_property_tag,estate_group_user,1,0,0,0 diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..d89042277e9 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,26 @@ + + + + Agent + Real estate agents can manage the properties under their care, or properties which are not specifically under the care of any agent. + + + + + Manager + Real estate managers can configure the system (manage available types and tags) as well as oversee every property in the pipeline. + + + + + + company: see or modify properties of my company only + + + + + + + [('company_id', '=', user.company_id.id)] + + diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..1e949c2c345 --- /dev/null +++ b/estate/tests/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_estate_property diff --git a/estate/tests/test_estate_property.py b/estate/tests/test_estate_property.py new file mode 100644 index 00000000000..3d77d166147 --- /dev/null +++ b/estate/tests/test_estate_property.py @@ -0,0 +1,85 @@ +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError +from odoo.tests import Form + + +class EstatePropertyTestCase(TransactionCase): + @classmethod + def setUpClass(cls): + return super().setUpClass() + + def test_offer_creation_on_sold_property(self): + property = self.env["estate.property"].create( + { + "name": "Test case Property", + "expected_price": "123", + } + ) + + self.env["estate.property.offer"].create( + { + "price": 1500.00, + "partner_id": self.env.ref("base.res_partner_1").id, + "date_deadline": "2025-09-14", + "property_id": property.id, + "status": "accepted", + } + ) + + property.action_sold() + + with self.assertRaises( + UserError, msg="Cannot create an offer for a sold property" + ): + self.env["estate.property.offer"].create( + { + "price": 1500.00, + "partner_id": self.env.ref("base.res_partner_1").id, + "date_deadline": "2025-09-14", + "property_id": property.id, + } + ) + + def test_sell_property_on_accepted_offer(self): + property = self.env["estate.property"].create( + { + "name": "Test case Property 2", + "expected_price": "456", + } + ) + + self.env["estate.property.offer"].create( + { + "price": 1500.00, + "partner_id": self.env.ref("base.res_partner_1").id, + "date_deadline": "2025-09-14", + "property_id": property.id, + } + ) + with self.assertRaises(UserError): + property.action_sold() + + def test_reset_garden_area_and_orientation(self): + property = self.env["estate.property"].create( + { + "name": "Garden Test Property", + "expected_price": "789", + "garden": True, + "garden_area": 50, + "garden_orientation": "north", + } + ) + + with Form(property) as form: + form.garden = False + form.save() + + self.assertFalse(property.garden, "Garden checkbox should be unchecked.") + self.assertFalse( + property.garden_area, + "Garden area should be reset when the garden checkbox is unchecked.", + ) + self.assertFalse( + property.garden_orientation, + "Orientation should be reset when the garden checkbox is unchecked.", + ) diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..06fe08a9720 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml new file mode 100644 index 00000000000..50aadd35e5c --- /dev/null +++ b/estate/views/estate_property_tag_views.xml @@ -0,0 +1,28 @@ + + + + Property Tags + estate.property.tag + list,form + + + + estate.property.tag.list + estate.property.tag + + + + + + + + + estate.property.tag.search + estate.property.tag + + + + + + + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..ceb8df2f1f3 --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,84 @@ + + + + Property Types + estate.property.type + list,form + + + + Offers + estate.property.offer + list,form + [('property_id.property_type_id', '=', active_id)] + + + + estate.property.type + estate.property.type + + + + + + + + + + estate.property.type.form + estate.property.type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.type.search + estate.property.type + + + + + + + + + estate.property.offer.tree + estate.property.offer + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..d498ecdc788 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,173 @@ + + + + Properties + estate.property + list,form,kanban + {'search_default_state': 1} + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + + + + + + + + + + + Expected Price: + + + Best Price: + + + Selling Price: + + + + + + + + + + estate.property.form + estate.property + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..05af134cd5c --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,34 @@ + + + + res.users.form.inherit.properties + res.users + + + + + + + + + + + + + + + + + + + + + + + + + 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..56ece2e724c --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,10 @@ +{ + 'name': 'Estate Account', + 'depends': ['estate', 'account'], + 'data': [ + 'security/ir.model.access.csv', + ], + 'installable': True, + 'application': True, + 'license': 'LGPL-3', +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..09b94f90f8d --- /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 diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..90f893dcbf2 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,29 @@ +from odoo import models +from odoo.fields import Command + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sold(self): + for property in self: + property.check_access("write") + + self.env["account.move"].sudo().create({ + "partner_id": property.buyer_id.id, + "move_type": "out_invoice", + "invoice_line_ids": [ + Command.create({ + "name": "6% Commission", + "quantity": 1, + "price_unit": property.selling_price * 0.06, + }), + Command.create({ + "name": "Administrative Fees", + "quantity": 1, + "price_unit": 100.00, + }), + ], + }) + + return super().action_sold() diff --git a/estate_account/security/ir.model.access.csv b/estate_account/security/ir.model.access.csv new file mode 100644 index 00000000000..d9d6ba57cc5 --- /dev/null +++ b/estate_account/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1
+ +
Counter:
The Sum is:
This is the content of Card 1.
No offers available for this property.