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/components/dashboard_item/dashboard_item.js b/awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.js new file mode 100644 index 00000000000..b383b9bc812 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.js @@ -0,0 +1,9 @@ +import { Component } from "@odoo/owl" + +export class DashboardItem extends Component { + static template = "awesome_dashboard.dashboard_item" + static props = { + slots: { type: Object, shape: { default: Object } }, + size: { type: Number, default: 1, optional: true } + } +} diff --git a/awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.xml b/awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.xml new file mode 100644 index 00000000000..b338385c421 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/components/number_card/number_card.js b/awesome_dashboard/static/src/dashboard/components/number_card/number_card.js new file mode 100644 index 00000000000..27399dc4d24 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/number_card/number_card.js @@ -0,0 +1,9 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.number_card" + static props = { + title: { type: String }, + value: { type: [Number, String] } + } +} diff --git a/awesome_dashboard/static/src/dashboard/components/number_card/number_card.xml b/awesome_dashboard/static/src/dashboard/components/number_card/number_card.xml new file mode 100644 index 00000000000..6b12226a555 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/number_card/number_card.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.js new file mode 100644 index 00000000000..125e9c8192b --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.js @@ -0,0 +1,43 @@ +import { Component, onWillStart, onMounted, useRef, onWillUpdateProps } from "@odoo/owl"; +import { loadJS } from "@web/core/assets"; +import { _t } from "@web/core/l10n/translation"; + + +export class PieChartCard extends Component { + static template = "awesome_dashboard.pie_chart" + + setup() { + this.canvasRef = useRef("canvas") + + onWillStart(async () => { + await loadJS("/web/static/lib/Chart/Chart.js") + }) + onMounted(() => { + this.renderChart(); + }); + onWillUpdateProps((nextProps) => { + if (this.chart) { + this.chart.destroy(); + } + this.renderChart(nextProps.data); + }); + } + + renderChart() { + this.chart = new Chart(this.canvasRef.el.getContext("2d"), { + type: "pie", + data: { + labels: Object.keys(this.props.data), + datasets: [{ + label: this.props.title, + data: Object.values(this.props.data), + backgroundColor: ["#007BFF", "#FFA500", "#808090"] + }] + }, + options: { + responsive: true, + maintainAspectRatio: false + }, + }) + } +} diff --git a/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.xml new file mode 100644 index 00000000000..c88c31d97da --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/components/services/statistics_service.js b/awesome_dashboard/static/src/dashboard/components/services/statistics_service.js new file mode 100644 index 00000000000..c39a1f060e8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/components/services/statistics_service.js @@ -0,0 +1,30 @@ +import { registry } from "@web/core/registry"; +import { rpc } from "@web/core/network/rpc"; +import { reactive } from "@odoo/owl"; + +const statisticsService = { + start() { + const stats = reactive({ + nb_new_orders: 0, + total_amount: 0, + average_quantity: 0, + nb_cancelled_orders: 0, + average_time: 0, + orders_by_size: { m: 0, s: 0, xl: 0 } + }); + const loadStatistics = async () => { + const result = await rpc("/awesome_dashboard/statistics"); + if (result) { + Object.assign(stats, result); + } + }; + loadStatistics(); + setInterval(() => { + loadStatistics(); + }, 10 * 60 * 1000); + + return { data: stats }; + } +} + +registry.category("services").add("awesome_dashboard.statistics", statisticsService); diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..c1205c3be16 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,94 @@ +import { Component, useState, onWillStart } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; +import { useService } from "@web/core/utils/hooks"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; +import { DashboardItem } from "@awesome_dashboard/dashboard/components/dashboard_item/dashboard_item"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem } + + setup() { + this.action = useService("action") + this.dialog = useService("dialog") + this.statisticsService = useService("awesome_dashboard.statistics"); + this.statistics = useState(this.statisticsService.data); + this.display = { controlPanel: {} } + this.items = registry.category("awesome_dashboard").getAll(); + this.state = useState({ + disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [] + }) + } + + openCustomersKanban() { + 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"] + ] + }) + } + + openConfigDialog() { + this.dialog.add(ConfigurationDialog, { + items: this.items, + disabledItems: this.state.disabledItems, + onUpdateConfiguration: this.updateConfiguration.bind(this), + }) + } + + updateConfiguration(newDisabledItems) { + this.state.disabledItems = newDisabledItems; + } + +} + +class ConfigurationDialog extends Component { + static template = "awesome_dashboard.ConfigurationDialog"; + static components = { CheckBox, Dialog }; + static props = { + items: { type: Array }, + disabledItems: { type: Array }, + onUpdateConfiguration: { type: Function }, + close: { type: Function } + }; + + 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..d76f98760b5 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,6 @@ +@media (max-width: 767px) { + .pie-chart-card { + width: 100% !important; + margin-bottom: 16px; + } +} diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..bcbf60f7cb6 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,39 @@ + + + + + + Customers + Leads + + + + + + + + + + + + + + + + + + + Which cards do you want to see? + + + + + + + + Done + + + + + 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..af421ea8fe8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,65 @@ +import { NumberCard } from "@awesome_dashboard/dashboard/components/number_card/number_card"; +import { registry } from "@web/core/registry"; +import { PieChartCard } from "@awesome_dashboard/dashboard/components/pie_chart_card/pie_chart_card"; +import { _t } from "@web/core/l10n/translation"; + + +const items = [ + { + id: "new_orders", + description: _t("Number of new orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Number of new orders this month"), + value: data.nb_new_orders + }) + }, + { + id: "amount_new_orders", + description: _t("Total amount of new orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Total amount of new orders this month"), + value: data.total_amount + }) + }, + { + id: "average_quantity", + description: _t("Average amount of t-shirt by order this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Average amount of t-shirt by order this month"), + value: data.average_quantity + }) + }, + { + id: "cancelled_orders", + description: _t("Number of cancelled orders this month"), + Component: NumberCard, + props: (data) => ({ + title: _t("Number of cancelled orders this month"), + value: data.nb_cancelled_orders + }) + }, + { + id: "average_time", + description: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"), + Component: NumberCard, + props: (data) => ({ + title: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"), + value: data.average_time + }) + }, + { + id: "pie_chart", + description: _t("Shirt orders by size"), + Component: PieChartCard, + size: 2, + props: (data) => ({ + title: _t("Shirt orders by size"), + data: data.orders_by_size + }) + } +] + +items.forEach((item) => { registry.category("awesome_dashboard").add(item.id, item) }) diff --git a/awesome_dashboard/static/src/dashboard_action.js b/awesome_dashboard/static/src/dashboard_action.js new file mode 100644 index 00000000000..edffe8ceefe --- /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"; + +class AwesomeDashboardAction extends Component { + static components = { LazyComponent }; + static template = xml` + + ` +} + +registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardAction); diff --git a/awesome_gallery/models/ir_action.py b/awesome_gallery/models/ir_action.py index eae20acbf5c..d796bc8beae 100644 --- a/awesome_gallery/models/ir_action.py +++ b/awesome_gallery/models/ir_action.py @@ -7,4 +7,4 @@ class ActWindowView(models.Model): view_mode = fields.Selection(selection_add=[ ('gallery', "Awesome Gallery") - ], ondelete={'gallery': 'cascade'}) + ], ondelete={'gallery': 'cascade'}) diff --git a/awesome_owl/__manifest__.py b/awesome_owl/__manifest__.py index 77abad510ef..d068840247d 100644 --- a/awesome_owl/__manifest__.py +++ b/awesome_owl/__manifest__.py @@ -33,6 +33,7 @@ 'web/static/lib/bootstrap/scss/_variables.scss', 'web/static/lib/bootstrap/scss/_maps.scss', ('include', 'web._assets_bootstrap'), + ("include", "web._assets_bootstrap_backend"), ('include', 'web._assets_core'), 'web/static/src/libs/fontawesome/css/font-awesome.css', 'awesome_owl/static/src/**/*', diff --git a/awesome_owl/static/src/components/card/card.js b/awesome_owl/static/src/components/card/card.js new file mode 100644 index 00000000000..e26af1a990f --- /dev/null +++ b/awesome_owl/static/src/components/card/card.js @@ -0,0 +1,15 @@ +import { Component, useState } from "@odoo/owl" + +export class Card extends Component { + static template = "awsome_owl123.Card"; + static props = { + title: { type: String }, + slots: { type: Object, optional: true }, + }; + setup() { + this.state = useState({ open: true }); + } + toggle() { + this.state.open = !this.state.open; + } +} diff --git a/awesome_owl/static/src/components/card/card.xml b/awesome_owl/static/src/components/card/card.xml new file mode 100644 index 00000000000..f92312f076c --- /dev/null +++ b/awesome_owl/static/src/components/card/card.xml @@ -0,0 +1,19 @@ + + + + + + + + + – + + + + + + + + + + + diff --git a/awesome_owl/static/src/components/counter/counter.js b/awesome_owl/static/src/components/counter/counter.js new file mode 100644 index 00000000000..f4145267dfa --- /dev/null +++ b/awesome_owl/static/src/components/counter/counter.js @@ -0,0 +1,20 @@ +import { Component, useState } from "@odoo/owl" + +export class Counter extends Component { + static template = "awsome_owl.Counter" + static props = { + id: { type: String }, + onChange: { type: Function, optional: true } + } + + setup() { + this.state = useState({ count: 0 }); + } + + increment() { + this.state.count++; + if (this.props.onChange) { + this.props.onChange() + } + } +} diff --git a/awesome_owl/static/src/components/counter/counter.xml b/awesome_owl/static/src/components/counter/counter.xml new file mode 100644 index 00000000000..6cdd3bea6ba --- /dev/null +++ b/awesome_owl/static/src/components/counter/counter.xml @@ -0,0 +1,9 @@ + + + + + Counter: + Increment + + + diff --git a/awesome_owl/static/src/components/todo_list/todo_item.js b/awesome_owl/static/src/components/todo_list/todo_item.js new file mode 100644 index 00000000000..9e074b895e4 --- /dev/null +++ b/awesome_owl/static/src/components/todo_list/todo_item.js @@ -0,0 +1,27 @@ +import { Component } from "@odoo/owl" + +export class TodoItem extends Component { + static template = "awsome_owl.todo_item" + + static props = { + deleteTodo: { type: Function }, + toggleState: { type: Function }, + todo: { + type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean + } + } + } + + toggleState() { + this.props.toggleState(this.props.todo.id); + } + + + removeTodo() { + this.props.deleteTodo(this.props.todo.id) + } +} diff --git a/awesome_owl/static/src/components/todo_list/todo_item.xml b/awesome_owl/static/src/components/todo_list/todo_item.xml new file mode 100644 index 00000000000..a109fd88840 --- /dev/null +++ b/awesome_owl/static/src/components/todo_list/todo_item.xml @@ -0,0 +1,12 @@ + + + + + + + . + + + + + diff --git a/awesome_owl/static/src/components/todo_list/todo_list.js b/awesome_owl/static/src/components/todo_list/todo_list.js new file mode 100644 index 00000000000..fa5427d222f --- /dev/null +++ b/awesome_owl/static/src/components/todo_list/todo_list.js @@ -0,0 +1,44 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "@awesome_owl/components/todo_list/todo_item"; +import { useAutoFocus } from "@awesome_owl/lib/utils"; + +export class TodoList extends Component { + static template = "awsome_owl.todo_list"; + static components = { TodoItem }; + + setup() { + this.state = useState({ nextId: 1, todos: [] }) + this.inputRef = useAutoFocus("add-input"); + } + + addTodo(e) { + if (e.keyCode === 13) { + const todoDesc = e.target.value.trim(); + e.target.value = ""; + if (todoDesc) { + const newTodo = { + id: this.state.nextId++, + description: todoDesc, + isCompleted: false + } + this.state.todos.push(newTodo); + } + } + } + + deleteTodo(id) { + const index = this.state.todos.findIndex(t => t.id == id) + if (index >= 0) { + this.state.todos.splice(index, 1) + } + } + + + toggleTodoState(id) { + const todo = this.state.todos.find(t => t.id == id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + +} diff --git a/awesome_owl/static/src/components/todo_list/todo_list.xml b/awesome_owl/static/src/components/todo_list/todo_list.xml new file mode 100644 index 00000000000..bea43b373e9 --- /dev/null +++ b/awesome_owl/static/src/components/todo_list/todo_list.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + No Todos. + + + + + diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..2b4895d71c1 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,19 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; +import { Component, useState } from "@odoo/owl"; +import { Counter } from "@awesome_owl/components/counter/counter"; +import { Card } from "@awesome_owl/components/card/card"; +import { TodoList } from "@awesome_owl/components/todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + + setup() { + this.state = useState({ sum: 0 }); + } + + incrementSum() { + this.state.sum++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..d80394e8ba8 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,17 @@ - + - - hello world + + + The sum is: + + + + + + + - 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..670e5c5baa6 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,30 @@ +{ + 'name': "Real Estate", + 'summary': "Manage real estate properties, offers, and sales in Odoo", + 'category': "Real Estate/Brokerage", + 'description': ( + "This module allows you to manage real estate properties, offers, property types, and related data. " + "It includes basic listing management, offer tracking, reporting capabilities, and user access controls. " + "Suitable for use in property management workflows within the Odoo system." + ), + 'author': "Dhruvrajsinh Zala (zadh)", + 'installable': True, + 'application': True, + 'data': [ + 'security/security.xml', + 'security/ir.model.access.csv', + 'report/estate_property_templates.xml', + 'report/estate_user_properties_templates.xml', + 'report/estate_user_properties_report.xml', + 'report/estate_property_reports.xml', + 'views/estate_property_views.xml', + 'views/estate_property_offers.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tags.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + 'data/estate.property.types.csv', + ], + 'demo': ['demo/demo_data.xml'], + 'license': 'AGPL-3' +} diff --git a/estate/data/estate.property.types.csv b/estate/data/estate.property.types.csv new file mode 100644 index 00000000000..6069981e33c --- /dev/null +++ b/estate/data/estate.property.types.csv @@ -0,0 +1,5 @@ +id,name +property_type_residential,Residential +property_type_commercial,Commercial +property_type_industrial,Industrial +property_type_land,Land diff --git a/estate/demo/demo_data.xml b/estate/demo/demo_data.xml new file mode 100644 index 00000000000..2366868f468 --- /dev/null +++ b/estate/demo/demo_data.xml @@ -0,0 +1,106 @@ + + + + Big Villa + new + A nice and big villa + 12345 + 2020-02-02 + 1600000 + 1600000 + 6 + 100 + 4 + True + True + 100000 + south + + + + Trailer home + cancelled + Home in a trailer park + 54321 + 1970-01-01 + 100000 + 1 + 10 + 4 + False + True + + + + Property with Offers + new + Villa with Offers + 12345 + 2021-07-07 + 3600000 + 3600000 + 7 + 150 + 6 + True + True + 200000 + south + + + + + + + 1000 + 14 + + + + + + 1500000 + 14 + + + + + + + 1500001 + 14 + + + + + + + 1000 + 14 + + + + + + 1500000 + 14 + + + + + + + 1500001 + 14 + + + + + + + + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..3561724904f --- /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 esatate_property_type +from . import estate_property_tags +from . import estate_property_offer +from . import res_users diff --git a/estate/models/esatate_property_type.py b/estate/models/esatate_property_type.py new file mode 100644 index 00000000000..28bcefeaefa --- /dev/null +++ b/estate/models/esatate_property_type.py @@ -0,0 +1,21 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields, api + + +class EstatePropertyTyeps(models.Model): + _name = "estate.property.types" + _description = "Types of Estate Property" + _order = "sequence, name" + _sql_constraints = [("_unique_type_name", "UNIQUE(name)", "Property type name must be unique.")] + + name = fields.Char(required=True, string="Title") + property_ids = fields.One2many("estate.property", "property_type_id", string="Properties") + sequence = fields.Integer(default=1, string="sequence") + offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers") + offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count", store=True) + + @api.depends("offer_ids") + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..7b2673cebb6 --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,104 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from dateutil.relativedelta import relativedelta +from odoo import models, fields, api, _ +from odoo.tools.float_utils import float_compare, float_is_zero +from odoo.exceptions import UserError, ValidationError + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property" + _order = "id desc" + + _sql_constraints = [ + ("_check_expected_price", "CHECK(expected_price > 0)", "The expected price must be positive."), + ("_check_selling_price", "CHECK(selling_price >= 0)", "The selling price must be positive.") + ] + + name = fields.Char(required=True, string="Title") + description = fields.Text(string="Description") + postcode = fields.Char(string="Postcode") + date_availability = fields.Date(default=lambda self: fields.Date.today() + relativedelta(months=3), + copy=False, string="Available From") + expected_price = fields.Float(required=True, string="Expected Price") + selling_price = fields.Float(readonly=True, copy=False, string="Selling Price") + bedrooms = fields.Integer(default=2, string="Bedrooms") + living_area = fields.Integer(string="Living Area (sqm)") + total_area = fields.Float(compute="_compute_total_area", store=True, string="Total Area") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") + active = fields.Boolean(default=True, string="Active") + garden_orientation = fields.Selection([ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West") + ], string="Garden Orientation") + state = fields.Selection([ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled") + ], required=True, copy=False, default="new", string="State") + property_type_id = fields.Many2one("estate.property.types", 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.tags", string="Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + best_price = fields.Float(compute="_get_best_offer_price", store=True, string="Best Price") + company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company) + + @api.ondelete(at_uninstall=False) + def _unlink_except_state_new_or_cancelled(self): + for record in self: + if record.state not in ["new", "cancelled"]: + raise UserError(_("You can only delete properties in 'New' or 'Cancelled' state.")) + + @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 _get_best_offer_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): + for record in self: + if record.garden: + record.garden_area = 10 + record.garden_orientation = "north" + else: + record.garden_area = 0 + record.garden_orientation = False + + def action_set_state_sold(self): + for record in self: + if record.state == "cancelled": + raise UserError(_("Cancelled property cannot be sold.")) + if not record.offer_ids.filtered(lambda offer: offer.status == "accepted"): + raise UserError(_("You cannot sell a property without an accepted offer.")) + record.state = "sold" + return True + + def action_set_state_cancel(self): + for record in self: + if record.state == "sold": + raise UserError(_("Sold property cannot be cancelled.")) + else: + record.state = "cancelled" + return True + + @api.constrains("selling_price", "expected_price") + def _check_selling_price(self): + for record in self: + if not float_is_zero(record.selling_price, precision_digits=2): + if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) < 0: + raise ValidationError(_("The selling price cannot be lower than 90% of the expected price")) diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..e5974c1d19c --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,72 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, api, _ +from odoo.exceptions import UserError, ValidationError +from datetime import timedelta, datetime + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Offers of Estate Property" + _order = "price desc" + _sql_constraints = [("_check_offer_price", "CHECK(price > 0)", "The Offer price must be positive.")] + + price = fields.Float(string="Price") + status = fields.Selection([("accepted", "Accepted"), ("refused", "Refused")], copy=False, string="Status") + 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.types", related="property_id.property_type_id", + string="Property Type", required=True) + validity = fields.Integer(default=7, string="Validity") + date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline", store=True, string="Deadline Date") + + @api.model_create_multi + def create(self, vals): + for val in vals: + property_id = val["property_id"] + offer_price = val["price"] + property = self.env["estate.property"].browse(property_id) + is_state_new = (property.state == "new") + result = self.read_group( + domain=[("property_id", "=", property_id)], + fields=["price:max"], + groupby=[], + ) + max_price = result[0]["price"] if result else 0 + if property.state == 'sold': + raise ValidationError(_("Cannot create an offer on a sold property.")) + if max_price >= offer_price: + raise UserError(_("You cannot create an offer with a lower or equal amount than an existing offer for this property.")) + if is_state_new: + property.state = "offer_received" + return super().create(vals) + + @api.depends("validity") + def _compute_deadline(self): + for record in self: + create_date = record.create_date or datetime.now() + record.date_deadline = create_date + timedelta(days=record.validity) + + def _inverse_deadline(self): + for record in self: + create_date = record.create_date or datetime.now() + if record.date_deadline: + delta = record.date_deadline - create_date.date() + record.validity = delta.days + + def action_accept_offer(self): + for record in self: + existing = self.search([("property_id", "=", record.property_id.id), ("status", "=", "accepted")]) + if existing: + raise UserError(_("Another offer has been already accepted.")) + record.status = "accepted" + record.property_id.state = "offer_accepted" + record.property_id.selling_price = record.price + record.property_id.buyer_id = record.partner_id.id + + def action_refuse_offer(self): + for record in self: + if record.status == "accepted": + raise UserError(_("Accepted Offer cannot be Refused")) + else: + record.status = "refused" diff --git a/estate/models/estate_property_tags.py b/estate/models/estate_property_tags.py new file mode 100644 index 00000000000..37c7130825c --- /dev/null +++ b/estate/models/estate_property_tags.py @@ -0,0 +1,13 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class EstatePropertyTags(models.Model): + _name = "estate.property.tags" + _description = "Estate Property Tags" + _order = "name" + _sql_constraints = [("_unique_tag_name", "UNIQUE(name)", "Tag name must be unique.")] + + name = fields.Char(required=True, string="Title") + color = fields.Integer(default=3, string="Color") diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..37511537056 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,10 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many("estate.property", "salesperson_id", string="Available Properties", + domain=[("state", "in", ["new", "offer_received"])]) diff --git a/estate/report/estate_property_reports.xml b/estate/report/estate_property_reports.xml new file mode 100644 index 00000000000..ee201b1db61 --- /dev/null +++ b/estate/report/estate_property_reports.xml @@ -0,0 +1,13 @@ + + + + Property Offers Report + estate.property + qweb-pdf + estate.report_property_offers + estate.report_property_offers + 'Property Offers - %s' % (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..f929486da04 --- /dev/null +++ b/estate/report/estate_property_templates.xml @@ -0,0 +1,59 @@ + + + + + + + + Price + Partner + Validity(days) + Deadline + State + + + + + + + + + + + + + + + + + + + + + + + + Salesman: + + + + Expected Price: + + + + Status: + + + + + + + + No offers yet for this property. + + + + + + + diff --git a/estate/report/estate_user_properties_report.xml b/estate/report/estate_user_properties_report.xml new file mode 100644 index 00000000000..9f7bd042433 --- /dev/null +++ b/estate/report/estate_user_properties_report.xml @@ -0,0 +1,13 @@ + + + + User Properties Report + res.users + qweb-pdf + estate.report_user_properties + estate.report_user_properties + 'User Properties - %s' % (object.name) + + report + + diff --git a/estate/report/estate_user_properties_templates.xml b/estate/report/estate_user_properties_templates.xml new file mode 100644 index 00000000000..6c1183727c9 --- /dev/null +++ b/estate/report/estate_user_properties_templates.xml @@ -0,0 +1,36 @@ + + + + + + + + Salesperson: + + + + + () + + + Type: + + + Expected Price: + + + + + + + + + + This salesperson has no assigned properties. + + + + + + + diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..8b34a30f8aa --- /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 +estate.access_estate_property_user,access_estate_property_user,estate.model_estate_property,base.group_user,1,0,0,0 +estate.access_estate_property_manager,access_estate_property_manager,estate.model_estate_property,estate.estate_group_manager,1,1,1,0 +estate.access_estate_property_agent,access_estate_property_agent,estate.model_estate_property,estate.estate_group_agent,1,1,1,0 +estate.access_estate_property_types_manager,access_estate_property_types_manager,estate.model_estate_property_types,estate.estate_group_manager,1,1,1,0 +estate.access_estate_property_types_agent,access_estate_property_types_agent,estate.model_estate_property_types,estate.estate_group_agent,1,0,0,0 +estate.access_estate_property_tags_manager,access_estate_property_tags_manager,estate.model_estate_property_tags,estate.estate_group_manager,1,1,1,0 +estate.access_estate_property_tags_agent,access_estate_property_tags_agent,estate.model_estate_property_types,estate.estate_group_agent,1,0,0,0 +estate.access_estate_property_offer_manager,access_estate_property_offer_manager,estate.model_estate_property_offer,estate.estate_group_manager,1,1,1,0 +estate.access_estate_property_offer_agent,access_estate_property_offer_agent,estate.model_estate_property_offer,estate.estate_group_agent,1,1,1,0 diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..3f4f0f73fd2 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,45 @@ + + + + Agent + + + + Manager + + + + + Agent: Own or Unassigned Properties + + + ['|',('salesperson_id','=',user.id),('salesperson_id','=',0)] + + + + + + + + Manager: All Properties + + + [(1,'=',1)] + + + + + + + Estate Property: Multi-company + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + + + + + + + diff --git a/estate/tests/__init__.py b/estate/tests/__init__.py new file mode 100644 index 00000000000..5441fbed086 --- /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_offer diff --git a/estate/tests/test_estate_property_offer.py b/estate/tests/test_estate_property_offer.py new file mode 100644 index 00000000000..48b913b8503 --- /dev/null +++ b/estate/tests/test_estate_property_offer.py @@ -0,0 +1,59 @@ +from odoo.exceptions import ValidationError, UserError +from odoo.tests import Form, tagged +from odoo.tests.common import TransactionCase + + +@tagged('post_install', '-at_install') +class TestEstateProperty(TransactionCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test Buyer"}) + cls.property_type = cls.env["estate.property.types"].create({"name": "Apartment2"}) + cls.property = cls.env["estate.property"].create({ + "name": "Test Property", + "expected_price": 150000, + "property_type_id": cls.property_type.id + }) + + def test_cannot_create_offer_on_sold_property(self): + self.property.state = "sold" + with self.assertRaises(ValidationError): + self.env["estate.property.offer"].create({ + "price": 160000, + "partner_id": self.partner.id, + "property_id": self.property.id + }) + + def test_cannot_sell_property_without_accepted_offer(self): + with self.assertRaises(UserError): + self.property.action_set_state_sold() + + def test_cannot_sell_property_with_accepted_offer(self): + offer = self.env["estate.property.offer"].create({ + "price": 160000, + "partner_id": self.partner.id, + "property_id": self.property.id + }) + offer.action_accept_offer() + self.property.action_set_state_sold() + self.assertEqual(self.property.state, "sold") + self.assertEqual(self.property.selling_price, offer.price) + self.assertEqual(self.property.buyer_id, self.partner) + + def test_garden_fields_reset_on_uncheck(self): + with Form(self.env["estate.property"]) as prop: + prop.expected_price = 10000 + prop.name = "Test property" + prop.garden = True + prop.garden_area = 25 + prop.garden_orientation = "west" + property = prop.save() + + with Form(property) as prop: + prop.garden = False + property = prop.save() + + self.assertEqual(property.garden_area, 0) + self.assertFalse(property.garden_orientation) diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..4cd0aa9e303 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offers.xml b/estate/views/estate_property_offers.xml new file mode 100644 index 00000000000..adbcb03a82a --- /dev/null +++ b/estate/views/estate_property_offers.xml @@ -0,0 +1,24 @@ + + + Property Offers + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + estate.property.offer.list + estate.property.offer + + + + + + + + + + + + diff --git a/estate/views/estate_property_tags.xml b/estate/views/estate_property_tags.xml new file mode 100644 index 00000000000..c298d1b7596 --- /dev/null +++ b/estate/views/estate_property_tags.xml @@ -0,0 +1,29 @@ + + + + Property Tags + estate.property.tags + list,form + + + estate.property.tags.list + estate.property.tags + + + + + + + + estate.property.tags.form + estate.property.tags + form + + + + + + + + + diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..c6682dd90fb --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,50 @@ + + + + Property Types + estate.property.types + list,form + + + estate.property.types.list + estate.property.types + + + + + + + + + estate.property.types.form + estate.property.types + form + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..9740f753060 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,116 @@ + + + + Properties + estate.property + list,form + {'search_default_available':1} + + + estate.property.list + estate.property + list + + + + + + + + + + + + + + + + estate.property.form + estate.property + form + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.search + estate.property + search + + + + + + + + + + + + + + + diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..605c5be7d48 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.form.inherit.estate + 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..7d20f4be95f --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,8 @@ +{ + "name": "Estate Account", + "depends": ["estate", "account"], + 'category': "Tutorials", + "installable": True, + "license": "AGPL-3", + 'data': ['report/estate_property_report_inherit.xml'] +} 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..412929a656a --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,33 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, Command +from odoo.exceptions import UserError, AccessError + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_set_state_sold(self): + res = super().action_set_state_sold() + journal = self.env["account.journal"].sudo().search([("type", "=", "sale")], limit=1) + if not journal: + raise UserError("No sales journal found!") + try: + self.check_access('write') + except AccessError: + raise UserError("You do not have sufficient access rights to create an invoice for this property.") + for property in self: + if property.buyer_id: + commission = property.selling_price * 0.06 + admin_fee = 100.00 + self.env["account.move"].sudo().create({ + "partner_id": property.buyer_id.id, + "move_type": "out_invoice", + "journal_id": journal.id, + "company_id": property.company_id.id, + "invoice_line_ids": [ + Command.create({"name": "Commission (6%)", "quantity": 1, "price_unit": commission}), + Command.create({"name": "Administrative fees", "quantity": 1, "price_unit": admin_fee}), + ], + }) + return res diff --git a/estate_account/report/estate_property_report_inherit.xml b/estate_account/report/estate_property_report_inherit.xml new file mode 100644 index 00000000000..a0a63b69b48 --- /dev/null +++ b/estate_account/report/estate_property_report_inherit.xml @@ -0,0 +1,13 @@ + + + + + + + Invoice Status: + Invoice has been created for this sold property. + + + + +
+ +
Counter:
No Todos.
No offers yet for this property.
This salesperson has no assigned properties.