From c78ee0e35afde587d7dd9c9f97fc9f2b4d58464e Mon Sep 17 00:00:00 2001 From: 4yuub Date: Tue, 19 May 2026 16:33:21 +0200 Subject: [PATCH] [ADD] estate{,_account}: Real Estate Module Porblem: Odoo doesn't support Real Estate business Solution: add the estate and estate account modules task-6229523 --- estate/__init__.py | 1 + estate/__manifest__.py | 24 +++ estate/models/__init__.py | 2 + estate/models/estate_property.py | 121 ++++++++++++++ estate/models/estate_property_offer.py | 91 +++++++++++ estate/models/estate_property_tag.py | 15 ++ estate/models/estate_property_type.py | 26 +++ estate/models/res_users.py | 10 ++ estate/security/ir.model.access.csv | 5 + estate/views/estate_menus.xml | 14 ++ estate/views/estate_property_offer_views.xml | 49 ++++++ estate/views/estate_property_tag_views.xml | 42 +++++ estate/views/estate_property_type_views.xml | 56 +++++++ estate/views/estate_property_views.xml | 162 +++++++++++++++++++ estate/views/estate_salesteam_views.xml | 23 +++ estate_account/__init__.py | 1 + estate_account/__manifest__.py | 11 ++ estate_account/models/__init__.py | 1 + estate_account/models/estate_property.py | 26 +++ 19 files changed, 680 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/estate_property.py create mode 100644 estate/models/estate_property_offer.py create mode 100644 estate/models/estate_property_tag.py create mode 100644 estate/models/estate_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/estate_salesteam_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..2233d34781c --- /dev/null +++ b/estate/__manifest__.py @@ -0,0 +1,24 @@ +{ + 'name': "Real Estate", + 'version': '1.0', + 'depends': ['base'], + 'author': "Odoo S.A.", + 'category': 'Customizations', + 'description': """ + This module is designed to manage real estate properties, including details such as property type, location, price, and status. + + It allows users to easily track and organize their real estate assets, making it easier to manage and analyze their property portfolio. + """, + 'installable': True, + 'application': True, + 'license': 'LGPL-3', + '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/estate_salesteam_views.xml', + 'views/estate_menus.xml', + ], +} diff --git a/estate/models/__init__.py b/estate/models/__init__.py new file mode 100644 index 00000000000..916057b6bbd --- /dev/null +++ b/estate/models/__init__.py @@ -0,0 +1,2 @@ +from . import (estate_property, estate_property_offer, estate_property_tag, + estate_property_type, res_users) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py new file mode 100644 index 00000000000..cf27828965e --- /dev/null +++ b/estate/models/estate_property.py @@ -0,0 +1,121 @@ +from datetime import date +from dateutil.relativedelta import relativedelta + +from odoo import _, api, exceptions, fields, models +from odoo.tools import float_compare, float_is_zero + + +class EstateProperty(models.Model): + _name = "estate.property" + _description = "Real Estate Property Model" + _order = "id desc" + + name = fields.Char(required=True) + description = fields.Text() + postcode = fields.Char() + date_availability = fields.Date( + copy=False, default=lambda x: date.today() + relativedelta(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() + facades = fields.Integer() + garage = fields.Boolean() + garden = fields.Boolean() + garden_area = fields.Integer() + garden_orientation = fields.Selection([ + ('north', 'North'), + ('south', 'South'), + ('east', 'East'), + ('west', 'West'), + ]) + + property_type_id = fields.Many2one( + "estate.property.type", string="Property Type" + ) + salesman_id = fields.Many2one( + "res.users", string="Salesman", default=lambda self: self.env.user + ) + buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) + + tag_ids = fields.Many2many("estate.property.tag") + offer_ids = fields.One2many( + "estate.property.offer", "property_id", string="Offers" + ) + active = fields.Boolean(default=True) + state = fields.Selection([ + ('new', 'New'), + ('offer_received', 'Offer Received'), + ('offer_accepted', 'Offer Accepted'), + ('sold', 'Sold'), + ('cancelled', 'Cancelled'), + ], required=True, default='new') + sequence = fields.Integer(default=1) + total_area = fields.Integer(compute='_compute_total_area') + best_price = fields.Float(compute='_compute_best_price') + + _check_expected_price = models.Constraint( + 'CHECK(expected_price > 0)', + 'The expected price must be stricly positive.' + ) + + _check_selling_price = models.Constraint( + 'CHECK(selling_price >= 0)', + 'The selling price must be stricly positive.' + ) + + @api.constrains('selling_price') + def _check_selling_price_py(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 * .9, + precision_digits=2) < 0: + raise exceptions.ValidationError( + "The selling price can't be lower than 90%% of the expected price.") # noqa: E501 + + @api.depends('living_area', 'garden_area') + def _compute_total_area(self): + for record in self: + record.total_area = record.living_area + record.garden_area + + @api.depends('offer_ids.price') + def _compute_best_price(self): + for record in self: + record.best_price = max(record.offer_ids.mapped( + 'price')) if record.offer_ids else None + + @api.onchange('garden') + def _onchange_garden(self): + self.garden_area = None + self.garden_orientation = None + if self.garden: + self.garden_area = 10 + self.garden_orientation = 'north' + + def action_set_sold(self): + error = None + for record in self: + if record.state == 'cancelled': + error = _('Cancelled properties cannot be sold') + continue + record.state = 'sold' + if error: + raise exceptions.UserError(error) + + def action_set_cancelled(self): + error = None + for record in self: + if record.state == 'sold': + error = _('Sold properties cannot be cancelled') + continue + record.state = 'cancelled' + if error: + raise exceptions.UserError(error) + + @api.ondelete(at_uninstall=False) + def _unlink_only_new_or_cancelled(self): + if self.state not in ['new', 'cancelled']: + raise exceptions.UserError( + _('Can only delete New or Cancelled properties.') + ) diff --git a/estate/models/estate_property_offer.py b/estate/models/estate_property_offer.py new file mode 100644 index 00000000000..b2e04c8842c --- /dev/null +++ b/estate/models/estate_property_offer.py @@ -0,0 +1,91 @@ +from datetime import date +from dateutil.relativedelta import relativedelta + +from odoo import _, api, exceptions, fields, models + + +class EstatePropertyOffer(models.Model): + _name = "estate.property.offer" + _description = "Real Estate Property Offer Model" + _order = "price desc" + + price = fields.Float() + status = fields.Selection( + selection=[ + ('accepted', 'Accepted'), + ('refused', 'Refused'), + ], copy=False + ) + validity = fields.Integer(default=7) + + 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', + ) + date_deadline = fields.Date( + compute='_compute_deadline_date', + inverse='_inverse_deadline_date', + ) + + _check_offer_price = models.Constraint( + 'CHECK(price > 0)', + 'The offer price must be stricly positive.' + ) + + @api.depends('validity') + def _compute_deadline_date(self): + for record in self: + record.date_deadline = (record.create_date or date.today()) + relativedelta( + days=record.validity + ) + + def _inverse_deadline_date(self): + for record in self: + start_date = ( + record.create_date.date() if record.create_date else date.today() + ) + + record.validity = (record.date_deadline - start_date).days + + def action_accept(self): + for record in self: + if any( + offer.status == "accepted" and record.id != offer.id + for offer in record.property_id.offer_ids + ): + raise exceptions.UserError( + 'A property can only have one accpeted Offer') + record.status = 'accepted' + record.property_id.selling_price = record.price + record.property_id.buyer_id = record.partner_id + record.property_id.state = 'offer_accepted' + + def action_refuse(self): + for record in self: + record.status = 'refused' + record.property_id.selling_price = None + record.property_id.buyer_id = None + + @api.model + def create(self, vals_list): + property_id = None + price = 0 + for vals in vals_list: + val_property_id = vals.get('property_id') + val_price = vals.get('price') + if val_property_id: + property_id = val_property_id + if val_price is not None: + price = val_price + + property_record = self.env['estate.property'].browse(property_id) + if any( + offer.price > price + for offer in property_record.offer_ids + ): + raise exceptions.UserError( + _('Can\'t create an offer with a lower price than an existing offer.') + ) + property_record.state = 'offer_received' + return super().create(vals_list) diff --git a/estate/models/estate_property_tag.py b/estate/models/estate_property_tag.py new file mode 100644 index 00000000000..e27bfc3324b --- /dev/null +++ b/estate/models/estate_property_tag.py @@ -0,0 +1,15 @@ +from odoo import fields, models + + +class EstatePropertyTag(models.Model): + _name = 'estate.property.tag' + _description = "Real Estate Property Tag Model" + _order = 'name' + + name = fields.Char(required=True) + color = fields.Integer() + + _check_unique_name = models.Constraint( + 'UNIQUE(name)', + 'Tag name must be unique.' + ) diff --git a/estate/models/estate_property_type.py b/estate/models/estate_property_type.py new file mode 100644 index 00000000000..98bbf105ce2 --- /dev/null +++ b/estate/models/estate_property_type.py @@ -0,0 +1,26 @@ +from odoo import api, fields, models + + +class EstatePropertyType(models.Model): + _name = 'estate.property.type' + _description = "Real Estate Property Type Model" + _order = 'name' + + name = fields.Char(required=True) + property_ids = fields.One2many( + 'estate.property', 'property_type_id', string="Properties" + ) + offer_ids = fields.One2many( + 'estate.property.offer', 'property_type_id', string="Offers" + ) + offer_count = fields.Integer(compute='_compute_offer_count') + + _check_unique_name = models.Constraint( + 'UNIQUE(name)', + 'Type name must be unique.' + ) + + @api.depends('offer_ids') + def _compute_offer_count(self): + for record in self: + record.offer_count = len(record.offer_ids or []) diff --git a/estate/models/res_users.py b/estate/models/res_users.py new file mode 100644 index 00000000000..69c78f8d367 --- /dev/null +++ b/estate/models/res_users.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class User(models.Model): + _inherit = 'res.users' + + property_ids = fields.One2many( + 'estate.property', 'salesman_id', + 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..89f97c50842 --- /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..2a6a227d848 --- /dev/null +++ b/estate/views/estate_menus.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/estate/views/estate_property_offer_views.xml b/estate/views/estate_property_offer_views.xml new file mode 100644 index 00000000000..5ed1513c447 --- /dev/null +++ b/estate/views/estate_property_offer_views.xml @@ -0,0 +1,49 @@ + + + + + Property Offer + estate.property.offer + list,form + [('property_type_id', '=', active_id)] + + + + estate.property.offer.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..3bca8057850 --- /dev/null +++ b/estate/views/estate_property_views.xml @@ -0,0 +1,162 @@ + + + + + Properties + estate.property + kanban,list,form + {'search_default_available': True} + + + + estate.property.kanban + estate.property + + + + + +
+
+ +
+ +
+
Expected Price:
+ +
Best + price: +
+ +
Selling + price: +
+ +
+ This is new! +
+
+ +
+ +
+
+
+
+
+
+
+ + + estate.property.list + estate.property + + + + + + + + + + + + + + + + estate.property.search + estate.property + + + + + + + + + + + + + + + + estate.property.form + estate.property + +
+
+
+ + +
+

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
diff --git a/estate/views/estate_salesteam_views.xml b/estate/views/estate_salesteam_views.xml new file mode 100644 index 00000000000..15b6e066eae --- /dev/null +++ b/estate/views/estate_salesteam_views.xml @@ -0,0 +1,23 @@ + + + + + Users & Companies + res.partner + list,form + + + + 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..e6fa6e009ca --- /dev/null +++ b/estate_account/__manifest__.py @@ -0,0 +1,11 @@ +{ + 'name': "Estate Account", + 'version': '1.0', + 'depends': ['base', 'estate', 'account'], + 'author': "Odoo S.A.", + 'category': 'Customizations', + 'description': """This module is designed to link the account and estate modules""", + 'license': 'LGPL-3', + 'data': [ + ], +} 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..1c4c9c1b05c --- /dev/null +++ b/estate_account/models/estate_property.py @@ -0,0 +1,26 @@ +from odoo import Command, models + + +class EstateProperty(models.Model): + _inherit = "estate.property" + + def action_set_sold(self): + for record in self: + values = { + 'partner_id': record.buyer_id.id, + 'move_type': 'out_invoice', + "line_ids": [ + Command.create({ + "name": "6% of the selling price", + "quantity": 1, + "price_unit": record.selling_price * .06, + }), + Command.create({ + "name": "administrative fees", + "quantity": 1, + "price_unit": 100, + }), + ], + } + self.env['account.move'].create(values) + return super().action_set_sold()