Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6c46d87
[ADD] estate: add initial manifest for Real Estate module
HashemKhaled Oct 20, 2025
0f11cda
[IMP] estate: implement estate property model
HashemKhaled Oct 20, 2025
15ad935
[IMP] estate: add access control for estate property model
HashemKhaled Oct 20, 2025
c521487
[IMP] estate: add estate property views and menus
HashemKhaled Oct 20, 2025
761b7a2
[FIX] estate: remove the unnneeded installable field
HashemKhaled Oct 20, 2025
7c4b002
[IMP] estate: enhance property views with detailed form and search fu…
HashemKhaled Oct 21, 2025
04e7f84
[FIX] estate: remove the group on postcode filter for property search…
HashemKhaled Oct 21, 2025
d771be5
[IMP] estate: add property type, tag, and offer models with views and…
HashemKhaled Oct 21, 2025
582c69a
[FIX] estate: adjust style
HashemKhaled Oct 21, 2025
9d9a3a4
[FIX] estate: adjust style
HashemKhaled Oct 21, 2025
7148e7f
[IMP] estate: Add notes.
Mathilde411 Oct 21, 2025
ffc7f58
[IMP] estate: add computed fields and onchanges
HashemKhaled Oct 21, 2025
c0276dc
[IMP] estate: add buttons for some actions
HashemKhaled Oct 21, 2025
3423a10
[IMP] estate: add sql and python constraints
HashemKhaled Oct 22, 2025
ea1092d
[IMP] estate: enhance views
HashemKhaled Oct 23, 2025
e2e96ab
[FIX] estate: adjust style
HashemKhaled Oct 23, 2025
f974e96
[IMP] estate: use inheritance
HashemKhaled Oct 23, 2025
978fe3d
[ADD] estate_account: implement property sale invoicing
HashemKhaled Oct 23, 2025
887b34e
[IMP] estate: add kanban view for properties
HashemKhaled Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
'name': 'Real Estate',
'summary': 'Manages real estate properties.',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_menus.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_type_menus.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_tag_menus.xml',
'views/res_users_views.xml',
],
'application': True,
'author': "Odoo",
'license': 'AGPL-3'
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
137 changes: 137 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from dateutil.relativedelta import relativedelta
from odoo import api, models, fields
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_is_zero, float_compare


class Property(models.Model):
_name = "estate.property"
_description = "Real Estate Property"
_order = "id desc"

name = fields.Char(required=True)
description = fields.Text()
notes = fields.Html()
postcode = fields.Char()
date_availability = fields.Date(
default=lambda self: fields.Date.today() + relativedelta(months=3), copy=False)
expected_price = fields.Float(required=True)
selling_price = fields.Float(
compute="_compute_selling_price", copy=False, readonly=True, store=True)
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'),
])
active = fields.Boolean(default=True)
state = fields.Selection([
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled'),
], default='new', required=True, copy=False)
property_type_id = fields.Many2one(
"estate.property.type", string="Property Type")
buyer_id = fields.Many2one("res.partner", string="Buyer",
copy=False, compute="_compute_buyer")
salesperson_id = fields.Many2one(
"res.users", string="Salesperson", default=lambda self: self.env.uid)
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
offer_ids = fields.One2many(
"estate.property.offer", "property_id", string="Offers")
total_area = fields.Integer(
compute="_compute_total_area", string="Total Area (sqm)")
best_offer = fields.Float(
compute="_compute_best_offer")

_check_expected_price = models.Constraint(
'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'
)
_check_selling_price = models.Constraint(
'CHECK(selling_price >= 0)', 'The selling price must be non-negative.'
)

@api.depends('offer_ids.status', 'offer_ids.price')
def _compute_selling_price(self):
for property in self:
accepted_offer = property.offer_ids.filtered(
lambda o: o.status == 'accepted')
if accepted_offer:
property.selling_price = accepted_offer.price
else:
property.selling_price = 0.0

@api.depends('offer_ids.status', 'offer_ids.partner_id')
def _compute_buyer(self):
for property in self:
accepted_offer = property.offer_ids.filtered(
lambda o: o.status == 'accepted')
if accepted_offer:
property.buyer_id = accepted_offer.partner_id
else:
property.buyer_id = None

@api.depends('living_area', 'garden_area')
def _compute_total_area(self):
for property in self:
property.total_area = property.living_area + property.garden_area

@api.depends('offer_ids.price')
def _compute_best_offer(self):
for property in self:
if property.offer_ids:
property.best_offer = max(property.offer_ids.mapped('price'))
else:
property.best_offer = 0.0

@api.constrains('selling_price', 'expected_price')
def _check_selling_price_is_acceptable(self):
for property in self:
if not float_is_zero(property.selling_price, precision_rounding=0.01) and float_compare(
property.selling_price,
0.9 * property.expected_price,
precision_rounding=0.01,
) < 0:
raise ValidationError(
"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."
)

@api.onchange('garden')
def _onchange_garden(self):
if not self.garden:
self.garden_area = 0
self.garden_orientation = None
else:
self.garden_area = 10
self.garden_orientation = 'north'

@api.ondelete(at_uninstall=False)
def _unlink_if_property_new_or_cancelled(self):
for property in self:
if property.state not in ['new', 'cancelled']:
raise UserError(
f"You cannot delete a property in the '{property.state}' state.")

def action_set_sold(self):
for property in self:
if property.state != 'cancelled':
property.state = 'sold'
else:
raise UserError(
"Cancelled properties cannot be sold.")

def action_set_cancelled(self):
for property in self:
if property.state != 'sold':
property.state = 'cancelled'
else:
raise UserError(
"Sold properties cannot be cancelled.")
91 changes: 91 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from odoo import api, models, fields
from odoo.exceptions import ValidationError


class PropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer"
_order = "price desc"

price = fields.Float()
status = fields.Selection(
[
("accepted", "Accepted"),
("refused", "Refused"),
],
copy=False,
)
partner_id = fields.Many2one(
"res.partner", string="Partner", required=True)
property_id = fields.Many2one(
"estate.property", string="Property", required=True)
validity = fields.Integer(default=7)
date_deadline = fields.Date(
compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline")
property_state = fields.Selection(
related="property_id.state",
)
property_type_id = fields.Many2one(
related="property_id.property_type_id",
store=True,
)

_check_price = models.Constraint(
'CHECK(price > 0)', 'The offer price must be strictly positive.'
)

@api.depends('validity', 'create_date')
def _compute_date_deadline(self):
for offer in self:
if offer.create_date:
offer.date_deadline = fields.Date.add(
offer.create_date.date(), days=offer.validity)
else:
offer.date_deadline = fields.Date.add(
fields.Date.today(), days=offer.validity)

def _inverse_date_deadline(self):
for offer in self:
if offer.create_date and offer.date_deadline:
delta = (offer.date_deadline - offer.create_date.date()).days
offer.validity = delta
elif offer.date_deadline:
delta = (offer.date_deadline - fields.Date.today()).days
offer.validity = delta

@api.model
def create(self, vals):
for val in vals:
property_obj = self.env['estate.property'].browse(
val.get('property_id'))
property_offers = self.env['estate.property.offer'].search([
('property_id', '=', property_obj.id),
])
if property_offers:
lowest_offer = min(property_offers.mapped('price'))
if val.get('price', 0) <= lowest_offer:
raise ValidationError(
"The offer price must be higher than existing offers."
)
property_obj.state = 'offer_received'
return super().create(vals)

def action_accept_offer(self):
for offer in self:
offer.status = "accepted"
offer.property_id.state = "offer_accepted"

other_offers = self.env['estate.property.offer'].search([
('property_id', '=', offer.property_id.id),
('id', '!=', offer.id),
('status', '!=', 'refused')
])
other_offers.action_refuse_offer()

return True

def action_refuse_offer(self):
for offer in self:
offer.status = "refused"

return True
14 changes: 14 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import models, fields


class PropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_order = "name"

name = fields.Char(required=True)
color = fields.Integer()

_unique_name = models.Constraint(
'UNIQUE(name)', 'The name must be unique.'
)
26 changes: 26 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import models, fields, api


class PropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"
_order = "sequence,name"

name = fields.Char(required=True)
property_ids = fields.One2many(
"estate.property", "property_type_id", string="Properties")
sequence = fields.Integer(
default=1, help="Used to order property types manually in the UI.")
offer_ids = fields.One2many(
"estate.property.offer", "property_type_id", string="Offers")
offer_count = fields.Integer(
compute="_compute_offer_count")

_unique_name = models.Constraint(
'UNIQUE(name)', 'The name must be unique.'
)

@api.depends('offer_ids')
def _compute_offer_count(self):
for property_type in self:
property_type.offer_count = len(property_type.offer_ids)
12 changes: 12 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class ResUsers(models.Model):
_inherit = "res.users"

# Add a domain to the field so it only lists the available properties.
property_ids = fields.One2many(
comodel_name="estate.property", inverse_name="salesperson_id",
domain=[('state', 'in', ['new', 'offer_received']),
('active', '=', True)],
)
5 changes: 5 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_menu_advertisements" name="Advertisements">
<menuitem id="estate_properties_menu_action" action="estate_property_action"/>
</menuitem>
</menuitem>
</odoo>
44 changes: 44 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>


<record id="estate_property_offer_view_list" model="ir.ui.view">
<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
<field name="price"/>
<field name="partner_id" width="200"/>
<field name="validity" string="Validity (days)" width="100%"/>
<field name="date_deadline"/>
<button name="action_accept_offer" type="object" title="Accept" icon="fa-check" invisible="status in ['accepted', 'refused'] or property_state in ['offer_accepted', 'sold', 'cancelled']"/>
<button name="action_refuse_offer" type="object" title="Refuse" icon="fa-times" invisible="status in ['accepted', 'refused'] or property_state in ['offer_accepted', 'sold', 'cancelled']"/>
</list>
</field>
</record>

<record id="estate_property_offer_view_form" model="ir.ui.view">
<field name="name">estate.property.offer.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="validity" string="Validity (days)"/>
<field name="date_deadline"/>
<field name="status"/>
</group>
</sheet>
</form>
</field>

</record>
</odoo>
8 changes: 8 additions & 0 deletions estate/views/estate_property_tag_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_menu_settings" name="Settings">
<menuitem id="estate_property_tags_menu_action" action="estate_property_tag_action"/>
</menuitem>
</menuitem>
</odoo>
Loading