diff --git a/.gitignore b/.gitignore index b6e47617de1..c36a577165c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.vscode/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000000..26d33521af1 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000000..105ce2da2d6 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000000..a971a2c9313 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000000..5c1c8885418 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tutorials.iml b/.idea/tutorials.iml new file mode 100644 index 00000000000..909438d88eb --- /dev/null +++ b/.idea/tutorials.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000000..35eb1ddfbbc --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..ad070639bd0 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -23,8 +23,14 @@ ], 'assets': { 'web.assets_backend': [ - 'awesome_dashboard/static/src/**/*', + 'awesome_dashboard/static/src/dashboard/**/*', + "awesome_dashboard/static/src/dashboard/services/statistics_service.js", ], + "awesome_dashboard.dashboard": [ + "awesome_dashboard/static/src/dashboard/**/*.js", + "awesome_dashboard/static/src/dashboard/**/*.xml", + ] + }, 'license': 'AGPL-3' } diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js deleted file mode 100644 index 637fa4bb972..00000000000 --- a/awesome_dashboard/static/src/dashboard.js +++ /dev/null @@ -1,10 +0,0 @@ -/** @odoo-module **/ - -import { Component } from "@odoo/owl"; -import { registry } from "@web/core/registry"; - -class AwesomeDashboard extends Component { - static template = "awesome_dashboard.AwesomeDashboard"; -} - -registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml deleted file mode 100644 index 1a2ac9a2fed..00000000000 --- a/awesome_dashboard/static/src/dashboard.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - hello dashboard - - - diff --git a/awesome_dashboard/static/src/dashboard/dashboard.js b/awesome_dashboard/static/src/dashboard/dashboard.js new file mode 100644 index 00000000000..ed9cad8d966 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,91 @@ +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 { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; +import { AwesomeDashboardItem } from "./dashboarditem/dashboarditem"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, AwesomeDashboardItem }; + + setup() { + this.action = useService("action"); + this.statistics = useState(useService("awesome_dashboard.statistics")); + this.dialog = useService("dialog"); + this.display = { + controlPanel: {}, + }; + this.items = registry.category("awesome_dashboard_items").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"], + ], + }); + } +} + +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..70da978a4a7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard{ + background-color: #ddd; +} \ 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..eaf5e964503 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,42 @@ + + + + + + + Customers + Leads + + + + + + + + + + + + + + + + + + + + + Which cards do you whish to see ? + + + + + + + + Done + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard_action.js b/awesome_dashboard/static/src/dashboard/dashboard_action.js new file mode 100644 index 00000000000..11519c464ec --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_action.js @@ -0,0 +1,16 @@ +/** @odoo-module **/ + +import { Component, xml } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; + +export 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/dashboard/dashboard_items.js b/awesome_dashboard/static/src/dashboard/dashboard_items.js new file mode 100644 index 00000000000..922fc6797bb --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_items.js @@ -0,0 +1,68 @@ +/** @odoo-module **/ + +import { NumberCard } from "./number_card"; +import { PieChartCard } from "./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_items").add(item.id, item); +}); diff --git a/awesome_dashboard/static/src/dashboard/dashboarditem/dashboardItem.xml b/awesome_dashboard/static/src/dashboard/dashboarditem/dashboardItem.xml new file mode 100644 index 00000000000..734f9582177 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboarditem/dashboardItem.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/awesome_dashboard/static/src/dashboard/dashboarditem/dashboarditem.js b/awesome_dashboard/static/src/dashboard/dashboarditem/dashboarditem.js new file mode 100644 index 00000000000..3cb71e27835 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboarditem/dashboarditem.js @@ -0,0 +1,29 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { Layout } from "@web/search/layout"; + +export class AwesomeDashboardItem extends Component { + static template = "awesome_dashboard.AwesomeDashboardItem"; + static components = { Layout }; + static props = { + slots: { + type: Object, + shape: { + default: Object, + }, + }, + size: { + type: Number, + default: 1, + optional: true, + }, + }; + + setup() {} +} + +registry + .category("actions") + .add("awesome_dashboard.dashboardItem", AwesomeDashboardItem); diff --git a/awesome_dashboard/static/src/dashboard/number_card.js b/awesome_dashboard/static/src/dashboard/number_card.js new file mode 100644 index 00000000000..bc00479cc9f --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/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, + }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/number_card.xml b/awesome_dashboard/static/src/dashboard/number_card.xml new file mode 100644 index 00000000000..73bc3cac926 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/number_card.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart.js b/awesome_dashboard/static/src/dashboard/pie_chart.js new file mode 100644 index 00000000000..04476e331fc --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart.js @@ -0,0 +1,47 @@ +import { loadJS } from "@web/core/assets"; +import { getColor } from "@web/core/colors/colors"; +import { + Component, + onWillStart, + useRef, + onMounted, + onWillUnmount, +} from "@odoo/owl"; + +export class PieChart extends Component { + static template = "awesome_dashboard.PieChart"; + static props = { + label: String, + data: Object, + }; + + setup() { + this.canvasRef = useRef("canvas"); + onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onMounted(() => { + this.renderChart(); + }); + onWillUnmount(() => { + this.chart.destroy(); + }); + } + + renderChart() { + const labels = Object.keys(this.props.data); + const data = Object.values(this.props.data); + const color = labels.map((_, index) => getColor(index)); + this.chart = new Chart(this.canvasRef.el, { + type: "pie", + data: { + labels: labels, + datasets: [ + { + label: this.props.label, + data: data, + backgroundColor: color, + }, + ], + }, + }); + } +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart.xml b/awesome_dashboard/static/src/dashboard/pie_chart.xml new file mode 100644 index 00000000000..18416e9a223 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card.js b/awesome_dashboard/static/src/dashboard/pie_chart_card.js new file mode 100644 index 00000000000..62900bd76d4 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card.js @@ -0,0 +1,15 @@ +import { Component } from "@odoo/owl"; +import { PieChart } from "./pie_chart"; + +export class PieChartCard extends Component { + static template = "awesome_dashboard.PieChartCard"; + static components = { PieChart }; + static props = { + title: { + type: String, + }, + values: { + type: Object, + }, + }; +} diff --git a/awesome_dashboard/static/src/dashboard/pie_chart_card.xml b/awesome_dashboard/static/src/dashboard/pie_chart_card.xml new file mode 100644 index 00000000000..b8c94bebb64 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart_card.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/services/statistics_service.js b/awesome_dashboard/static/src/dashboard/services/statistics_service.js new file mode 100644 index 00000000000..6a52d50c4c7 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/services/statistics_service.js @@ -0,0 +1,23 @@ +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 * 60 * 1000); + loadData(); + + return statistics; + }, +}; + +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..3e77501e1d5 --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,15 @@ +/** @odoo-module **/ + +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + + setup() { + this.state = useState({ open: true }); + } + + toggle() { + this.state.open = !this.state.open; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..be00e0414fc --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..1fbf4849e5f --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,22 @@ +/** @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..249f86a3d21 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,9 @@ + + + + + Counter: + Increment + + + \ No newline at end of file diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..edb691dfef7 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,29 @@ /** @odoo-module **/ -import { Component } from "@odoo/owl"; - +import { Component, useState } from "@odoo/owl"; +import { Card } from "./card/card"; +import { Counter } from "./counter/counter"; +import { TodoList } from "./todo/todoList"; export class Playground extends Component { - static template = "awesome_owl.playground"; + static template = "awesome_owl.playground"; + static components = { Counter, Card, TodoList }; + + setup() { + this.state = useState({ + counter1: 0, + counter2: 0, + }); + } + + onCounter1Change(newValue) { + this.state.counter1 = newValue; + } + + onCounter2Change(newValue) { + this.state.counter2 = newValue; + } + + get sum() { + return this.state.counter1 + this.state.counter2; + } } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..2ea13f45e9d 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -2,9 +2,25 @@ - - hello world - + + + Todo List + + + + + + + + + Counters + + + + + + - + + \ No newline at end of file diff --git a/awesome_owl/static/src/todo/todoItem.js b/awesome_owl/static/src/todo/todoItem.js new file mode 100644 index 00000000000..52b5b096aa7 --- /dev/null +++ b/awesome_owl/static/src/todo/todoItem.js @@ -0,0 +1,37 @@ +/** @odoo-module **/ + +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + todo: { + type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean, + }, + optional: false, + }, + toggleState: { type: Function, optional: false }, + removeTodo: { type: Function, optional: false }, + }; + + onCheckboxChange() { + this.props.toggleState(this.props.todo.id); + } + + onDeleteClick() { + this.props.removeTodo(this.props.todo.id); + } + + toggleCompletion() { + const newTodo = { + ...this.props.todo, + isCompleted: !this.props.todo.isCompleted, + }; + this.props.onChange(newTodo); + } +} diff --git a/awesome_owl/static/src/todo/todoItem.xml b/awesome_owl/static/src/todo/todoItem.xml new file mode 100644 index 00000000000..1ed354e122a --- /dev/null +++ b/awesome_owl/static/src/todo/todoItem.xml @@ -0,0 +1,15 @@ + + + + + + + ID: + + Description: + + + + + + \ No newline at end of file diff --git a/awesome_owl/static/src/todo/todoList.js b/awesome_owl/static/src/todo/todoList.js new file mode 100644 index 00000000000..1744c76d93b --- /dev/null +++ b/awesome_owl/static/src/todo/todoList.js @@ -0,0 +1,67 @@ +/** @odoo-module **/ + +import { Component, useState, useRef, onMounted } from "@odoo/owl"; +import { TodoItem } from "./todoItem"; + +function useAutoFocus(refName) { + let inputRef = useRef(refName); + onMounted(() => { + inputRef.el.focus(); + }); +} + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static components = { TodoItem }; + + setup() { + this.todos = useState([]); + this.state = useState({ text: "" }); + this.todosId = useState({ value: 1 }); + useAutoFocus("new_task_input"); + } + + _updateInputValue(event) { + this.state.text = event.target.value; + } + + checkPressedKey(e) { + const value = e.target.value; + if (value) { + if (e.key === "Enter") { + this.addTodo(); + } + } + } + + addTodo() { + const newTodo = { + id: this.todosId.value, + description: this.state.text, + isCompleted: false, + }; + this.todos.push(newTodo); + this.todosId.value++; + } + + toggleCompletion(updatedTodo) { + const index = this.todos.findIndex((t) => t.id === updatedTodo.id); + if (index !== -1) { + this.todos[index].isCompleted = updatedTodo.isCompleted; + } + } + + 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 !== -1) { + this.todos.splice(index, 1); + } + } +} diff --git a/awesome_owl/static/src/todo/todoList.xml b/awesome_owl/static/src/todo/todoList.xml new file mode 100644 index 00000000000..cc2d4fc4b3a --- /dev/null +++ b/awesome_owl/static/src/todo/todoList.xml @@ -0,0 +1,15 @@ + + + + + + Write your todo: + Add + + + + + + + + \ No newline at end of file diff --git a/estate/__init__.py b/estate/__init__.py new file mode 100644 index 00000000000..9a7e03eded3 --- /dev/null +++ b/estate/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/estate/__manifest__.py b/estate/__manifest__.py new file mode 100644 index 00000000000..a2f0f5b8caf --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,16 @@ +{ + 'name': 'Estate', + 'depends': [ + 'base_setup', + ], + 'data':[ + 'security/ir.model.access.csv', + 'views/inherited_res_users_views.xml', + 'views/estate_property_tag_views.xml', + 'views/estate_property_offer_views.xml', + 'views/estate_property_type_views.xml', + 'views/estate_property_views.xml', + 'views/estate_menus.xml', + ], + 'application': True +} \ No newline at end of file diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..30a7d7353cf --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,2 @@ +from . import (estate_property, estate_property_offer, estate_property_tag, + estate_property_type, inherited_res_users) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..999e6d5a2ab --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,132 @@ +from datetime import date + +from dateutil.relativedelta import relativedelta +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 = "Store Real Estate Properties" + _order = "id desc" + # SQL Constraints + _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.", + ), + ("unique_name", "UNIQUE(name)", "The name must be unique."), + ] + + name = fields.Char("Estate Name", required=True) + description = fields.Text(help="Enter the real estate item description") + postcode = fields.Char("Postcode") + date_availability = fields.Date( + "Available From", + copy=False, + default=lambda self: date.today() + relativedelta(months=3), + ) + expected_price = fields.Float(digits="Product Price") + selling_price = fields.Float(digits="Product Price", copy=False, readonly=True) + bedrooms = fields.Integer(default=2, help="Number of bedrooms in the property") + living_area = fields.Integer("Living Area (m²)") + facades = fields.Integer(help="Number of building facades") + garage = fields.Boolean(default=False) + garden = fields.Boolean(default=False) + garden_area = fields.Integer("Garden Area (m²)") + garden_orientation = fields.Selection( + [("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], + help="Direction the garden faces", + ) + active = fields.Boolean(default=True) + state = fields.Selection( + [ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + copy=False, + default="new", + ) + + note = fields.Text("Special mentions about the house") + + # Relations + 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="Property Tags") + offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") + + # Computed fields + total_area = fields.Float(compute="_compute_total_area") + best_price = fields.Float(string="Best Offer", compute="_compute_best_price") + + @api.ondelete(at_uninstall=False) + def _check_can_be_deleted(self): + for estate in self: + if estate.state not in ["new", "cancelled"]: + raise UserError(_("Only 'new' or 'cancelled' properties can be deleted.")) + + # Computed functions + @api.depends("living_area", "garden_area") + def _compute_total_area(self): + for estate in self: + estate.total_area = estate.living_area + estate.garden_area + + @api.depends("offer_ids.price") + def _compute_best_price(self): + for estate in self: + prices = estate.offer_ids.mapped("price") + estate.best_price = max(prices, default=0.0) + + @api.onchange("garden") + def _onchange_garden(self): + if self.garden: + self.garden_area = 10 + self.garden_orientation = "north" + else: + self.garden_area = 0 + self.garden_orientation = False + + # Python Constraints + @api.constrains("expected_price", "selling_price") + def _check_selling_price(self): + for estate in self: + if not float_is_zero(estate.selling_price, precision_digits=2): + min_acceptable = estate.expected_price * 0.9 + if ( + float_compare( + estate.selling_price, min_acceptable, precision_digits=2 + ) + < 0 + ): + raise ValidationError( + "Selling price cannot be lower than 90% of the expected price." + ) + + # Actions + def action_set_sold(self): + for estate in self: + if estate.state == "cancelled": + raise UserError(_("Cancelled properties cannot be sold.")) + estate.state = "sold" + return True + + def action_set_cancelled(self): + for estate in self: + if estate.state == "sold": + raise UserError(_("Sold properties cannot be cancelled.")) + estate.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..f4076f317c8 --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,111 @@ +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" + # SQL Constraints + _sql_constraints = [ + ( + "check_offer_price_positive", + "CHECK(price > 0)", + "The offer price must be strictly positive.", + ) + ] + + validity = fields.Integer( + "Valid For", default=7, help="Number of days until this offer expires" + ) + + price = fields.Float(string="Offer Price") + status = fields.Selection( + [("accepted", "Accepted"), ("refused", "Refused")], string="Status", copy=False + ) + # Relational Fields + partner_id = fields.Many2one("res.partner", string="Buyer", required=True) + property_id = fields.Many2one("estate.property", string="Property", required=True) + property_type_id = fields.Many2one( + "estate.property.type", + string="Property Type", + related="property_id.property_type_id", + store=True, + readonly=True, + ) + # Computed fields + date_deadline = fields.Datetime( + compute="_compute_date_deadline", inverse="_inverse_date_deadline" + ) + + @api.model + def create(self, vals): + # Fetch the property ID from the incoming data + property_id = vals.get("property_id") + new_offer_price = vals.get("price") + + # Safeguard in case required data is missing + if not property_id or not new_offer_price: + raise ValidationError(_("Both price and property must be provided.")) + + # Get the actual property record + property_rec = self.env["estate.property"].browse(property_id) + + # Compare offer price with existing offers + existing_prices = property_rec.offer_ids.mapped("price") + if existing_prices and new_offer_price < max(existing_prices): + raise ValidationError(_("Offer must be higher than existing offers.")) + + # Update property state if needed + if property_rec.state == "new": + property_rec.state = "offer_received" + + # Create the offer + return super().create(vals) + + # Computed functions + @api.depends("validity") + def _compute_date_deadline(self): + for estate_offer in self: + create_date = estate_offer.create_date or fields.Date.today() + estate_offer.date_deadline = create_date + timedelta( + days=estate_offer.validity + ) + + def _inverse_date_deadline(self): + for estate_offer in self: + create_date = estate_offer.create_date or fields.Date.today() + if estate_offer.date_deadline: + delta = estate_offer.date_deadline - create_date + estate_offer.validity = delta.days + + # Actions + def action_accept_offer(self): + for offer in self: + if offer.property_id.state == "sold": + raise UserError(_("You cannot accept an offer on a sold property.")) + if offer.property_id.state == "offer_accepted": + raise UserError( + _("An offer has already been accepted for this property.") + ) + + offer.status = "accepted" + offer.property_id.buyer_id = offer.partner_id + offer.property_id.selling_price = offer.price + offer.property_id.state = "offer_accepted" + + # Refuse all other offers + other_offers = offer.property_id.offer_ids - offer + other_offers.write({"status": "refused"}) + return True + + def action_refuse_offer(self): + for offer in self: + if offer.status == "accepted": + raise UserError( + _("You cannot refuse an offer that has already been accepted.") + ) + 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..d884aee4b76 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Store Real Estate Properties Tags" + _order = "name" + # SQL Constraints + _sql_constraints = [("unique_name", "UNIQUE(name)", "The tag must be unique.")] + + name = fields.Char("Estate Type Tag", required=True, translate=True) + color = fields.Integer("Color") \ No newline at end of file diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..4f15cd4846d --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,29 @@ +from odoo import api, fields, models + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Store Real Estate Properties Types" + _order = "sequence, name" + + name = fields.Char("Estate Type Name", required=True, translate=True) + sequence = fields.Integer(default=1, help="Used to order property types. Lower is better.") + offer_count = fields.Integer(compute='_compute_offer_count') + + # Relations + property_ids = fields.One2many( + "estate.property", "property_type_id", string="Properties" + ) + offer_ids = fields.One2many( + 'estate.property.offer', + 'property_type_id', + string="Offers" + ) + + # Computed Functions + @api.depends('offer_ids') + def _compute_offer_count(self): + for estate_type in self: + estate_type.offer_count = len(estate_type.offer_ids) + _sql_constraints = [ + ('unique_type_name', 'UNIQUE(name)', 'The property type name must be unique.') + ] \ No newline at end of file diff --git a/estate/models/inherited_res_users.py b/estate/models/inherited_res_users.py new file mode 100644 index 00000000000..916c561318f --- /dev/null +++ b/estate/models/inherited_res_users.py @@ -0,0 +1,11 @@ +from odoo import models, fields + +class ResUsers(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", + "salesperson_id", + string="Properties", + domain=[("state", "=", "new")], + ) \ No newline at end of file diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..f23056ab1a5 --- /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_model,access_estate_model,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type_model,access_estate_property_type_model,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag_model,access_estate_property_tag_model,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer_model,access_estate_property_offer_model,model_estate_property_offer,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml new file mode 100644 index 00000000000..3fec9ea9015 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ 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..f0fa7169256 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,30 @@ + + + + estate.property.offer.tree + estate.property.offer + + + + + + + + + + + + + + Offers + estate.property.offer + tree,form + [('property_type_id', '=', context.get('default_property_type_id'))] + {} + + + \ No newline at end of file diff --git a/estate/views/estate_property_tag_views.xml b/estate/views/estate_property_tag_views.xml new file mode 100644 index 00000000000..c8a769b61c8 --- /dev/null +++ b/estate/views/estate_property_tag_views.xml @@ -0,0 +1,31 @@ + + + + Estate Property Tag + estate.property.tag + list,form + + + + estate.property.tag.list + estate.property.tag + + + + + + + + + estate.property.tag.form + estate.property.tag + + + + + + + + + + \ No newline at end of file diff --git a/estate/views/estate_property_type_views.xml b/estate/views/estate_property_type_views.xml new file mode 100644 index 00000000000..d4f986ecb4c --- /dev/null +++ b/estate/views/estate_property_type_views.xml @@ -0,0 +1,61 @@ + + + + Estate Property Type + estate.property.type + list,form + + + + estate.property.type.list + estate.property.type + + + + + + + + + + + + estate.property.type.form + estate.property.type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..9eca0936c9f --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,161 @@ + + + + Estate Property + estate.property + kanban,list,form + {'search_default_availability': True} + + + + estate.property.kanban + estate.property + + + + + + + + + + + + + + + + + + + Expected: + + + + + Best Offer: + + + + + Selling Price: + + + + + State: + + + + + + + + + + + + estate.property.list + estate.property + + + + + + + + + + + + + + + + estate.property.form + estate.property + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/estate/views/inherited_res_users_views.xml b/estate/views/inherited_res_users_views.xml new file mode 100644 index 00000000000..ea20eaeebfd --- /dev/null +++ b/estate/views/inherited_res_users_views.xml @@ -0,0 +1,20 @@ + + + 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..9a7e03eded3 --- /dev/null +++ b/estate_account/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py new file mode 100644 index 00000000000..a6c9ea4f00c --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,7 @@ +{ + "name": "Estate Account", + "depends": ["estate", "account"], + "data": [], + "application": True, + "description": "Create invoices when estate properties are sold", +} diff --git a/estate_account/models/__init__.py b/estate_account/models/__init__.py new file mode 100644 index 00000000000..f4c8fd6db6d --- /dev/null +++ b/estate_account/models/__init__.py @@ -0,0 +1 @@ +from . import estate_property \ No newline at end of file diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py new file mode 100644 index 00000000000..b07f9f35f4a --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,40 @@ +from odoo import Command, _, models + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_set_sold(self): + res = super().action_set_sold() + + for property in self: + if not property.buyer_id: + continue + + commission = property.selling_price * 0.06 + admin_fee = 100.00 + + invoice_vals = { + "partner_id": property.buyer_id.id, + "move_type": "out_invoice", + "invoice_line_ids": [ + Command.create( + { + "name": _("6% Commission"), + "quantity": 1, + "price_unit": commission, + } + ), + Command.create( + { + "name": _("Administrative Fees"), + "quantity": 1, + "price_unit": admin_fee, + } + ), + ], + } + + invoice = self.env["account.move"].create(invoice_vals) + + return res