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
8424d45
[ADD] estate: initialize estate module
hossamelgendy1 Jan 20, 2026
3451b71
[IMP] generic: add ruff configs
hossamelgendy1 Jan 20, 2026
1c06c66
[LINT] estate: apply ruff linting on __manifest__.py
hossamelgendy1 Jan 20, 2026
252aa28
[IMP] estate: create EstateProperty model
hossamelgendy1 Jan 20, 2026
969410c
[FIX] add manifest missing fields
hossamelgendy1 Jan 20, 2026
58c8f38
[IMP] estate: add access for estate_property
hossamelgendy1 Jan 20, 2026
9274576
[IMP] estate: follow model naming convention
hossamelgendy1 Jan 20, 2026
cb5c04b
[IMP] estate: grant access rights
hossamelgendy1 Jan 20, 2026
ca6ae73
[IMP] estate: add the estate.property form view
hossamelgendy1 Jan 21, 2026
566bdda
[LINT] adding new lines at end of files
hossamelgendy1 Jan 21, 2026
a6fb904
[IMP] estate: implement basic views
hossamelgendy1 Jan 21, 2026
54b4659
[IMP] estate: introduce new models for Property with relations
hossamelgendy1 Jan 22, 2026
8373d8e
[IMP] estate: introduce computed fields for offer and property
hossamelgendy1 Jan 26, 2026
03e3412
[IMP] fix field formatting and include property state in views
hossamelgendy1 Jan 26, 2026
67fc2fa
[IMP] estate: add actions to property and offer
hossamelgendy1 Jan 26, 2026
7088e9a
[FIX] estate: give titles to icons
hossamelgendy1 Jan 26, 2026
8c01399
[IMP] add field constraints
hossamelgendy1 Jan 26, 2026
55645e3
[IMP] estate: make accept/refuse offer actions work on one record
hossamelgendy1 Jan 26, 2026
04514c2
[IMP] estate: add UI enhancements
hossamelgendy1 Jan 28, 2026
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
18 changes: 18 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "estate",
"depends": [
"base",
],
"data": [
"security/ir.model.access.csv",
"views/estate_property_offer_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_tag_views.xml",
"views/estate_property_views.xml",
"views/estate_menus.xml",
],
"application": True,
"installable": True,
"author": "Gendi (HOELG)",
"license": "LGPL-3",
}
6 changes: 6 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import (
estate_property,
estate_property_offer,
estate_property_tag,
estate_property_type,
)
132 changes: 132 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import logging

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

logger = logging.getLogger(__name__)


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real state property"
_order = "id DESC"

name = fields.Char(required=True, string="Title")
description = fields.Text()
property_type_id = fields.Many2one(
comodel_name="estate.property.type",
string="Type",
)
postcode = fields.Char()
date_availability = fields.Date(
copy=False,
default=fields.Date.today() + relativedelta(months=3),
string="Available From",
)
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"),
],
)
total_area = fields.Integer(
compute="_compute_total_area", string="Total Area (sqm)",
)
state = fields.Selection(
selection=[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
default="new",
)
active = fields.Boolean(default=True)
seller = fields.Many2one(
comodel_name="res.users",
string="Salesman",
default=(lambda self: self.env.user),
)
buyer = fields.Many2one(
comodel_name="res.partner",
copy=False,
)
tag_ids = fields.Many2many(
comodel_name="estate.property.tag",
string="Tags",
)
offer_ids = fields.One2many(
comodel_name="estate.property.offer",
inverse_name="property_id",
string="Offers",
)
best_offer = fields.Float(compute="_compute_best_offer")

_check_positive_expected_price = models.Constraint(
"CHECK(expected_price > 0)",
"Expected Price must be positive!",
)
_check_positive_selling_price = models.Constraint(
"CHECK(selling_price > 0)",
"Selling Price must be positive!",
)
_name_uniq = models.Constraint(
"UNIQUE(name)",
"A property with this name already exists!",
)

@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
)

@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 = None

def action_cancel(self):
for record in self:
if record.state == 'sold':
raise UserError("Sold properties cannot be cancelled.")
record.state = "cancelled"

def action_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError("Cancelled properties cannot be sold")
record.state = "sold"

@api.constrains("selling_price", "expected_price")
def _check_reasonable_selling_price(self):
for record in self:
if (
not float_is_zero(record.selling_price, precision_digits=2)
and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) == -1
):
raise ValidationError("Selling price cannot be lower than 90% of the expected price")
70 changes: 70 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import timedelta

from odoo import api, fields, models
from odoo.exceptions import UserError


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "an amount a potential buyer offers to the seller"
_order = "price DESC"

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

_check_positive_price = models.Constraint(
"CHECK(price > 0)",
"Offer price must be positive!",
)

@api.depends("validity", "create_date")
def _compute_date_deadline(self):
for record in self:
record.date_deadline = (
record.create_date or fields.Date.today()
) + timedelta(days=record.validity)

def _inverse_date_deadline(self):
for record in self:
record.validity = (
record.date_deadline - fields.Date.to_date(record.create_date)
).days

def action_refuse(self):
self.ensure_one()
self.status = "refused"

def action_accept(self):
self.ensure_one()
# TODO: property state should be readonly and just check on state == 'offer_accepted'
if any(offer.status == 'accepted' for offer in self.property_id.offer_ids):
raise UserError("Property already has another accepted offer.")
# TODO: consider checking other property states
self.status = "accepted"
self.property_id.buyer = self.partner_id
self.property_id.selling_price = self.price
self.property_id.state = 'offer_accepted'
15 changes: 15 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class PropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Tag to be applied to a property"
_order = "name"

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

_name_uniq = models.Constraint(
"UNIQUE(name)",
"A property tag with this name already exists!",
)
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 api, fields, models


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Type of a real estate property"
_order = "sequence, name"

name = fields.Char(required=True)
sequence = fields.Integer("Sequence", default=1, help="Used to order property types. Lower is better.")
property_ids = fields.One2many(
comodel_name="estate.property",
inverse_name="property_type_id",
string="Properties",
)
offer_ids = fields.One2many(
comodel_name="estate.property.offer",
inverse_name="property_type_id",
string="Offers",
)
offer_count = fields.Integer(compute="_compute_offer_count", string="Offer count")

@api.depends("offer_ids")
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
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
12 changes: 12 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="advertisement" name="Advertisement">
<menuitem id="estate_property_menu_action" action="estate_property_action"/>
</menuitem>
<menuitem id="settings" name="Settings">
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_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_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 string="Property Offer">
<sheet>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="estate_property_offer_view_tree" 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"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_accept" title="Accept" type="object" icon="fa-check" invisible="status"/>
<button name="action_refuse" title="Refuse" type="object" icon="fa-times" invisible="status"/>
</list>
</field>
</record>

<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Property offer</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>
</odoo>
18 changes: 18 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_tag_view_tree" model="ir.ui.view">
<field name="name">estate.property.tag.view.list</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list string="Tags" editable="bottom">
<field name="name"/>
</list>
</field>
</record>

<record id="estate_property_tag_action" model="ir.actions.act_window">
<field name="name">Property Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
</record>
</odoo>
Loading