diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..7752920121b 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -22,6 +22,9 @@ 'views/views.xml', ], 'assets': { + "awesome_dashboard.dashboard_assets": [ + "awesome_dashboard/static/src/dashboard/**/*", + ], 'web.assets_backend': [ 'awesome_dashboard/static/src/**/*', ], 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/DashboardItem/dashboard_item.js b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.js new file mode 100644 index 00000000000..dae993bf51c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.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/dashboard_item.scss b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.scss new file mode 100644 index 00000000000..e3a09884986 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.scss @@ -0,0 +1,8 @@ +.dashboard-item { + margin: 0.5rem; + padding: 1rem; + background: white; + border: 1px solid #ccc; + border-radius: 0.5rem; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} diff --git a/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.xml new file mode 100644 index 00000000000..12fdab82f20 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/DashboardItem/dashboard_item.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard/NumberCard/number_card.js b/awesome_dashboard/static/src/dashboard/NumberCard/number_card.js new file mode 100644 index 00000000000..8acfe1a0246 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/NumberCard/number_card.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; // Match template name in XML + static props = { + title: { type: String }, + value: { type: Number }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/NumberCard/number_card.xml b/awesome_dashboard/static/src/dashboard/NumberCard/number_card.xml new file mode 100644 index 00000000000..44c18028459 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/NumberCard/number_card.xml @@ -0,0 +1,13 @@ + + + +
+

+ +

+
+ +
+
+
+
diff --git a/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.js b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.js new file mode 100644 index 00000000000..09ca03018ed --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.js @@ -0,0 +1,64 @@ +/** @odoo-module **/ + +import { Component, onWillStart, onMounted, useRef } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef("canvas"); + + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js"); + }); + + onMounted(() => { + if (!this.props.data || Object.keys(this.props.data).length === 0) { + console.warn("PieChart: No data provided for chart."); + console.log(this.props.data); + return; + } + + const ctx = this.canvasRef.el.getContext("2d"); + + const data = { + labels: Object.keys(this.props.data), + datasets: [ + { + label: "Shirt Sizes", + data: Object.values(this.props.data), + backgroundColor: [ + "#3498db", + "#e67e22", + "#2ecc71", + "#9b59b6", + "#95a5a6", + ], + }, + ], + }; + + new window.Chart(ctx, { + type: "pie", + data, + options: { + responsive: true, + plugins: { + legend: { + position: "top", + }, + title: { + display: true, + text: "Shirt orders by size", + }, + }, + }, + }); + }); + } +} diff --git a/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.xml b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.xml new file mode 100644 index 00000000000..6ce336c0476 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/PieChart/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart_card.xml new file mode 100644 index 00000000000..58a6811c83a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/PieChart/piechart_card.js b/awesome_dashboard/static/src/dashboard/PieChart/piechart_card.js new file mode 100644 index 00000000000..59fea5ea47a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/PieChart/piechart_card.js @@ -0,0 +1,17 @@ +/** @odoo-module */ + +import { Component } from "@odoo/owl"; +import { PieChart } from "./pie_chart.js"; + +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/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..89cae9d7b66 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,92 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; +import { Layout } from "@web/search/layout"; +import { registry } from "@web/core/registry"; +import { DashboardItem } from "./DashboardItem/dashboard_item.js"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; + +export class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem }; + + setup() { + this.items = registry.category("awesome_dashboard").getAll(); + this.action = useService("action"); + this.display = { + controlPanel: {}, + }; + + const statisticsService = useService("awesome_dashboard.statistics"); + this.stats = useState(statisticsService.getStatistics()); + 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), + }); + } + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } + openCustomers() { + this.action.doAction("base.action_partner_form"); + } + + 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..9eba3db19e7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + +
+ + + + + + +
+
+
+ + + Which cards do you whish to see ? + + + + + + + + + + +
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..6155259521a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,68 @@ +/** @odoo-module */ + +import { NumberCard } from "./NumberCard/number_card.js"; +import { PieChartCard } from "./PieChart/piechart_card.js"; +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_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..0112909e2a5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,13 @@ +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; +import { Component, xml } from "@odoo/owl"; + +class AwesomeDashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; +} +registry + .category("actions") + .add("awesome_dashboard.dashboard", AwesomeDashboardLoader); diff --git a/awesome_dashboard/static/src/statistic_service.js b/awesome_dashboard/static/src/statistic_service.js new file mode 100644 index 00000000000..15e5618f3cd --- /dev/null +++ b/awesome_dashboard/static/src/statistic_service.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +async function fetchStatistics() { + return await rpc("/awesome_dashboard/statistics", {}); +} + +export const statisticsService = { + dependencies: [], + start() { + const stats = reactive({}); + + async function loadAndUpdateStatistics() { + const newStats = await fetchStatistics(); + Object.assign(stats, newStats); + } + loadAndUpdateStatistics(); + + setInterval(() => { + loadAndUpdateStatistics(); + }, 10000); + + return { + getStatistics: () => stats, + }; + }, +}; + +registry + .category("services") + .add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_owl/static/src/Card/card.js b/awesome_owl/static/src/Card/card.js new file mode 100644 index 00000000000..85a460ed2d6 --- /dev/null +++ b/awesome_owl/static/src/Card/card.js @@ -0,0 +1,17 @@ +/** @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..4f7983d2c26 --- /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..63e5b5b51a5 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,19 @@ +/** @odoo-module */ + +import { Component, useState } from "@odoo/owl"; + +export class Counter extends Component { + static template = "awesome_owl.Counter"; + static props = { + onChange: { type: Function, optional: true }, + }; + setup() { + this.state = useState({ value: 0 }); + } + 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..c9843280484 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + +
+ Counter: + + +
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..06eb21674ea 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,26 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, markup, useState } from "@odoo/owl"; +import { Counter } from "./counter/counter.js"; +import { Card } from "./Card/card.js"; +import { TodoList } from "./todo/todo_list.js"; +const html = "
some content
"; 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.incrementSum = (newValue) => { + this.state.sum++; + }; + this.card1 = { + title: "card 1", + content: markup(html), + }; + this.card2 = { + title: "card 2", + content: markup("another content"), + }; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..4da1885a7f4 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,23 @@ - -
- hello world +
+ hello world +
+ + +
+

The sum is: +

+ +

hello

+
+ + + +
+
+
- 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..0944866982c --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.js @@ -0,0 +1,18 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static props = { + todo: Object, + toggleState: Function, + removeTodo: Function, + }; + toggleTodo(ev) { + this.props.toggleState(this.props.todo.id); + } + deleteTodo() { + this.props.removeTodo(this.props.todo.id); + } +} +TodoItem.template = "awesome_owl.TodoItem"; 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..4cc59f45422 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item.xml @@ -0,0 +1,12 @@ + + + +
  • + + +: + + +
  • +
    +
    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..3160fafbfd5 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.js @@ -0,0 +1,42 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "./todo_item.js"; + +let nextId = 0; +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.todos = useState([]); + this.inputRef = useState({ value: "" }); + } + + toggleState = (id) => { + const todo = this.todos.find((t) => t.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + }; + removeTodo = (id) => { + const index = this.todos.findIndex((t) => t.id === id); + if (index >= 0) { + this.todos.splice(index, 1); + } + }; + addTodo(ev) { + if (ev.keyCode === 13) { + const desc = this.inputRef.value.trim(); + if (!desc) return; + + this.todos.push({ + id: nextId++, + description: desc, + isCompleted: false, + }); + + this.inputRef.value = ""; + } + } +} 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..aff8489fa77 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list.xml @@ -0,0 +1,14 @@ + + + +
    +

    My Todo List

    +
    + + + + +
    +
    +
    +
    diff --git a/awesome_owl/utils.js b/awesome_owl/utils.js new file mode 100644 index 00000000000..664e9bb3a9e --- /dev/null +++ b/awesome_owl/utils.js @@ -0,0 +1,9 @@ +import { onMounted } from "@odoo/owl"; + +export function useAutofocus(ref) { + onMounted(() => { + if (ref.el) { + ref.el.focus(); + } + }); +} diff --git a/estate_account/__init__.py b/estate_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..8a9983d2198 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,9 @@ +{ + 'name': 'Estate Accounting', + 'version': '1.0', + 'depends': ['real_estate', 'account'], + 'category': 'Real Estate', + 'license': 'LGPL-3', + 'installable': True, + 'application': 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..aae8386df01 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,43 @@ +from odoo import Command, models +from odoo.exceptions import UserError + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_sold(self): + res = super().action_sold() + self.check_access('write') + + journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1) + if not journal: + raise UserError("No sale journal found. Please configure at least one sale journal.") + + for record in self: + if not record.buyer_id: + raise UserError("Please set a Buyer before generating an invoice.") + if not record.selling_price: + raise UserError("Please set a Selling Price before generating an invoice.") + + journal = self.env['account.journal'].sudo().search([('type', '=', 'sale')], limit=1) + if not journal: + raise UserError("No sale journal found. Please configure at least one sale journal.") + invoice_vals = { + "partner_id": record.buyer_id.id, + "move_type": "out_invoice", + "journal_id": journal.id, + "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) + return res 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..1d8142d4a3d --- /dev/null +++ b/real_estate/__manifest__.py @@ -0,0 +1,30 @@ +{ + 'name': 'estate', + 'version': '1.0.0', + 'author': 'rodh', + 'summary': 'Manage real estate properties and transactions', + 'depends': [ + 'base', + ], + 'application': True, + 'installable': True, + 'license': 'LGPL-3', + 'category': 'Real Estate/Brokerage', + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + 'security/record_rules.xml', + 'view/estate_property_views.xml', + 'view/estate_property_offer_views.xml', + 'view/estate_property_type_views.xml', + 'view/estate_property_tag_views.xml', + 'view/estate_res_users_view.xml', + 'data/estate.property.type.csv', + 'view/estate_menu.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..a5c7fea920b --- /dev/null +++ b/real_estate/demo/demo_data.xml @@ -0,0 +1,85 @@ + + + + Big Villa + new + A nice and big villa + a + 2020-02-02 + 16000.0 + 15900.0 + 6 + 100.0 + 4 + + + 100000.0 + south + + + + Trailer home + new + Home in a trailer park + a + 1970-01-01 + 10000.0 + 15000.0 + 2 + 10.0 + 4 + + + + + + + 15800.00 + 14 + + + + + + 16800.00 + 14 + + + + + + 17800.00 + 14 + + + + + + + + + + + Modern Apartment + a + new + 900000.0 + 920000.0 + 85.0 + 3 + + + diff --git a/real_estate/models/__init__.py b/real_estate/models/__init__.py new file mode 100644 index 00000000000..06001dca391 --- /dev/null +++ b/real_estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import estate_property +from . import estate_property_type +from . import estate_property_tag +from . import estate_property_offer +from . import estate_res_users diff --git a/real_estate/models/estate_property.py b/real_estate/models/estate_property.py new file mode 100644 index 00000000000..977f4bd65d0 --- /dev/null +++ b/real_estate/models/estate_property.py @@ -0,0 +1,113 @@ +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, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + _order = "id desc" + + name = fields.Char(default="Unknown", required=True) + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + availability_date = fields.Date(default=lambda self: date.today() + timedelta(days=90), copy=False) + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(readonly=True, copy=False) + _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.') +] + bedrooms = fields.Integer(default=2) + living_area = fields.Float(string="Living Area") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Float(string="Garden Area") + total_area = fields.Float(string="Total Area", compute="_compute_total_area") + garden_orientation = fields.Selection( + [ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West') + ], + string="Garden Orientation" + ) + active = fields.Boolean(default=False) + 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_id = fields.Many2one('estate.property.type', string="Property Type") + buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False) + salesperson_id = 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") + best_price = fields.Float(string="Best Offer", compute="_compute_best_price") + company_id = fields.Many2one( + 'res.company', + string='Company', + default=lambda self: self.env.company + ) + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if (float_is_zero(record.selling_price, precision_digits=2) + or record.state not in ['offer_accepted', 'sold']): + continue + 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.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = (record.living_area or 0.0) + (record.garden_area or 0.0) + + @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 + + @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' + return True + + def action_sold(self): + for record in self: + if not any(offer.state == 'accepted' for offer in record.offer_ids): + raise UserError("You cannot sell a property without an accepted offer.") + if record.state == 'cancelled': + raise UserError("Cancelled properties cannot be sold.") + record.state = 'sold' + return True + + @api.ondelete(at_uninstall=False) + def _check_deletion(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError("You can only delete a property if its state is 'New' or 'Cancelled'.") diff --git a/real_estate/models/estate_property_offer.py b/real_estate/models/estate_property_offer.py new file mode 100644 index 00000000000..0dbc4a6c12a --- /dev/null +++ b/real_estate/models/estate_property_offer.py @@ -0,0 +1,72 @@ +from datetime import timedelta +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Property Offer" + _order = "price desc" + + price = fields.Float(string="Offer Price") + state = fields.Selection([ + ('new', 'New'), + ('accepted', 'Accepted'), + ('refused', 'Refused') + ], string="State", default='new', required=True) + _sql_constraints = [ + ('check_price', 'CHECK(price > 0)', 'The offer price must be strictly positive.'), +] + partner_id = fields.Many2one('res.partner', string="Partner", required=True) + property_id = fields.Many2one('estate.property', string="Property", required=True) + property_type_id = fields.Many2one( + 'estate.property.type', + related="property_id.property_type_id", + store=True, + readonly=True + ) + validity = fields.Integer(default=7) + date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", store=True) + + @api.depends('create_date', 'validity') + 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() + delta = record.date_deadline - create_date.date() + record.validity = delta.days + + def action_accept(self): + for offer in self: + if offer.property_id.buyer_id: + raise UserError("An offer has already been accepted.") + offer.state = 'accepted' + offer.property_id.write({ + 'selling_price': offer.price, + 'buyer_id': offer.partner_id.id, + 'state': 'offer_accepted' + }) + return True + + def action_refuse(self): + for offer in self: + offer.state = 'refused' + return True + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + price = vals.get('price') + property_obj = self.env['estate.property'].browse(vals.get('property_id')) + existing_offers = property_obj.offer_ids.filtered(lambda o: o.price is not None and price is not None and o.price >= price) + if property_obj.state == 'sold': + raise UserError("Cannot create offer for a sold property.") + 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..6d526f66bbf --- /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(string="Name", required=True) + color = fields.Integer('Color') + _sql_constraints = [ + ('unique_tag_name', 'UNIQUE(name)', 'A property 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..eec16f17f20 --- /dev/null +++ b/real_estate/models/estate_property_type.py @@ -0,0 +1,28 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Property Type' + _order = "sequence, name" + + name = fields.Char(required=True) + _sql_constraints = [ + ('unique_property_type', 'UNIQUE(name)', 'A property type name must be unique') +] + property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") + sequence = fields.Integer(string="Sequence", default=10) + offer_ids = fields.One2many( + "estate.property.offer", + "property_type_id", + string="Offers" + ) + offer_count = fields.Integer( + string="Offers Count", + compute="_compute_offer_count" + ) + + @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/estate_res_users.py b/real_estate/models/estate_res_users.py new file mode 100644 index 00000000000..c376d77a343 --- /dev/null +++ b/real_estate/models/estate_res_users.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', + 'salesperson_id', + 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..307b2835a50 --- /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('/', '') + + + + 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/report/estate_property_templates.xml b/real_estate/report/estate_property_templates.xml new file mode 100644 index 00000000000..8e60997bbb6 --- /dev/null +++ b/real_estate/report/estate_property_templates.xml @@ -0,0 +1,108 @@ + + + + + + + diff --git a/real_estate/security/ir.model.access.csv b/real_estate/security/ir.model.access.csv new file mode 100644 index 00000000000..0bc494ff4e5 --- /dev/null +++ b/real_estate/security/ir.model.access.csv @@ -0,0 +1,13 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1 +access_estate_offer_user,access_estate_offer_user,model_estate_property_offer,base.group_user,1,1,1,1 + +access_estate_property_manager,access.estate.property.manager,model_estate_property,estate_group_manager,1,1,1,0 +access_estate_type_manager,access.estate.type.manager,model_estate_property_type,estate_group_manager,1,1,1,1 +access_estate_tag_manager,access.estate.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_agent,access.estate.property.agent,model_estate_property,estate_group_user,1,1,1,0 +access_estate_type_agent,access.estate.type.agent,model_estate_property_type,estate_group_user,1,1,0,0 +access_estate_tag_agent,access.estate.tag.agent,model_estate_property_tag,estate_group_user,1,0,0,0 +access_estate_offer_agent,access.estate.offer.agent,model_estate_property_offer,estate_group_user,1,1,1,0 \ No newline at end of file diff --git a/real_estate/security/record_rules.xml b/real_estate/security/record_rules.xml new file mode 100644 index 00000000000..bb24a7d1e29 --- /dev/null +++ b/real_estate/security/record_rules.xml @@ -0,0 +1,38 @@ + + + + + Agent can access own or unassigned properties + + + [ + '|', ('salesperson_id', '=', user.id), + ('salesperson_id', '=', False) + ] + + + + + + + Manager can access all properties + + + [(1, '=', 1)] + + + + + + + Multi-company restriction on properties + + [ + '|', ('company_id', '=', False), + ('company_id', 'in', company_ids) + ] + + + + + diff --git a/real_estate/security/security.xml b/real_estate/security/security.xml new file mode 100644 index 00000000000..944cc6f8402 --- /dev/null +++ b/real_estate/security/security.xml @@ -0,0 +1,14 @@ + + + + + Agent + + + + Manager + + + + + diff --git a/real_estate/tests/__init__.py b/real_estate/tests/__init__.py new file mode 100644 index 00000000000..51377e5c131 --- /dev/null +++ b/real_estate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_property_logic diff --git a/real_estate/tests/test_property_logic.py b/real_estate/tests/test_property_logic.py new file mode 100644 index 00000000000..e54c9ccc396 --- /dev/null +++ b/real_estate/tests/test_property_logic.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_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_id, 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/view/estate_menu.xml b/real_estate/view/estate_menu.xml new file mode 100644 index 00000000000..a124f812e3f --- /dev/null +++ b/real_estate/view/estate_menu.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/real_estate/view/estate_property_offer_views.xml b/real_estate/view/estate_property_offer_views.xml new file mode 100644 index 00000000000..f057e7f897c --- /dev/null +++ b/real_estate/view/estate_property_offer_views.xml @@ -0,0 +1,40 @@ + + + Real estate offer + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + estate.property.offer.form + estate.property.offer + +
    +
    +
    + + + + + + + + +
    +
    +
    + + estate.property.offer.list + estate.property.offer + + + + + +
    + + + + + + + + + + + + + + + + + + + + + estate.property.type.tree + estate.property.type + + + + + + + + + diff --git a/real_estate/view/estate_property_views.xml b/real_estate/view/estate_property_views.xml new file mode 100644 index 00000000000..c7813f98ed5 --- /dev/null +++ b/real_estate/view/estate_property_views.xml @@ -0,0 +1,112 @@ + + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
    +
    +
    + +

    + +

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