From a7e4365ea13710a1a57aac4edbe961393964547e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bertrand?= Date: Mon, 15 Dec 2025 13:52:34 +0100 Subject: [PATCH 1/2] [ADD] estate{,_account}: implement a module for real estate This provides an implementation for a module allowing people to manage their properties, people to place offers and alters the users' view to include the list of properties being sold by the person --- estate/__init__.py | 1 + estate/__manifest__.py | 18 +++ estate/models/__init__.py | 5 + estate/models/property.py | 110 ++++++++++++++ estate/models/property_offer.py | 61 ++++++++ estate/models/property_tag.py | 12 ++ estate/models/property_type.py | 20 +++ estate/models/res_users.py | 7 + estate/security/ir.model.access.csv | 5 + estate/views/estate_menus.xml | 12 ++ estate/views/estate_property_offer_views.xml | 44 ++++++ estate/views/estate_property_tag_views.xml | 32 ++++ estate/views/estate_property_type_views.xml | 57 ++++++++ estate/views/estate_property_views.xml | 145 +++++++++++++++++++ estate/views/res_users_views.xml | 15 ++ estate_account/__init__.py | 1 + estate_account/__manifest__.py | 7 + estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 16 ++ 19 files changed, 569 insertions(+) create mode 100644 estate/__init__.py create mode 100644 estate/__manifest__.py create mode 100644 estate/models/__init__.py create mode 100644 estate/models/property.py create mode 100644 estate/models/property_offer.py create mode 100644 estate/models/property_tag.py create mode 100644 estate/models/property_type.py create mode 100644 estate/models/res_users.py create mode 100644 estate/security/ir.model.access.csv create mode 100644 estate/views/estate_menus.xml create mode 100644 estate/views/estate_property_offer_views.xml create mode 100644 estate/views/estate_property_tag_views.xml create mode 100644 estate/views/estate_property_type_views.xml create mode 100644 estate/views/estate_property_views.xml create mode 100644 estate/views/res_users_views.xml create mode 100644 estate_account/__init__.py create mode 100644 estate_account/__manifest__.py create mode 100644 estate_account/models/__init__.py create mode 100644 estate_account/models/estate_property.py 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..d99c0dd1381 --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'Real Estate', + 'depends': ['base'], + 'data': [ + 'security/ir.model.access.csv', + + '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', + 'views/res_users_views.xml', + ], + 'installable': True, + 'application': True, + 'author': "Odoo", + 'license': 'AGPL-3' +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..cfb3cd728e5 --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,5 @@ +from . import property +from . import property_offer +from . import property_tag +from . import property_type +from . import res_users diff --git a/estate/models/property.py b/estate/models/property.py new file mode 100644 index 00000000000..9dbe30b9a94 --- /dev/null +++ b/estate/models/property.py @@ -0,0 +1,110 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_compare, float_is_zero + + +class Property(models.Model): + _name = 'estate.property' + _description = "Estate property" + _order = 'id desc' + + name = fields.Char(string="Title", required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date( + string="Available From", + default=lambda self: fields.Date.today() + relativedelta(months=3), + copy=False, + ) + expected_price = fields.Float(required=True) + selling_price = fields.Float(readonly=True, copy=False) + bedrooms = fields.Integer(default=2) + living_area = fields.Integer(string="Living Area (sqm)") + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer(string="Garden Area (sqm)") + garden_orientation = fields.Selection( + selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')] + ) + state = fields.Selection( + default="new", + string="Status", + selection=[ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], + required=True, + copy=False, + ) + active = fields.Boolean(default=True) + property_type_id = fields.Many2one('estate.property.type', string="Property Type") + partner_id = fields.Many2one('res.partner', string="Buyer", readonly=True) + user_id = fields.Many2one('res.users', string="Salesman", 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") + total_area = fields.Integer(string="Total Area (sqm)", compute='_compute_total_area') + best_offer = fields.Float(default=0.0, compute="_compute_best_offer") + + _expected_price_strictly_pos = models.Constraint( + "CHECK(expected_price > 0)", "The expected price must be strictly positive." + ) + _selling_price_pos = models.Constraint( + "CHECK(selling_price >= 0)", "The selling price must be positive." + ) + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends('offer_ids') + def _compute_best_offer(self): + for record in self: + record.best_offer = max(record.offer_ids.mapped('price')) if record.offer_ids else 0.0 + + @api.onchange('garden') + def _onchange_garden(self): + self.garden_area = 10 if self.garden else 0 + self.garden_orientation = 'north' if self.garden else '' + + @api.constrains('selling_price', 'expected_price') + def _check_selling_price(self): + for record in self: + if ( + not float_is_zero(record.selling_price, precision_digits=2) and + float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1 + ): + raise ValidationError( + self.env._( + "The selling price must be at least 90% of the expected price! " + "You must reduce the expected price if you want to accept this offer." + ) + ) + + def action_set_sold(self): + if self.state == 'cancelled': + raise UserError(self.env._("Cancelled properties cannot be sold.")) + + self.state = 'sold' + return True + + def action_set_cancelled(self): + if self.state == 'sold': + raise UserError(self.env._("Sold properties cannot be cancelled.")) + + self.state = 'cancelled' + return True + + @api.ondelete(at_uninstall=False) + def _unlink_except_new_or_cancelled(self): + for record in self: + if record.state not in ['new', 'cancelled']: + raise UserError( + self.env._("Only new and cancelled properties can be deleted.") + ) diff --git a/estate/models/property_offer.py b/estate/models/property_offer.py new file mode 100644 index 00000000000..aa8861596de --- /dev/null +++ b/estate/models/property_offer.py @@ -0,0 +1,61 @@ +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class PropertyOffer(models.Model): + _name = 'estate.property.offer' + _description = "Property Offer" + _order = "price desc" + + price = fields.Float() + status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False) + partner_id = fields.Many2one('res.partner', required=True) + property_id = fields.Many2one('estate.property', required=True) + property_type_id = fields.Many2one(related='property_id.property_type_id', store=True) + validity = fields.Integer(default=7, string="Validity (days)") + deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline') + + _price_pos = models.Constraint( + "CHECK(price > 0)", "The offer price must be strictly positive." + ) + + @api.depends('validity') + def _compute_deadline(self): + for record in self: + create_date = record.create_date or fields.Date.today() + record.deadline = create_date + relativedelta(days=record.validity) + + def _inverse_deadline(self): + for record in self: + record.validity = (record.deadline - fields.Date.to_date(record.create_date)).days + + def action_confirm(self): + self.status = 'accepted' + for offer in self.property_id.offer_ids: + if offer.id == self.id: + continue + + offer.status = 'refused' + + self.property_id.state = 'offer_accepted' + self.property_id.partner_id = self.partner_id + self.property_id.selling_price = self.price + return True + + def action_refuse(self): + self.status = 'refused' + return True + + @api.model_create_multi + def create(self, vals): + for record in vals: + property = self.env['estate.property'].browse(record['property_id']) + min_price = min(property.offer_ids.mapped('price')) if property.offer_ids else 0.0 + if record['price'] < min_price: + raise UserError(self.env._("The offer must be higher than %d.", min_price)) + + property.state = 'offer_received' + + return super().create(vals) diff --git a/estate/models/property_tag.py b/estate/models/property_tag.py new file mode 100644 index 00000000000..463b41c6554 --- /dev/null +++ b/estate/models/property_tag.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class PropertyTag(models.Model): + _name = 'estate.property.tag' + _description = "Property Tag" + _order = "name" + + name = fields.Char(required=True) + color = fields.Integer() + + _name_uniq = models.Constraint("UNIQUE(name)", "The name must be unique.") diff --git a/estate/models/property_type.py b/estate/models/property_type.py new file mode 100644 index 00000000000..9aec69f9cfd --- /dev/null +++ b/estate/models/property_type.py @@ -0,0 +1,20 @@ +from odoo import api, fields, models + + +class PropertyType(models.Model): + _name = 'estate.property.type' + _description = "Property Type" + _order = "sequence desc, name" + + name = fields.Char(required=True) + property_ids = fields.One2many('estate.property', 'property_type_id') + sequence = fields.Integer(help="Used to order property types. Higher is better.") + offer_ids = fields.One2many('estate.property.offer', 'property_type_id') + offer_count = fields.Integer(compute='_compute_offer_count') + + _name_uniq = models.Constraint("UNIQUE(name)", "The name must be unique.") + + @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..e8176a5c886 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many('estate.property', 'user_id', domain="[('active', '=', 'True')]") diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv new file mode 100644 index 00000000000..49bca99cac8 --- /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_property,access_estate_property,model_estate_property,base.group_user,1,1,1,1 +access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1 +access_estate_property_offer,access_estate_property_offer,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..fd703d86f5a --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..0f9aec3a8f8 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,44 @@ + + + + estate.property.offer.form + estate.property.offer + +
+ + + + + + + + + + +
+
+
+ + + estate.property.offer.list + estate.property.offer + + + + + + + + +
+

+ +

+
+ + + + + + + + + + + + + +
+
+ + + estate.property.type.list + estate.property.type + + + + + + + + + + Property Types + estate.property.type + list,form + +
diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml new file mode 100644 index 00000000000..cf034bdd3f7 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,145 @@ + + + + estate.property.form + estate.property + +
+
+
+ +
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + + + estate.property.kanban + estate.property + + + + +
+ +
+
+ Expected Price: + +
+
+ Best Offer: + +
+
+ Selling Price: + +
+
+ +
+ +
+
+
+
+
+ + + estate.property.search + estate.property + + + + + + + + + + + + + + + + + + + Properties + estate.property + kanban,list,form + {'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..4496b1fd673 --- /dev/null +++ b/estate/views/res_users_views.xml @@ -0,0 +1,15 @@ + + + + res.users.view.form.inherit.estate + 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..d88f4fc8a39 --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,7 @@ +{ + 'name': 'Real Estate Account', + 'depends': ['estate', 'account'], + 'author': "Odoo", + 'installable': True, + 'license': 'AGPL-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..33f32940423 --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,16 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = 'estate.property' + + def action_set_sold(self): + self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_id.id, + 'line_ids': [ + Command.create({'name': self.name, 'quantity': 1, 'price_unit': 0.06 * self.selling_price}), + Command.create({'name': "Administrative fees", 'quantity': 1, 'price_unit': 100}), + ] + }) + return super().action_set_sold() From 22764f4415428c9c82cc87f3d27a8617352c1972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bertrand?= Date: Tue, 23 Dec 2025 13:21:44 +0100 Subject: [PATCH 2/2] [IMP] awesome_owl: enhance the playground with various components This enhances the playground with various components, such as counters, cards, a to-do list, eventually combining multiple ones --- awesome_owl/static/src/card/card.js | 23 ++++++++++ awesome_owl/static/src/card/card.xml | 18 ++++++++ awesome_owl/static/src/counter/counter.js | 20 +++++++++ awesome_owl/static/src/counter/counter.xml | 11 +++++ awesome_owl/static/src/playground.js | 20 ++++++++- awesome_owl/static/src/playground.xml | 18 +++++++- .../static/src/todo/todo_item/todo_item.js | 26 +++++++++++ .../static/src/todo/todo_item/todo_item.xml | 13 ++++++ .../static/src/todo/todo_list/todo_list.js | 43 +++++++++++++++++++ .../static/src/todo/todo_list/todo_list.xml | 13 ++++++ awesome_owl/static/src/utils.js | 8 ++++ 11 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 awesome_owl/static/src/card/card.js create mode 100644 awesome_owl/static/src/card/card.xml create mode 100644 awesome_owl/static/src/counter/counter.js create mode 100644 awesome_owl/static/src/counter/counter.xml create mode 100644 awesome_owl/static/src/todo/todo_item/todo_item.js create mode 100644 awesome_owl/static/src/todo/todo_item/todo_item.xml create mode 100644 awesome_owl/static/src/todo/todo_list/todo_list.js create mode 100644 awesome_owl/static/src/todo/todo_list/todo_list.xml create mode 100644 awesome_owl/static/src/utils.js diff --git a/awesome_owl/static/src/card/card.js b/awesome_owl/static/src/card/card.js new file mode 100644 index 00000000000..de0828c622a --- /dev/null +++ b/awesome_owl/static/src/card/card.js @@ -0,0 +1,23 @@ +import { Component, useState } from "@odoo/owl"; + +export class Card extends Component { + static template = "awesome_owl.card"; + + static props = { + title: {type: String}, + slots: { + type: Object, + shape: { + default: true + } + }, + }; + + setup() { + this.state = useState({value: true}) + } + + toggleState() { + this.state.value = !this.state.value; + } +} diff --git a/awesome_owl/static/src/card/card.xml b/awesome_owl/static/src/card/card.xml new file mode 100644 index 00000000000..17abbbbf552 --- /dev/null +++ b/awesome_owl/static/src/card/card.xml @@ -0,0 +1,18 @@ + + + + +
+
+
+ + +
+

+ +

+
+
+
+ +
diff --git a/awesome_owl/static/src/counter/counter.js b/awesome_owl/static/src/counter/counter.js new file mode 100644 index 00000000000..82e73fc8fc0 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.js @@ -0,0 +1,20 @@ +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(); + } + } +} diff --git a/awesome_owl/static/src/counter/counter.xml b/awesome_owl/static/src/counter/counter.xml new file mode 100644 index 00000000000..acead7ab7d7 --- /dev/null +++ b/awesome_owl/static/src/counter/counter.xml @@ -0,0 +1,11 @@ + + + + +
+

Counter:

+ +
+
+ +
diff --git a/awesome_owl/static/src/playground.js b/awesome_owl/static/src/playground.js index 4ac769b0aa5..e0508fa40b5 100644 --- a/awesome_owl/static/src/playground.js +++ b/awesome_owl/static/src/playground.js @@ -1,5 +1,23 @@ -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/todo_list/todo_list" export class Playground extends Component { static template = "awesome_owl.playground"; + + static components = { Card, Counter, TodoList }; + + static props = {}; + + value = markup("
some content
"); + + setup() { + this.sum = useState( {value: 0} ); + } + + incrementSum() { + this.sum.value++; + } + } diff --git a/awesome_owl/static/src/playground.xml b/awesome_owl/static/src/playground.xml index 4fb905d59f9..e48b30e4712 100644 --- a/awesome_owl/static/src/playground.xml +++ b/awesome_owl/static/src/playground.xml @@ -3,7 +3,23 @@
- hello world + + +

The sum is:

+
+
+ + some content + + + + + + + +
+
+
diff --git a/awesome_owl/static/src/todo/todo_item/todo_item.js b/awesome_owl/static/src/todo/todo_item/todo_item.js new file mode 100644 index 00000000000..bcb6a41d675 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item/todo_item.js @@ -0,0 +1,26 @@ +import { Component } from "@odoo/owl"; + +export class TodoItem extends Component { + static template = "awesome_owl.todo.todo_item"; + + static props = { + todo: { + type: Object, + shape: { + id: Number, + description: String, + isCompleted: Boolean, + } + }, + toggleState: {type: Function}, + removeTodo: {type: Function}, + }; + + toggleState() { + this.props.toggleState(this.props.todo.id); + } + + removeTodo() { + this.props.removeTodo(this.props.todo.id); + } +} diff --git a/awesome_owl/static/src/todo/todo_item/todo_item.xml b/awesome_owl/static/src/todo/todo_item/todo_item.xml new file mode 100644 index 00000000000..7b474fd8f7a --- /dev/null +++ b/awesome_owl/static/src/todo/todo_item/todo_item.xml @@ -0,0 +1,13 @@ + + + + +

+ + . + + +

+
+ +
diff --git a/awesome_owl/static/src/todo/todo_list/todo_list.js b/awesome_owl/static/src/todo/todo_list/todo_list.js new file mode 100644 index 00000000000..110d896e0d0 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list/todo_list.js @@ -0,0 +1,43 @@ +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.todo.todo_list"; + + static components = { TodoItem }; + + static props = {}; + + setup() { + this.todos = useState([]); + this.id = 0; + useAutoFocus("input"); + } + + addTodo(event) { + if (event.type !== "keyup" || event.keyCode !== 13 || event.target.value === "") { + return; + } + this.todos.push({id: this.id++, description: event.target.value, isCompleted: false}); + event.target.value = ""; + } + + toggleTodo(id) { + let todo = this.todos.find(todo => todo.id === id); + todo.isCompleted = !todo.isCompleted; + } + + #reOrderItems() { + for (let i = 0; i < this.todos.length; i++) { + this.todos[i].id = i; + } + } + + removeTodo(id) { + const todo = this.todos.findIndex(todo => todo.id === id); + this.todos.splice(todo, 1); + this.#reOrderItems(); + this.id--; + } +} diff --git a/awesome_owl/static/src/todo/todo_list/todo_list.xml b/awesome_owl/static/src/todo/todo_list/todo_list.xml new file mode 100644 index 00000000000..8e80bd6aed6 --- /dev/null +++ b/awesome_owl/static/src/todo/todo_list/todo_list.xml @@ -0,0 +1,13 @@ + + + + +
+
Enter a new task:
+ + + +
+
+ +
diff --git a/awesome_owl/static/src/utils.js b/awesome_owl/static/src/utils.js new file mode 100644 index 00000000000..9447231a18c --- /dev/null +++ b/awesome_owl/static/src/utils.js @@ -0,0 +1,8 @@ +import { onMounted, useRef } from "@odoo/owl"; + +export function useAutoFocus(name) { + let ref = useRef(name); + onMounted(() => { + ref.el.focus(); + }); +}