diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..59d70791d98 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,7 +24,11 @@ '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' } 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..c612176e649 --- /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.statisticsService = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); + this.display = { + controlPanel: {}, + }; + 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; + } + + openCustomerView() { + 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"], + ], + 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..6ecef78b54a --- /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..cd3d1592f71 --- /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..4644048af21 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.js @@ -0,0 +1,18 @@ +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..33e1fd98752 --- /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..9d6236be7d9 --- /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 items = [ + { + id: "average_quantity", + description: "Average amount of t-shirt", + Component: NumberCard, + props: (data) => ({ + title: "Average amount of t-shirt by order this month", + value: data.average_quantity, + }) + }, + { + id: "average_time", + description: "Average 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, + }) + } +] +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..0de2c3f98b4 --- /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..3a0713623fa --- /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..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..58a6811c83a --- /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_service.js b/awesome_dashboard/static/src/dashboard/statistics_service.js new file mode 100644 index 00000000000..1049e290756 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,18 @@ +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 }); + } + setInterval(loadData, 10 * 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..2c43f9ee72a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,9 @@ +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/__manifest__.py b/awesome_owl/__manifest__.py index 77abad510ef..d973a9d293b 100644 --- a/awesome_owl/__manifest__.py +++ b/awesome_owl/__manifest__.py @@ -27,6 +27,13 @@ 'views/templates.xml', ], 'assets': { + 'web.assets_qweb': [ + 'awesome_owl/static/src/counter/counter.xml', + 'awesome_owl/static/src/card/card.xml', + 'awesome_owl/static/src/todo/todo_list.xml', + 'awesome_owl/static/src/todo/todo_item.xml' + 'awesome_owl/static/src/playground.xml', + ], 'awesome_owl.assets_playground': [ ('include', 'web._assets_helpers'), 'web/static/src/scss/pre_variables.scss', diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..cdf30444260 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,17 @@ +import { Component,useState } from "@odoo/owl"; + +export class Card extends Component{ + static template = "awesome_owl.card"; + static props = { + title: String, + slots:{} + }; + setup() { + this.state = useState({ + isOpen: true, + }); + } + toggleOpen() { + 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..23fd7eb472e --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,20 @@ + + + +
+
+
+ +
+ +
+ +
+ +
+
+
+
+
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..0ccc7b6a65b --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,17 @@ +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..0ac1af29985 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,12 @@ + + + +
+

Counter:

+ +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..61ada9f1976 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 "./counter/counter"; +import { Card } from "./card/card"; +import { TodoList } from "./todo/todo_list"; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + static props = {}; + setup() { + this.state = useState({ + sum: 2, + }); + + this.counterValues = [1, 1]; + + (this.str1 = markup("
some content
")), + (this.str2 = "some content"); + } + updateCounterValue(index, newValue) { + this.counterValues[index] = newValue; + this.state.sum = this.counterValues.reduce((a, b) => a + b, 0); + } + + onChange1 = (val) => this.updateCounterValue(0, val); + onChange2 = (val) => this.updateCounterValue(1, val); } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..b428403d631 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,25 @@ - + + +
+ + +
+
+

Total Sum:

+
+
+ +
some content
+
- -
- hello world -
-
+ + + +
+
+ +
+
diff --git a/awesome_owl/static/src/todo/todo_item.js b/awesome_owl/static/src/todo/todo_item.js new file mode 100644 index 00000000000..05bf4894533 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,24 @@ +/** @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, + }; + onToggle() { + this.props.toggleState(this.props.todo.id); + } + onDelete(){ + this.props.removeTodo(this.props.todo.id); + } +} diff --git a/awesome_owl/static/src/todo/todo_item.xml b/awesome_owl/static/src/todo/todo_item.xml new file mode 100644 index 00000000000..67f3f8820db --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,17 @@ + + + +
+ +
+ + . + +
+ + + + +
+
+
diff --git a/awesome_owl/static/src/todo/todo_list.js b/awesome_owl/static/src/todo/todo_list.js new file mode 100644 index 00000000000..a6a2e19e75c --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,45 @@ +/** @odoo-module **/ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item"; + +let nextId = 0; +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + static props = {}; + + setup() { + this.todos = useState([]); + this.inputRefValue = useState({ value: "" }); + this.toggleState = this.toggleState.bind(this) + this.removeTodo = this.removeTodo.bind(this) + } + + addTodo(ev) { + if (ev.keyCode === 13) { + const desc = this.inputRefValue.value.trim(); + if (!desc) return; + + this.todos.push({ + id: nextId++, + description: desc, + isCompleted: false, + }); + + this.inputRefValue.value = ""; + } + } + toggleState(id) { + const todo = this.todos.find((todo) => todo.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(id) { + const index = this.todos.findIndex((todo) => todo.id === id); + if (index >= 0) { + this.todos.splice(index, 1); + } +} +} diff --git a/awesome_owl/static/src/todo/todo_list.xml b/awesome_owl/static/src/todo/todo_list.xml new file mode 100644 index 00000000000..f5f035befbc --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,12 @@ + + + +
+ + + + +
+
+
diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..ac6688ea06d --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1,2 @@ +# license: LGPL-3 +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..2e3a8f103ee --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Estate Account', + 'version': '1.0', + 'sequence': 2, + 'depends': ['base', 'real_estate', 'account'], + 'category': 'Real Estate', + 'author': 'prbo', + 'summary': 'Invoice integration with Real Estate', + 'description': 'Creates an invoice when a property is sold.', + 'license': 'LGPL-3', + 'data': [], + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..5e1963c9d2f --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +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..9cf52525c88 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,42 @@ +from odoo import Command, models +from odoo.exceptions import UserError + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + self.check_access('write') + journal = self.env['account.journal'].sudo().search([ + ('type', '=', 'sale'), + ], limit=1) + + if not journal: + raise UserError("No sales journal found!") + + for property in self: + if not property.buyer: + raise UserError("Buyer is required to create invoice.") + + selling_price = property.selling_price + service_fee = selling_price * 0.06 + + invoice_vals = { + 'partner_id': property.buyer.id, + 'move_type': 'out_invoice', + 'journal_id': journal.id, + 'invoice_line_ids': [ + Command.create({ + 'name': "Service Fees (6%)", + 'quantity': 1, + 'price_unit': service_fee, + }), + Command.create({ + 'name': "Administrative Fees", + 'quantity': 1, + 'price_unit': 100.00, + }), + ], + } + self.env['account.move'].sudo().create(invoice_vals) + return super().action_sold() diff --git a/real_estate/__init__.py b/real_estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/real_estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/real_estate/__manifest__.py b/real_estate/__manifest__.py new file mode 100644 index 00000000000..73a687eab70 --- /dev/null +++ b/real_estate/__manifest__.py @@ -0,0 +1,27 @@ +{ + 'name': "Real Estate", + 'version': '1.0', + 'author': "prbo", + 'license': 'LGPL-3', + 'category': 'Real Estate/Brokerage', + 'sequence': 1, + 'application': True, + 'depends': ['base'], + 'data': [ + 'security/estate_security.xml', + 'security/ir.model.access.csv', + 'security/estate_property_rules.xml', + 'data/estate.property.type.csv', + 'views/estate_property_offer_view.xml', + 'views/estate_property_type_view.xml', + 'views/estate_property_views.xml', + 'views/estate_property_tag_view.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + 'report/estate_property_templates.xml', + 'report/estate_property_reports.xml', + ], + 'demo': [ + 'demo/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/demo_data.xml b/real_estate/demo/demo_data.xml new file mode 100644 index 00000000000..19106223ea8 --- /dev/null +++ b/real_estate/demo/demo_data.xml @@ -0,0 +1,92 @@ + + + Big Villa + A nice and big villa + 97000 + 97000 + 6 + 100 + 4 + True + True + 100000 + south + 12345 + 2020-02-02 + new + + + + Trailer home + Home in a trailer park + 1000 + 1000 + 1 + 10 + 4 + False + False + 54321 + 1970-01-01 + cancelled + + + + + + 98000 + 14 + + + + + + 1500000 + 14 + + + + + + 1500001 + 14 + + + + + + + + + + + + + Modern Apartment + 100000 + Stylish and modern 2BHK in the city center. + 2024-06-10 + 12345 + 99000 + new + 2 + 950 + 2 + + + 200 + + + + diff --git a/real_estate/models/__init__.py b/real_estate/models/__init__.py new file mode 100644 index 00000000000..4c3251e0f97 --- /dev/null +++ b/real_estate/models/__init__.py @@ -0,0 +1,6 @@ +# license: LGPL-3 +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/real_estate/models/estate_property.py b/real_estate/models/estate_property.py new file mode 100644 index 00000000000..29aadf347dd --- /dev/null +++ b/real_estate/models/estate_property.py @@ -0,0 +1,116 @@ +from datetime import date, timedelta +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_compare + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Test Model" + _order = "id desc" + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date( + string="Available From", + copy=False, + default=lambda self: date.today() + timedelta(days=90) + ) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + best_price = fields.Float(compute="_compute_best_price") + bedrooms = fields.Integer(string="Bedrooms", default=2) + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + living_area = fields.Float(string="Living Area (m²)") + garden_area = fields.Float(string="Garden Area (m²)") + total_area = fields.Float(compute="_compute_total_area") + garden_orientation = fields.Selection( + string='Garden Orientation', + selection=[ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West') + ], + help="Direction of the garden" + ) + active = fields.Boolean(default=True) + state = fields.Selection( + selection=[ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled') + ], + required=True, + copy=False, + default='new' + ) + 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") + _sql_constraints = [ + ('check_expected_price_positive', 'CHECK(expected_price > 0)', 'Expected price must be strictly positive.'), + ('check_selling_price_positive', 'CHECK(selling_price >= 0)', 'Selling price must be zero or positive.') + ] + 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: + record.best_price = max(record.offer_ids.mapped("price"), default=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): + self.check_access('write') + for record in self: + if record.state == 'cancelled': + raise UserError("Cancelled properties cannot be sold.") + if record.state == 'sold': + raise UserError("The property is already sold.") + if not record.offer_ids.filtered(lambda o: o.status == 'accepted'): + raise UserError("You cannot sell a property without an accepted offer.") + record.state = 'sold' + + def action_cancel(self): + for record in self: + if record.state in ['sold', 'cancelled']: + raise UserError("You cannot cancel a sold or already cancelled property.") + record.state = 'cancelled' + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price_margin(self): + for record in self: + if float_compare(record.selling_price, 0.0, precision_digits=2) > 0: + min_acceptable_price = 0.9 * record.expected_price + if float_compare(record.selling_price, min_acceptable_price, precision_digits=2) < 0: + raise ValidationError("Selling price cannot be lower than 90% of the expected price.") + + @api.ondelete(at_uninstall=False) + def _check_property_state_on_delete(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("Only properties with state 'New' or 'Cancelled' can be deleted.") diff --git a/real_estate/models/estate_property_offer.py b/real_estate/models/estate_property_offer.py new file mode 100644 index 00000000000..bc7d427dadd --- /dev/null +++ b/real_estate/models/estate_property_offer.py @@ -0,0 +1,79 @@ +from datetime import timedelta +from odoo import api, models, fields +from odoo.exceptions import UserError, ValidationError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Property Offer" + _order = "price desc" + price = fields.Float(required=True) + status = fields.Selection([ + ('accepted', 'Accepted'), + ('refused', 'Refused') + ]) + partner_id = fields.Many2one("res.partner", string="Partner", required=True) + property_id = fields.Many2one( + "estate.property", + required=True, + ondelete='cascade' + ) + property_type_id = fields.Many2one( + related="property_id.property_type", + store=True, + string="Property Type" + ) + validity = fields.Integer(string="Validity (days)", default=7) + date_deadline = fields.Date(string="Deadline Date", compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + _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: + 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.date() if record.create_date else fields.Date.today() + record.validity = (record.date_deadline - create_date).days + + def action_accept(self): + for record in self: + if record.property_id.state == 'sold': + raise UserError("You cannot accept an offer on a sold property.") + record.status = 'accepted' + record.property_id.selling_price = record.price + record.property_id.buyer = record.partner_id + record.property_id.state = 'offer_accepted' + other_offers = self.search([ + ('property_id', '=', record.property_id.id), + ('id', '!=', record.id) + ]) + other_offers.write({'status': 'refused'}) + + def action_refuse(self): + for offer in self: + offer.status = 'refused' + return True + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + price = vals.get('price') + property_id = vals.get('property_id') + if not property_id: + raise ValidationError("Property ID must be provided.") + property_obj = self.env['estate.property'].browse(property_id) + + if property_obj.state == 'sold': + raise UserError("Cannot create offer for a sold property.") + existing_offers = property_obj.offer_ids.filtered( + lambda o: o.price is not None and price is not None and o.price >= price + ) + if existing_offers: + raise ValidationError("You cannot create an offer with a lower or equal price than existing offers.") + property_obj.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..dc2107a6bfe --- /dev/null +++ b/real_estate/models/estate_property_tag.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Property Tag" + _order = "name" + name = fields.Char(required=True) + color = fields.Integer(string="Color") + sequence = fields.Integer(string="sequence", default="10") + _sql_constraints = [ + ('unique_tag_name', 'UNIQUE(name)', 'Tag name must be unique.') + ] diff --git a/real_estate/models/estate_property_type.py b/real_estate/models/estate_property_type.py new file mode 100644 index 00000000000..3f7aaf7b55e --- /dev/null +++ b/real_estate/models/estate_property_type.py @@ -0,0 +1,31 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Property Type" + _order = "sequence, name" + name = fields.Char(string="Property Type", required=True) + sequence = fields.Integer(string="Sequence of property", default=10) + _sql_constraints = [ + ('unique_type_name', 'UNIQUE(name)', 'Property type name must be unique.') + ] + offer_ids = fields.One2many( + 'estate.property.offer', + 'property_type_id', + string="Offers" + ) + offer_count = fields.Integer( + string="Offer Count", + compute="_compute_offer_count" + ) + property_ids = fields.One2many( + "estate.property", + "property_type", + string="Properties" + ) + + @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..8df73bb6647 --- /dev/null +++ b/real_estate/models/res_users.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class ResUsers(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_reports.xml b/real_estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..9db20163eda --- /dev/null +++ b/real_estate/report/estate_property_reports.xml @@ -0,0 +1,21 @@ + + + + Print Offers + estate.property + qweb-pdf + real_estate.report_property_offers + real_estate.report_property_offers + 'Property Offers - %s' % (object.name).replace('/', '') + + + + Salesman Property Offers + res.users + + qweb-pdf + real_estate.report_property_user_offers + real_estate.report_property_user_offers + 'Salesman Properties - %s' % object.name + + diff --git a/real_estate/report/estate_property_templates.xml b/real_estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..19ec94ba324 --- /dev/null +++ b/real_estate/report/estate_property_templates.xml @@ -0,0 +1,107 @@ + + + + + + + diff --git a/real_estate/security/estate_property_rules.xml b/real_estate/security/estate_property_rules.xml new file mode 100644 index 00000000000..b46c8c4b32b --- /dev/null +++ b/real_estate/security/estate_property_rules.xml @@ -0,0 +1,34 @@ + + + Agents: Own or Unassigned Properties Only + + + [ + '|', + ('seller', '=', user.id), + ('seller', '=', False) + ] + + + + + + + Managers: Full Access to Properties + + + [(1, '=', 1)] + + + + + + + Estate Property: Multi-Company Access + + [ + ('company_id', 'in', company_ids) + ] + + + diff --git a/real_estate/security/estate_security.xml b/real_estate/security/estate_security.xml new file mode 100644 index 00000000000..2f2912e7208 --- /dev/null +++ b/real_estate/security/estate_security.xml @@ -0,0 +1,11 @@ + + + Agent + + + + Manager + + + + diff --git a/real_estate/security/ir.model.access.csv b/real_estate/security/ir.model.access.csv new file mode 100644 index 00000000000..7c78fb5c401 --- /dev/null +++ b/real_estate/security/ir.model.access.csv @@ -0,0 +1,12 @@ +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,1 +access_estate_property_agent,access_estate_property_agent,model_estate_property,estate_group_user,1,0,0,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_type_agent,access.estate.property.type.agent,model_estate_property_type,estate_group_user,1,0,0,0 + +access_estate_property_tag_manager,access.estate.property.tag.manager,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_property_tag_agent,access.estate.property.tag.agent,model_estate_property_tag,estate_group_user,1,0,0,0 + +access_estate_property_offer_manager,access.estate.property.offer.manager,model_estate_property_offer,estate_group_manager,1,1,1,1 +access_estate_property_offer_agent,access.estate.property.offer.agent,model_estate_property_offer,estate_group_user,1,1,1,1 diff --git a/real_estate/tests/__init__.py b/real_estate/tests/__init__.py new file mode 100644 index 00000000000..01614a9991f --- /dev/null +++ b/real_estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_estate_offer diff --git a/real_estate/tests/test_estate_offer.py b/real_estate/tests/test_estate_offer.py new file mode 100644 index 00000000000..31be3aa5459 --- /dev/null +++ b/real_estate/tests/test_estate_offer.py @@ -0,0 +1,63 @@ +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_sold() + + def test_can_sell_property_with_accepted_offer(self): + self.offer.action_accept() + self.property.action_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..f2ad52b5efe --- /dev/null +++ b/real_estate/views/estate_menus.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/real_estate/views/estate_property_offer_view.xml b/real_estate/views/estate_property_offer_view.xml new file mode 100644 index 00000000000..5c4867ddc3d --- /dev/null +++ b/real_estate/views/estate_property_offer_view.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_tag_view.xml b/real_estate/views/estate_property_tag_view.xml new file mode 100644 index 00000000000..9b492ade771 --- /dev/null +++ b/real_estate/views/estate_property_tag_view.xml @@ -0,0 +1,28 @@ + + + + estate.property.tag.list + estate.property.tag + + + + + + + + + + estate.property.tag.form + estate.property.tag + +
+ + +
+
+ + Property Tags + estate.property.tag + list,form + +
diff --git a/real_estate/views/estate_property_type_view.xml b/real_estate/views/estate_property_type_view.xml new file mode 100644 index 00000000000..72cabb57535 --- /dev/null +++ b/real_estate/views/estate_property_type_view.xml @@ -0,0 +1,50 @@ + + + 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..4919d351c27 --- /dev/null +++ b/real_estate/views/estate_property_views.xml @@ -0,0 +1,135 @@ + + + + Properties + estate.property + list,form + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ +

+ +

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