diff --git a/.gitignore b/.gitignore index b6e47617de1..c5479395052 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,9 @@ dmypy.json # Pyre type checker .pyre/ + +estate/.idea/ +.idea +package.json +package-lock.json +node_modules diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..9cb889db903 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -24,6 +24,10 @@ '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/configuration_dialog.js b/awesome_dashboard/static/src/dashboard/configuration_dialog.js new file mode 100644 index 00000000000..6f5d3d1757a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration_dialog.js @@ -0,0 +1,38 @@ +import { Component, useState } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; + +export 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); + } + +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/configuration_dialog.xml b/awesome_dashboard/static/src/dashboard/configuration_dialog.xml new file mode 100644 index 00000000000..c443d76206e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/configuration_dialog.xml @@ -0,0 +1,15 @@ + + + Which cards do you wish to see ? + + + + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..4d846ccb282 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,58 @@ +/** @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 { browser } from "@web/core/browser/browser"; +import { ConfigurationDialog } from "./configuration_dialog"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem }; + + setup() { + this.dialog = useService("dialog"); + this.action = useService("action"); + this.display = { + controlPanel: {}, + }; + this.statistics = useState(useService("awesome_dashboard.statistics")); + 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"], + ], + }); + } +} + +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..1ee54bd1063 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard { + background-color: gray; +} \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.xml b/awesome_dashboard/static/src/dashboard/dashboard.xml new file mode 100644 index 00000000000..cf88feb04e0 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + +
+ + + + + + +
+
+
+
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..5f6ce4577c4 --- /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, + }, + }; +} \ No newline at end of file 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..d023340bb59 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
\ No newline at end of file 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..8de9fdedf20 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,65 @@ +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); +}); \ No newline at end of file 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..d3bd9c0e4ef --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl"; + +export class NumberCard extends Component { + static template = "awesome_dashboard.NumberCard"; + static props = { + title: { + type: String, + }, + value: { + type: Number, + } + } +} \ No newline at end of file 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..73bc3cac926 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card/number_card.xml @@ -0,0 +1,9 @@ + + + + +
+ +
+
+
\ No newline at end of file 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..aefa3e8e7c8 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,63 @@ +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +import { Component, onWillStart, useRef, onMounted, onWillUnmount, onWillUpdateProps } from "@odoo/owl"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef("canvas"); + this.chart = null; + onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"])); + onMounted(() => { + this.renderChart(); + }); + + // This is the key change. This hook will be executed whenever the + // component is about to receive new props. + onWillUpdateProps((nextProps) => { + if (!this.chart) { + return; + } + // Update the chart's data and labels with the new props + this.chart.data.labels = Object.keys(nextProps.data); + this.chart.data.datasets[0].data = Object.values(nextProps.data); + this.chart.data.datasets[0].backgroundColor = Object.keys(nextProps.data).map((_, index) => getColor(index)); + + // Tell Chart.js to re-render with the new data + this.chart.update(); + }); + + onWillUnmount(() => { + if (this.chart) { + this.chart.destroy(); + } + }); + } + + renderChart() { + if (this.chart) { + this.chart.destroy(); + } + 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, + }, + ], + }, + }); + } +} \ No newline at end of file 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..18416e9a223 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,10 @@ + + + +
+
+ +
+
+
+
\ No newline at end of file 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..04dc61aa73a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.js @@ -0,0 +1,15 @@ +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, + }, + } +} \ No newline at end of file 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..b8c94bebb64 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file 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..cd52baf417e --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/statistics_service.js @@ -0,0 +1,20 @@ +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + 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); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..fde089e0f9e --- /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); \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..ab9dbbf33bc --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,22 @@ +import {Component, useState} from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + static props = { + title: String, + slots: { + type: Object, + shape: { + default: true + }, + }, + }; + + setup() { + this.state = useState({ isOpen: true }); + } + + toggleContent() { + this.state.isOpen = !this.state.isOpen; + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..3b7f1e5ab8b --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,16 @@ + + + +
+
+
+ + +
+

+ +

+
+
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..b552ecefe0b --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,19 @@ +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 = this.state.value + 1; + if (this.props.onChange) { + this.props.onChange(); + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..3926013cbad --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,7 @@ + + + +

Counter:

+ +
+
\ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..020120215dc 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, markup, useState} from "@odoo/owl" +import {Counter} from "./counter/counter"; +import {Card} from "./card/card"; +import { TodoList } from "./todo_list/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; + static components = {Counter, Card, TodoList}; + + setup() { + this.sum = useState({ value: 2 }); + } + + incrementSum() { + this.sum.value++; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..734e9ddc80a 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,10 +1,20 @@ - -
- hello world + Hello World +
+ + +
The sum is:
+
+ + content of card 1 + + + + +
+ - diff --git a/awesome_owl/static/src/todo_item/todo_item.js b/awesome_owl/static/src/todo_item/todo_item.js new file mode 100644 index 00000000000..305365ff491 --- /dev/null +++ b/awesome_owl/static/src/todo_item/todo_item.js @@ -0,0 +1,21 @@ +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, + }; + + onChange() { + this.props.toggleState(this.props.todo.id); + } + + onRemove() { + this.props.removeTodo(this.props.todo.id); + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/todo_item/todo_item.xml b/awesome_owl/static/src/todo_item/todo_item.xml new file mode 100644 index 00000000000..ab21b5eb865 --- /dev/null +++ b/awesome_owl/static/src/todo_item/todo_item.xml @@ -0,0 +1,13 @@ + + + +
+ + + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/todo_list/todo_list.js b/awesome_owl/static/src/todo_list/todo_list.js new file mode 100644 index 00000000000..e43f34baa22 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.js @@ -0,0 +1,41 @@ +import { Component, useState } from "@odoo/owl"; +import { TodoItem } from "../todo_item/todo_item"; +import { useAutofocus } from "../utils"; + + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.nextId = 0; + this.todos = useState([]); + useAutofocus("input") + } + + addTodo(ev) { + if (ev.keyCode === 13 && ev.target.value != "") { + this.todos.push({ + id: this.nextId++, + description: ev.target.value, + isCompleted: false + }); + ev.target.value = ""; + } + } + + toggleTodo(todoId) { + const todo = this.todos.find((todo) => todo.id === todoId); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(todoId) { + const todoIndex = this.todos.findIndex((todo) => todo.id === todoId); + if (todoIndex >= 0) { + this.todos.splice(todoIndex, 1); + } + } + +} \ No newline at end of file diff --git a/awesome_owl/static/src/todo_list/todo_list.xml b/awesome_owl/static/src/todo_list/todo_list.xml new file mode 100644 index 00000000000..da712437054 --- /dev/null +++ b/awesome_owl/static/src/todo_list/todo_list.xml @@ -0,0 +1,11 @@ + + + +
+ + + + +
+
+
\ No newline at end of file diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..6a5475b357e --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { useRef, onMounted } from "@odoo/owl"; + +export function useAutofocus(refName) { + const ref = useRef(refName); + onMounted(() => { + ref.el.focus(); + }); +} \ No newline at end of file diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..96351812b24 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,23 @@ +{ + 'name': "estate", + 'version': '1.0', + 'category': 'Sales/RealEstate', + 'summary': 'Track and deal with real estate properties.', + 'author': "Odoo S.A.", + 'description': """ + Description text + """, + 'depends': ['base'], + 'installable': True, + 'application': True, + 'data': [ + 'security/ir.model.access.csv', + 'views/estate_property_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_tag_views.xml', + 'views/res_users_views.xml', + 'views/estate_menus.xml', + ], + 'license': 'LGPL-3', +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..3a6159510bf --- /dev/null +++ b/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 (res_users) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..6b643f4488a --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,131 @@ +from odoo import _, api, exceptions, fields, models +from odoo.tools.date_utils import add +from odoo.tools.float_utils import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = 'estate.property' + _description = 'Estate Property' + _order = 'id desc' + _sql_constraints = [ + ('check_expected_price_strictly_positive', 'CHECK(expected_price > 0)', + 'The expected price of a property should be strictly positive.'), + ('check_selling_price_positive', 'CHECK(selling_price >= 0)', + 'The selling price of a property should be positive or zero.'), + ] + + name = fields.Char("Title", required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date("Available From", copy=False, + default=lambda _: add(fields.Date.today(), months=3)) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer("Living Area (sqm)") + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer("Garden Area (sqm)") + garden_orientation = fields.Selection( + selection=[('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West')], + help="Orientation of the garden, if it exists.", + ) + active = fields.Boolean(default=True) + state = fields.Selection( + string="Status", + selection=[('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled')], + default='new', + help="State of the property.", + copy=False, + required=True, + ) + property_type_id = fields.Many2one( + comodel_name='estate.property.type', + help="Type of the property.", + ) + buyer_id = fields.Many2one( + comodel_name='res.partner', + copy=False, + help="Buyer of the property.", + ) + salesperson_id = fields.Many2one( + comodel_name='res.users', + default=lambda self: self.env.user, + help="Salesperson responsible for the property.", + ) + tag_ids = fields.Many2many( + string="Tags", + comodel_name='estate.property.tag', + help="Tags associated with the property.", + ) + offer_ids = fields.One2many( + string="Offers", + comodel_name='estate.property.offer', + inverse_name='property_id', + help="Offers made on the property.", + ) + total_area = fields.Integer( + string="Total Area (sqm)", + compute='_compute_total_area', + help="Total area of the property, including living area and garden area.", + ) + best_offer = fields.Float( + compute='_compute_best_offer', + help="Best offer made on the property.", + ) + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for property in self: + property.total_area = property.living_area + property.garden_area + + @api.depends('offer_ids.price') + def _compute_best_offer(self): + for property in self: + property.best_offer = max(property.offer_ids.mapped('price'), default=0.0) + + @api.constrains('expected_price', 'selling_price') + def _check_prices(self): + for property in self: + if ( + not float_is_zero(property.selling_price, precision_rounding=0.01) + and float_compare(property.selling_price, + 0.9 * property.expected_price, precision_rounding=0.01) < 0): + raise exceptions.ValidationError(_("The selling price cannot be lower than 90% of the expected price.")) + + @api.onchange('garden') + def _onchange_garden(self): + if not self.garden: + self.garden_area = 0 + self.garden_orientation = False + else: + self.garden_area = 10 + self.garden_orientation = 'north' + + @api.ondelete(at_uninstall=False) + def _delete_except_new_cancelled(self): + for property in self: + if property.state not in ['new', 'cancelled']: + raise exceptions.UserError(_("You can only delete properties that are new or cancelled.")) + + def action_sold(self): + for property in self: + if property.state != 'offer_accepted': + raise exceptions.UserError(_("Only properties with an accepted offer can be sold.")) + property.state = 'sold' + return True + + def action_cancel(self): + for property in self: + if property.state == 'sold': + raise exceptions.UserError(_("Sold properties cannot be cancelled.")) + property.state = 'cancelled' + return True diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..0a4fa0c2d32 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,93 @@ +from odoo import _, api, exceptions, fields, models +from odoo.tools.date_utils import add + + +class EstatePropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = 'Estate Property Offer' + _order = 'price desc' + _sql_constraints = [ + ('check_price_strictly_positive', 'CHECK(price > 0)', + 'The price of an offer should be strictly positive.'), + ] + + price = fields.Float() + status = fields.Selection( + selection=[ + ('accepted', 'Accepted'), + ('refused', 'Refused'), + ], + copy=False, + help="Status of the offer.", + ) + partner_id = fields.Many2one( + comodel_name='res.partner', + required=True, + help="Partner who made the offer.", + ) + property_id = fields.Many2one( + comodel_name='estate.property', + required=True, + help="Property for which the offer is made.", + ) + validity = fields.Integer( + string="Validity (days)", + default=7, + help="Validity period of the offer in days.", + ) + date_deadline = fields.Date( + string="Deadline", + compute='_compute_date_deadline', + inverse='_inverse_date_deadline', + store=True, + help="Deadline for the offer based on validity period.", + ) + property_type_id = fields.Many2one( + related='property_id.property_type_id', + ) + + @api.depends('validity') + def _compute_date_deadline(self): + for property_offer in self: + property_offer.date_deadline = add(fields.Date.to_date(property_offer.create_date) + or fields.Date.today(), days=property_offer.validity) + + def _inverse_date_deadline(self): + for property_offer in self: + property_offer.validity = (property_offer.date_deadline - + fields.Date.to_date(property_offer.create_date) + or fields.Date.today()).days + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + property = self.env['estate.property'].browse(vals.get('property_id')) + + if (vals.get('price') < property.best_offer): + raise exceptions.UserError( + _("The offer price must be greater than the best offer of the property.") + ) + + if property.state == 'new': + property.state = 'offer_received' + return super().create(vals_list) + + def action_accept(self): + for property_offer in self: + if (property_offer.property_id.state != 'offer_accepted'): + property_offer.status = 'accepted' + property_offer.property_id.state = 'offer_accepted' + property_offer.property_id.buyer_id = property_offer.partner_id + property_offer.property_id.selling_price = property_offer.price + + self.search( + [('property_id', 'in', property_offer.property_id.ids), + ('status', '=', False)] + ).write({'status': 'refused'}) + + return True + + def action_refuse(self): + for property_offer in self: + property_offer.status = 'refused' + return True diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..368d8b7f2fe --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = 'Estate Property Tag' + _order = 'name' + _sql_constraints = [ + ('check_name_unique', 'UNIQUE(name)', + 'The name of the property type must be unique.'), + ] + + name = fields.Char(required=True) + color = fields.Integer() diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..12e593c1436 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,36 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = 'Estate Property Type' + _order = 'sequence, name' + _sql_constraints = [ + ('check_name_unique', 'UNIQUE(name)', + 'The name of the property type must be unique.'), + ] + + name = fields.Char(required=True) + property_ids = fields.One2many( + string="Properties", + comodel_name='estate.property', + inverse_name='property_type_id', + help="Properties of this type.", + ) + sequence = fields.Integer( + default=1, + help="Sequence of the property type for ordering.", + ) + offer_ids = fields.One2many( + string="Offers", + comodel_name='estate.property.offer', + inverse_name='property_type_id', + ) + offer_count = fields.Integer( + compute='_compute_offer_count', + ) + + @api.depends('offer_ids') + def _compute_offer_count(self): + for property_type in self: + property_type.offer_count = len(property_type.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..8d418f7962b --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,13 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + string="Properties", + comodel_name='estate.property', + inverse_name='salesperson_id', + help="Properties owned by the user.", + domain=['|', ('state', '=', 'new'), ('state', '=', 'offer_received')], + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..e9bde38a35f --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_estate_user,estate.user,model_estate_property,base.group_user,1,1,1,1 +access_estate_prop_type_user,estate.property.type.user,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_prop_tag_user,estate.property.tag.user,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_prop_offer_user,estate.property.offer.user,model_estate_property_offer,base.group_user,1,1,1,1 diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..8389b129155 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..e3d1cda5d37 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,47 @@ + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + + +
+
+
+ + + estate.property.offer.list + estate.property.offer + + + + + + + +
+ + + +

+ +

+
+ + + + + + + + + + + +
+ + + + + + Property Types + estate.property.type + list,form + + \ No newline at end of file diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..c86afdc64c1 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,146 @@ + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ + +

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + + +

+ +

+ + Expected Price: + + + Best Offer:
+
+ + Selling Price: + + +
+
+
+
+
+ + + Properties + estate.property + list,form,kanban + {"search_default_available": True} + +
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..d6164f7fdf9 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.view.form.inherit.estate + res.users + + + + + + + + + + \ No newline at end of file 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..596dcb0371a --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,17 @@ +{ + 'name': "estate_account", + 'version': '1.0', + 'category': 'Sales/RealEstate', + 'summary': 'Link estate properties with accounting features.', + 'author': "Odoo S.A.", + 'description': """ + Description text + """, + 'depends': [ + 'estate', + 'account' + ], + 'installable': True, + 'application': False, + 'license': 'LGPL-3', +} 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..b8de561dc65 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,23 @@ +from odoo import Command, models + + +class EstateAccountProperty(models.Model): + _inherit = "estate.property" + + def action_sold(self): + for property_record in self: + self.env['account.move'].create( + [ + dict( + partner_id=property_record.buyer_id.id, + move_type="out_invoice", + line_ids=[ + Command.create(dict(name="6% Down Payment", quantity=1, + price_unit=0.06 * property_record.selling_price)), + Command.create(dict(name="Administrative Fees", quantity=1, price_unit=100)) + ], + + ) + ] + ) + return super().action_sold()