diff --git a/awesome_dashboard/__manifest__.py b/awesome_dashboard/__manifest__.py index 31406e8addb..db9befa8c5e 100644 --- a/awesome_dashboard/__manifest__.py +++ b/awesome_dashboard/__manifest__.py @@ -17,14 +17,17 @@ 'application': True, 'installable': True, 'depends': ['base', 'web', 'mail', 'crm'], - 'data': [ 'views/views.xml', ], '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' + '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..c2f1d958e8c --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.js @@ -0,0 +1,38 @@ +/** @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 { PieChart } from "./pie_chart/pie_chart"; + +class AwesomeDashboard extends Component { + static template = "awesome_dashboard.AwesomeDashboard"; + static components = { Layout, DashboardItem, PieChart } ; + + setup(){ + this.actions = useService("action"); + this.statisticsService = useService("awesome_dashboard.statistics"); + this.statistics = useState(this.statisticsService.statistics) + this.display = { controlPanel: {} }; + } + + openCustomersView(){ + this.actions.doAction("base.action_partner_form"); + } + + openAllLeads(){ + this.actions.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); \ No newline at end of file diff --git a/awesome_dashboard/static/src/dashboard/dashboard.scss b/awesome_dashboard/static/src/dashboard/dashboard.scss new file mode 100644 index 00000000000..15f19d2497a --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.scss @@ -0,0 +1,3 @@ +.o_dashboard{ + background-color: grey; +} \ 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..efb3e6c2282 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard.xml @@ -0,0 +1,49 @@ + + + + + + + + + +
+ + Average amount of t-shirt by order this month +
+ +
+
+ + Average time for an order to go from 'new' to 'sent' or 'cancelled' +
+ +
+
+ + Number of new orders this month +
+ +
+
+ + Number of cancelled orders this month +
+ +
+
+ + Total amount of new orders this month +
+ +
+
+ + Shirt orders by size + + +
+
+
+ +
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..48da234c514 --- /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..baa15f159c4 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/dashboard_item/dashboard_item.xml @@ -0,0 +1,12 @@ + + + + +
+
+ +
+
+
+ +
\ 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..c7891986de3 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.js @@ -0,0 +1,43 @@ +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(() => { + if(this.chart){ + 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, + }, + ], + }, + }); + } +} \ 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..ab0fd353aff --- /dev/null +++ b/awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.xml @@ -0,0 +1,8 @@ + + + +
+ +
+
+
diff --git a/awesome_dashboard/static/src/dashboard_loader.js b/awesome_dashboard/static/src/dashboard_loader.js new file mode 100644 index 00000000000..d06527b2283 --- /dev/null +++ b/awesome_dashboard/static/src/dashboard_loader.js @@ -0,0 +1,18 @@ +/** @odoo-module **/ + +import { Component, xml } from "@odoo/owl"; +import { registry } from "@web/core/registry"; +import { LazyComponent } from "@web/core/assets"; + +export class DashboardLoader extends Component { + static components = { LazyComponent }; + static template = xml` + + `; +} + +registry.category("actions").add("awesome_dashboard.dashboard", DashboardLoader); \ No newline at end of file diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js new file mode 100644 index 00000000000..0f7b607138b --- /dev/null +++ b/awesome_dashboard/static/src/statistics_service.js @@ -0,0 +1,26 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { reactive } from "@odoo/owl"; +import { rpc } from "@web/core/network/rpc"; + +const statisticsService = { + start() { + const statistics = reactive({}); + + async function loadStatistics(){ + const data = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics,data); + } + + loadStatistics(); + setInterval(loadStatistics, 10*60*1000); + + return { + statistics, + }; + }, +}; + +// Register the service +registry.category("services").add("awesome_dashboard.statistics", statisticsService); \ 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..36e06bf4cc1 --- /dev/null +++ b/awesome_owl/static/src/Card/card.js @@ -0,0 +1,19 @@ +import { Component , useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.Card"; + + static props = { + title: String, + // content: { type: String, optional: true}, + slots: Object + }; + + 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..bc5a3618cc3 --- /dev/null +++ b/awesome_owl/static/src/Card/card.xml @@ -0,0 +1,29 @@ + + + + + +
+
+ + +
+
+ +
+ +
+ + + + + +
+
+
+ +
diff --git a/awesome_owl/static/src/Counter/counter.js b/awesome_owl/static/src/Counter/counter.js new file mode 100644 index 00000000000..d997b00fe95 --- /dev/null +++ b/awesome_owl/static/src/Counter/counter.js @@ -0,0 +1,18 @@ +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({count: 0}); + } + + increment() { + if(this.props.onChange) { + this.props.onChange(); + } + this.state.count++; + } +} \ 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..a473b75dfe8 --- /dev/null +++ b/awesome_owl/static/src/Counter/counter.xml @@ -0,0 +1,16 @@ + + + + + + +

Counter:

+ + +
+ +
diff --git a/awesome_owl/static/src/TodoList/todo_item.js b/awesome_owl/static/src/TodoList/todo_item.js new file mode 100644 index 00000000000..9f98e0360ad --- /dev/null +++ b/awesome_owl/static/src/TodoList/todo_item.js @@ -0,0 +1,13 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.TodoItem"; + + static props = { + id: Number, + description: String, + isCompleted: Boolean, + toggleState: Function, // callback to toggle the state + removeTodo: Function // callback to remove the todo + }; +} \ No newline at end of file diff --git a/awesome_owl/static/src/TodoList/todo_item.xml b/awesome_owl/static/src/TodoList/todo_item.xml new file mode 100644 index 00000000000..6503d630e68 --- /dev/null +++ b/awesome_owl/static/src/TodoList/todo_item.xml @@ -0,0 +1,41 @@ + + + + + +
+ + +
+ + + + + + + + + + + +
+ + +
+ Done + Pending + + + +
+
+
+
diff --git a/awesome_owl/static/src/TodoList/todo_list.js b/awesome_owl/static/src/TodoList/todo_list.js new file mode 100644 index 00000000000..5dc4ee5bcf7 --- /dev/null +++ b/awesome_owl/static/src/TodoList/todo_list.js @@ -0,0 +1,45 @@ +import { Component ,useState} from "@odoo/owl"; +import { TodoItem } from "./todo_item"; +import { useAutoFocus } from "../utils"; + +export class TodoList extends Component { + static template = "awesome_owl.TodoList"; + static props = {}; + static components = { TodoItem }; + + setup() { + this.todos = useState([]); + this.nextId = 1; + + // hook will automatically focus the input on mount + this.inputRef = useAutoFocus("taskInput"); + } + + addTodo(ev) { + // Check if Enter was pressed + if (ev.keyCode === 13 && ev.target.value.trim() !== "") { + this.todos.push({ + id: this.nextId++, + description: ev.target.value.trim(), + isCompleted: false, + }); + // Clear input + ev.target.value = ""; + } + } + + toggleState(id) { + const todo = this.todos.find(t => t.id === id); + if (todo) { + todo.isCompleted = !todo.isCompleted; + } + } + + removeTodo(id) { + const index = this.todos.findIndex((elem) => elem.id === id); + if (index >= 0) { + // remove the element at index from list + this.todos.splice(index, 1); + } + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/TodoList/todo_list.xml b/awesome_owl/static/src/TodoList/todo_list.xml new file mode 100644 index 00000000000..2fe0dde1dba --- /dev/null +++ b/awesome_owl/static/src/TodoList/todo_list.xml @@ -0,0 +1,48 @@ + + + + +
+ +
+ Todo List +
+ + +
+ +
+ +
+ + +
    + + + + +
  • + +
  • +
    +
    + + +
  • + No tasks yet. +
  • +
    +
+
+
+
+
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 657fb8b07bb..9a6d9fd2194 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,7 +1,25 @@ /** @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 "./TodoList/todo_list"; export class Playground extends Component { static template = "awesome_owl.playground"; -} + + static props = {}; + + // Register Counter so it can be used in the template + static components = { Counter , Card , TodoList }; + + setup() { + this.content_1 = markup("
This is safe HTML
"); + this.content_2 = "
This will be escaped
"; + this.state = useState({ sum: 0 }); + } + + incrementSum() { + this.state.sum++; + } +} \ No newline at end of file diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..80d09777c2e 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -1,9 +1,34 @@ +
- hello world + Playground +
+ +
+ + + +

The sum is:

+
+
+ +
+ + + + + + + +
+ +
+
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..c361bf79dc2 --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,9 @@ +import { onMounted, useRef } from "@odoo/owl"; + +export function useAutoFocus(refName) { + let elementRef = useRef(refName); + onMounted(() => { + elementRef.el.focus(); + }); + return elementRef; +} 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..fce12b8b8f9 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,26 @@ +{ + "name": "Real Estate", + "description": "", + "category": "Real Estate/Brokerage", + "depends": ["base"], + "sequence": 1, + "data": [ + "security/security.xml", + "security/ir.model.access.csv", + "data/ir_cron_data.xml", + "views/estate_property_views.xml", + "views/estate_property_offer_views.xml", + "views/estate_property_type_views.xml", + "views/estate_property_tag_views.xml", + "views/estate_menus.xml", + "views/res_users_views.xml", + ], + "assets": { + "web.assets_backend": [ + "estate/static/src/css/custom.css", + ], + }, + "license": "LGPL-3", + "application": True, + "installable": True, +} diff --git a/estate/data/ir_cron_data.xml b/estate/data/ir_cron_data.xml new file mode 100644 index 00000000000..f2a435c2583 --- /dev/null +++ b/estate/data/ir_cron_data.xml @@ -0,0 +1,15 @@ + + + + + Expire Property Offers + + code + model._cron_refuse_expired_offers() + + 1 + days + 2025-08-26 18:30:00 + + + diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..9a2189b6382 --- /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..37230c8cf1d --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,162 @@ +from datetime import timedelta +from odoo import models, fields, api +from odoo.exceptions import ValidationError, UserError +from odoo.tools import float_is_zero, float_compare + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Estate Property" + _order = "id desc" + + _sql_constraints = [ + ( + "check_expected_price", + "CHECK(expected_price > 0)", + "The expected price must be greater than 0.", + ), + ] + + name = fields.Char(string="Name", required=True) + description = fields.Text(string="Description") + active = fields.Boolean( + string="Active", + default=True, + help="Mark as active if you want the property to be listed.", + ) + postcode = fields.Char(string="Postcode") + property_type_id = fields.Many2one("estate.property.type", string="Property Type") + date_availability = fields.Date( + string="Available From", + default=fields.Date.today() + timedelta(days=90), + copy=False, + ) + expected_price = fields.Float(string="Expected Price", required=True) + selling_price = fields.Float(string="Selling Price", readonly=True, copy=False) + bedrooms = fields.Integer(string="Bedrooms", default=2) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer(string="Facades") + garage = fields.Boolean(string="Garage") + garden = fields.Boolean(string="Garden") + garden_area = fields.Integer(string="Garden Area (sqm)") + garden_orientation = fields.Selection( + string="Garden Orientation", + selection=[ + ("north", "North"), + ("south", "South"), + ("east", "East"), + ("west", "West"), + ], + ) + total_area = fields.Integer( + string="Total Area (sqm)", + compute="_compute_total_area", + ) + state = fields.Selection( + string="State", + required=True, + default="new", + copy=False, + selection=[ + ("new", "New"), + ("offer_received", "Offer Received"), + ("offer_accepted", "Offer Accepted"), + ("sold", "Sold"), + ("cancelled", "Cancelled"), + ], + ) + salesman_id = fields.Many2one( + "res.users", string="Salesman", default=lambda self: self.env.user + ) + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False, readonly=True) + tag_ids = fields.Many2many( + "estate.property.tag", + string="Tags", + help="Properties associated with this tag.", + ) + offer_ids = fields.One2many( + "estate.property.offer", + "property_id", + string="Offers", + help="Offers made on this property.", + ) + best_price = fields.Float( + string="Best Offer", + compute="_compute_best_price", + ) + company_id = fields.Many2one( + "res.company", + required=True, + default=lambda self: self.env.company, + string="Agency", + ) + + @api.depends("living_area", "garden_area", "garden") + def _compute_total_area(self): + for property in self: + property.total_area = property.living_area + ( + property.garden_area if property.garden else 0 + ) + + @api.depends("offer_ids.price") + def _compute_best_price(self): + for property in self: + property.best_price = max(property.offer_ids.mapped("price"), default=0.0) + + @api.constrains("selling_price", "expected_price") + def _check_selling_price(self): + for property in self: + if float_is_zero(property.selling_price, precision_rounding=2): + continue + + if ( + float_compare( + property.selling_price, + property.expected_price * 0.9, + precision_rounding=2, + ) + < 0 + ): + raise ValidationError( + "The selling price cannot be lower than 90'%' of the expected price!" + ) + + @api.onchange("garden") + def _onchange_garden(self): + for property in self: + if property.garden: + property.garden_area = 10 + property.garden_orientation = "north" + else: + property.garden_area = 0 + property.garden_orientation = False + + @api.ondelete(at_uninstall=False) + def _unlink_check(self): + for property in self: + if property.state not in ["new", "cancelled"]: + raise UserError( + "You cannot delete a property that is not new or cancelled." + ) + + def action_set_sold(self): + for property in self: + if property.selling_price > 0.0 and property.state != "cancelled": + property.state = "sold" + elif property.state == "cancelled": + raise UserError("A cancelled property cannot be sold.") + elif property.state == "new" or property.state == "offer_received": + raise UserError( + "This property must have an accepted offer before it can be sold." + ) + elif property.state == "sold": + raise UserError("This property is already sold.") + + def action_set_cancelled(self): + for property in self: + if property.state != "cancelled" and property.state != "sold": + property.state = "cancelled" + elif property.state == "cancelled": + raise UserError("This property is already cancelled.") + elif property.state == "sold": + raise UserError("A sold property cannot be cancelled.") diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..b1c701cac9b --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,114 @@ +from datetime import timedelta +from odoo import models, fields, api +from odoo.exceptions import UserError + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Estate Property Offer" + _order = "price desc" + + _sql_constraints = [ + ("check_price", "CHECK(price > 0)", "The price must be greater than 0."), + ] + + price = fields.Float(string="Price") + status = fields.Selection( + string="Status", + selection=[ + ("accepted", "Accepted"), + ("refused", "Refused"), + ], + ) + validity = fields.Integer( + string="Validity(days)", + default=7, + help="Validity of the offer in days, after that it will be refused automatically.", + ) + date_deadline = fields.Date( + string="Deadline", + compute="_compute_date_deadline", + inverse="_inverse_date_deadline", + store=True, + ) + partner_id = fields.Many2one("res.partner", string="Partner", required=True) + property_id = fields.Many2one("estate.property", string="Property", required=True) + property_type_id = fields.Many2one( + "estate.property.type", + string="Property Type", + related="property_id.property_type_id", + store=True, + ) + + @api.depends("validity") + def _compute_date_deadline(self): + for offer in self: + base_date = ( + fields.Date.to_date(offer.create_date) + if offer.create_date + else fields.Date.context_today(offer) + ) + offer.date_deadline = base_date + timedelta(days=offer.validity or 0) + + def _inverse_date_deadline(self): + for offer in self: + if offer.date_deadline: + base_date = ( + fields.Date.to_date(offer.create_date) + if offer.create_date + else fields.Date.context_today(offer) + ) + offer.validity = (offer.date_deadline - base_date).days + else: + offer.validity = 0 + + @api.model_create_multi + def create(self, vals_list): + for record in vals_list: + property = self.env["estate.property"].browse(record["property_id"]) + + if record.get("price") < property.best_price: + raise UserError( + "You cannot create an offer lower than an existing one." + ) + + property.state = "offer_received" + return super().create(vals_list) + + @api.model + def _cron_refuse_expired_offers(self): + today = fields.Date.context_today(self) + expired_offers = self.search( + [ + ("status", "!=", "accepted"), + ("date_deadline", "<=", today), + ] + ) + expired_offers.write({"status": "refused"}) + + def action_set_accepted(self): + for offer in self: + if offer.property_id.selling_price == 0.0: + offer.write({"status": "accepted"}) + + offer.property_id.write( + { + "state": "offer_accepted", + "selling_price": offer.price, + "buyer_id": offer.partner_id.id, + } + ) + + other_offers = offer.property_id.offer_ids - offer + + other_offers.write({"status": "refused"}) + else: + raise UserError("One offer is already accepted for this property.") + + def action_set_refused(self): + for offer in self: + if offer.status == "accepted": + offer.property_id.state = "offer_received" + offer.property_id.buyer_id = False + offer.property_id.selling_price = 0.0 + offer.status = "refused" diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..00356afe988 --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import models, fields + + +class EstatePropertyTag(models.Model): + _name = "estate.property.tag" + _description = "Estate Property Tag" + _order = "name asc" + + _sql_constraints = [ + ("unique_name", "UNIQUE(name)", "A tag with same name is already exists."), + ] + + name = fields.Char(string="Tag Name", required=True) + description = fields.Text(string="Description") + color = fields.Integer(string="Color") diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..393cb200e33 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,28 @@ +from odoo import models, fields, api + + +class EstatePropertyType(models.Model): + _name = "estate.property.type" + _description = "Estate Property Type" + _order = "sequence,name" + + _sql_constraints = [ + ("unique_name", "UNIQUE(name)", "A type with same name is already exists."), + ] + + name = fields.Char(required=True) + property_ids = fields.One2many( + comodel_name="estate.property", + inverse_name="property_type_id", + string="Properties", + ) + offer_ids = fields.One2many("estate.property.offer", "property_type_id") + sequence = fields.Integer( + "Sequence", default=1, help="Used to order types. Lower is better." + ) + offer_count = fields.Integer("Offers", compute="_compute_offer_count") + + @api.depends("offer_ids") + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..d498c977709 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResUser(models.Model): + _inherit = "res.users" + + property_ids = fields.One2many( + "estate.property", + "salesman_id", + string="Properties", + domain=[("state", "in", ["new", "offer_received"])], + ) diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..858c89435f6 --- /dev/null +++ b/estate/security/ir.model.access.csv @@ -0,0 +1,11 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_estate_property,estate.property,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_manager,estate.property.manager,model_estate_property,estate_group_manager,1,1,1,1 +access_estate_property_type_manager,estate.property.type.manager,model_estate_property_type,estate_group_manager,1,1,1,1 +access_estate_property_tag_manager,estate.property.tag.manager,model_estate_property_tag,estate_group_manager,1,1,1,1 +access_estate_property_offer_manager,estate.property.offer.manager,model_estate_property_offer,estate_group_manager,1,1,1,1 + +access_estate_property_user,estate.property.user,model_estate_property,estate_group_user,1,1,1,0 +access_estate_property_offer_user,estate.property.offer.user,model_estate_property_offer,estate_group_user,1,1,1,0 +access_estate_property_type_user,estate.property.type.user,model_estate_property_type,estate_group_user,1,0,0,0 +access_estate_property_tag_user,estate.property.tag.user,model_estate_property_tag,estate_group_user,1,0,0,0 \ No newline at end of file diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 00000000000..0412fd7f620 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,38 @@ + + + + Agent + + + + + Manager + + + + + + + Estate property view to specific user + + + + + ['|', ('salesman_id', '=', user.id),('salesman_id', '=', False)] + + + + Estate property view to specific manager + + + + + + + Estate Property Multi-Company Rule + + + ['|', ('company_id', '=', False),('company_id', 'in', company_ids)] + + + diff --git a/estate/static/src/css/custom.css b/estate/static/src/css/custom.css new file mode 100644 index 00000000000..d8ea469c7b6 --- /dev/null +++ b/estate/static/src/css/custom.css @@ -0,0 +1,12 @@ +/* Apply only inside this specific list view */ +/* Left-align the price column cells */ +.o_list_view.price-left-align td.o_list_number[name="price"] { + text-align: left !important; +} + +/* Left-align the price column header */ +.o_list_view.price-left-align th[data-name="price"], +.o_list_view.price-left-align th[data-name="price"] .o_list_number_th { + text-align: left !important; + justify-content: flex-start !important; /* override flex alignment */ +} \ 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..4d9d7fea42c --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..ff7927c8085 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,47 @@ + + + + + Property Offer + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + + estate.property.offer.view.list + estate.property.offer + + + + + + + +

+ +

+ + + + + + + + + + + + + +
+
+
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..c644041de4c --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,158 @@ + + + + + Property + estate.property + list,form,kanban + {'search_default_available_properties' : 1} + +

+ Create your first property +

+
+
+ + + + estate.property.view.list + estate.property + + + + + + + + + + + + + + + + + + estate.property.view.form + estate.property + +
+
+
+ + +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + estate.property.view.search + estate.property + + + + + + + + + + + + + + + + + + + + + estate.property.view.kanban + estate.property + + + + + + +
+
+ +
+
Expected Price:
+ + +
+ Best Price: +
+
+ Selling Price: +
+ + +
+
+
+
+
+
+
diff --git a/estate/views/res_users_views.xml b/estate/views/res_users_views.xml new file mode 100644 index 00000000000..fa66cfe91cc --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.view.form.inherit.estate.property + res.users + + + + + + + + + + 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..6bee59ef1ac --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,9 @@ +{ + "name": "Real Estate Accounting", + "descrption": "", + "sequence": 2, + "category": "Real Estate", + "depends": ["estate", "account"], + "license": "LGPL-3", + "installable": True, +} 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..e6ab2ce2f45 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,39 @@ +from odoo import models, fields, Command +from odoo.exceptions import AccessError + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_set_sold(self): + + try: + self.check_access("write") + except AccessError: + raise AccessError("You are not allowed to sell this property. Contact your manager.") + + self.env["account.move"].sudo().create( + { + "partner_id": self.buyer_id.id, + "move_type": "out_invoice", + "invoice_date": fields.Date.context_today(self), + "invoice_line_ids": [ + Command.create( + { + "name": self.name, + "quantity": 1, + "price_unit": self.selling_price * 0.06, + } + ), + Command.create( + { + "name": "Administration fees", + "quantity": 1, + "price_unit": 100.00, + } + ), + ], + } + ) + + return super().action_set_sold()