Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d87cc90
[ADD] estate: initial module setup
amtha-odoo Jul 2, 2026
350ef88
[IMP] estate: added estate_property model
amtha-odoo Jul 2, 2026
bdaafbc
[LINT] Fix Code Formatting
amtha-odoo Jul 3, 2026
95e2760
[LINT] Fix Code Formatting and add module license
amtha-odoo Jul 3, 2026
5371919
[LINT] Fix Code Formatting and add lincense data and add security fil…
amtha-odoo Jul 3, 2026
f888899
[LINT] Fix Code Formatting and add lincense data and add security fil…
amtha-odoo Jul 3, 2026
a6e7ce2
[IMP] estate: add basic UI and property defaults
amtha-odoo Jul 3, 2026
2f23484
[IMP] estate: add basic UI and property defaults
amtha-odoo Jul 3, 2026
6583a65
[IMP] estate: add custom list and form views
amtha-odoo Jul 6, 2026
7481584
[IMP] estate: Add search view for estate properties
amtha-odoo Jul 7, 2026
5da110c
[ADD] estate: add property type model and relation
amtha-odoo Jul 8, 2026
9533150
[IMP] estate: add menus for property type and tag and custom search view
amtha-odoo Jul 9, 2026
bab61c0
[IMP] estate: add security access rules and update __init__.py and ma…
amtha-odoo Jul 9, 2026
f9dce55
[IMP] estate: Add property types, tags, offers, and model relations
amtha-odoo Jul 9, 2026
9f22c07
[IMP] estate: Add computed total_area field using @api.depends
amtha-odoo Jul 13, 2026
0b416ba
[IMP] estate: add total-area, best-price, offer validity and deadline
amtha-odoo Jul 23, 2026
9d5c18a
[IMP] estate: Add actions for property and offer management
amtha-odoo Jul 28, 2026
cb60158
[IMP] estate: add Sql constraints for selling price,expected price,pr…
amtha-odoo Jul 31, 2026
05d7e93
[LINT] estate: fix check type error
amtha-odoo Jul 31, 2026
26ccc80
[IMP] estate: add python constrains for selling price and expected pr…
amtha-odoo Aug 11, 2026
b00f3b5
[IMP] estate: Apply code review feedback and improve code style
amtha-odoo Aug 13, 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
17 changes: 17 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Estate",
"version": "1.0",
"depends": ["base"],
"application": True,
"category": "Tutorials",
"author": "Odoo S.A",
"license": "LGPL-3",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other options are there for licensing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/odoo/odoo19/community/odoo/addons/base/models/ir_module.py == line no. : 296

GPL-2,GPL-3,AGPL-3,LGPL-3,OEEL-1,OPL-1

"data": [
"security/ir.model.access.csv",
"view/estate_property_views.xml",
"view/estate_property_type_views.xml",
"view/estate_property_tag_views.xml",
"view/estate_property_offer_views.xml",
"view/estate_menus.xml",
],
}
4 changes: 4 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
138 changes: 138 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
from datetime import timedelta
from odoo import fields, models, api
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare, float_is_zero


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Estate Property"

name = fields.Char(required=True)
total_area = fields.Integer(compute="_compute_total_area")
description = fields.Text()
postcode = fields.Char()
property_type_id = fields.Many2one(
"estate.property.type",
)
buyer_id = fields.Many2one(
"res.partner",
copy=False,
)
salesperson_id = fields.Many2one(
"res.users",
default=lambda self: self.env.user,
Comment on lines +15 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add string explicitly if you want it to be similar to the field name itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove string attributes from fields where the default field label is already appropriate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string /home/odoo/odoo19/community/odoo/orm/fields.py line no. = 508 =>Odoo automatically generates the UI label from the field's technical name.

)
tag_ids = fields.Many2many(
"estate.property.tag",
string="Tags",
)
offer_ids = fields.One2many(
"estate.property.offer",
"property_id",
string="Offers",
)
best_price = fields.Float(
string="Best Offer",
compute="_compute_best_price",
)
date_availability = fields.Date(
copy=False,
default=lambda self: fields.Date.today() + timedelta(days=90),
)
expected_price = fields.Float()
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"),
]
)
Comment on lines +54 to +61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
garden_orientation = fields.Selection(
[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
]
)
garden_orientation = fields.Selection(
[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
]
)

Try to keep the key i.e the technical strings in single quotes and the values which are to be displayed to the user in double quotes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

active = fields.Boolean(default=True)
state = fields.Selection(
[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
required=True,
copy=False,
default="new",
)

_check_selling_price = models.Constraint(
"CHECK(selling_price >= 0)",
"A property selling price must be positive",
)

_check_expected_price = models.Constraint(
"CHECK(expected_price > 0)",
"A property expected price must be strictly 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.price")
def _compute_best_price(self):
for property in self:
if property.offer_ids:
property.best_price = max(property.offer_ids.mapped("price"))
else:
property.best_price = 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 = False

@api.constrains("selling_price", "expected_price")
def check_price(self):
for record in self:
if float_is_zero(record.selling_price, precision_rounding=0.01):
continue
minimum_price = record.expected_price * 0.9
if (
float_compare(
record.selling_price,
minimum_price,
precision_rounding=0.01,
)
< 0
):
raise ValidationError(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would you raise UserError and ValidationError?
What is the difference between both of them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserError : use when the user perform invalid action.usually use in button and action methods and stop the current operation
ValidationError : use when data violates a validation.prevents invalid data from being saved.

Both will show an error popup to the user, but UserError is used when a user performs an action that is not allowed, and ValidationError is used when entered or modified data fails a validation

" the selling price cannot be lower than 90% of the expected price"
)

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

def action_cancel(self):
for record in self:
if record.state == "sold":
raise UserError("Sold property cannot be cancelled.")
record.state = "cancelled"
return True
62 changes: 62 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from odoo import fields, models, api
from datetime import timedelta


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Property Offer"

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

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

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

def _inverse_date_deadline(self):
for record in self:
if record.create_date and record.deadline:
record.validity = (record.deadline - record.create_date.date()).days

def action_confirm(self):
for record in self:
record.status = "accepted"
record.property_id.selling_price = record.price
record.property_id.buyer_id = record.partner_id

def action_cancel(self):
for record in self:
record.status = "refused"
13 changes: 13 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Property Tag"

name = fields.Char(required=True)

_check_tag_name = models.Constraint(
"UNIQUE(name)",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this unique work for all the case?

"A property tag name must be unique",
)
13 changes: 13 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Property Type"

name = fields.Char(required=True)

_check_property_type_name = models.Constraint(
"UNIQUE(name)",
"A property type name must be unique",
)
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_tag,estate.property.tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,estate.property.offer,model_estate_property_offer,base.group_user,1,1,1,1
access_estate_property_type,estate.property.type,model_estate_property_type,base.group_user,1,1,1,1
27 changes: 27 additions & 0 deletions estate/view/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!--TOP MENU-->
<menuitem id="estate_menu_root" name="Real Estate"/>
<!--CATEGORY MENU-->
<menuitem id="estate_property_menu"
name="Advertisements"
parent="estate_menu_root"/>
<menuitem id="estate_property_menu1"
name="Setting"
parent="estate_menu_root"/>
<menuitem id="estate_property_menu_action"
name="Properties"
parent="estate_property_menu"
action="estate_property_action"/>
<menuitem
id="estate_property_type_menu"
name="Property Types"
parent="estate_property_menu1"
action="estate_property_type_action"/>
<menuitem
id="estate_property_tag_menu"
name="Property Tags"
parent="estate_property_menu1"
action="estate_property_tag_action"
/>
</odoo>
45 changes: 45 additions & 0 deletions estate/view/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Action -->
<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>
</record>
<!-- List View -->
<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 string="Property Offers">
<field name="property_id"/>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
<button name="action_confirm" string="Confirm" type="object" icon="fa-check"/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When to use type object and type action?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type = "object" : used when execute python method defined on the model.
type = "action" : used when execute an odoo action identified by its external ID.

<button name="action_cancel" string="Cancel" type="object" icon="fa-times"/>
<field name="status"/>
</list>
</field>
</record>
<!-- Form View -->
<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="property_id"/>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
<field name="status" readonly="True"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
33 changes: 33 additions & 0 deletions estate/view/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Action -->
<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>
<!-- List View -->
<record id="estate_property_tag_view_list" model="ir.ui.view">
<field name="name">estate.property.tag.list</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list string="Property Tags">
<field name="name"/>
</list>
</field>
</record>
<!-- Form View -->
<record id="estate_property_tag_view_form" model="ir.ui.view">
<field name="name">estate.property.tag.form</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<form string="Property Tag">
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
Loading