Skip to content
Draft
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
076ed51
[ADD] estate: initial module setup
ancha-odoo Jul 2, 2026
d23e871
[LINT] Fix Code Formatting
ancha-odoo Jul 3, 2026
b48be13
[IMP] estate: add missing author and license to manifest
ancha-odoo Jul 3, 2026
e27c9fc
[ADD] estate: create estate_property model and configure initial fields
ancha-odoo Jul 3, 2026
13997f0
[IMP] estate: load access control rules to manifest
ancha-odoo Jul 3, 2026
63d7e80
[IMP] estate: add first user interface
ancha-odoo Jul 6, 2026
5a323bf
[LINT] estate:remove unused imports
ancha-odoo Jul 6, 2026
84072b3
[IMP] estate: add missing author and license to manifest
ancha-odoo Jul 3, 2026
cc8b8c9
[IMP] estate: add first user interface
ancha-odoo Jul 6, 2026
ba8b5a0
[LINT] estate: remove unwanted imports
ancha-odoo Jul 6, 2026
e1c3eab
[IMP] estate: implement property UI with menus, actions, and views
ancha-odoo Jul 7, 2026
ef8a011
[IMP] estate: add property relations and offers
ancha-odoo Jul 8, 2026
4a9cc26
[LINT] estate: Fix code formatting
ancha-odoo Jul 8, 2026
5139800
[IMP] estate: add groups to the security records of property tag and …
ancha-odoo Jul 8, 2026
fbb8e20
[IMP] estate: add total-area, best-price, offer validity and deadline
ancha-odoo Jul 13, 2026
7198b8c
[IMP] estate: add property and offer actions
ancha-odoo Jul 28, 2026
2e403aa
[LINT] estate: Apply suggestions from code review
ancha-odoo Aug 10, 2026
75a635b
[IMP] estate: add SQL constraints to property-related models
ancha-odoo Aug 11, 2026
92fc8e8
[IMP] estate: complete task 10 with property price constraint
ancha-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",
"category": "",
"depends": [
"base",
],
"application": True,
"author": "Odoo S.A.",
"license": "LGPL-3",
"data": [
"security/ir.model.access.csv",
"views/estate_property.xml",
"views/estate_property_offers.xml",
"views/estate_property_types.xml",
"views/estate_property_menus.xml",
],
}
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_type,
estate_property_tags,
estate_property_offers,
)
125 changes: 125 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare


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

name = fields.Char(required=True, default="Unknown")
property_type_id = fields.Many2one("estate.property.type", string="Type")
description = fields.Text()
tag_ids = fields.Many2many("estate.property.tags", string="Tags")
salesman_id = fields.Many2one("res.users", default=lambda self: self.env.user.id)
buyer_id = fields.Many2one(
"res.partner", default=lambda self: self.env.user.id, copy=False
)
postcode = fields.Char()
date_availability = fields.Date(copy=False)
expected_price = fields.Float(required=True, default=15.6)
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()
total_area = fields.Float(compute="_compute_total_area")
best_price = fields.Float(compute="_compute_best_price")
garden_orientation = fields.Selection(
[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
],
string="Garden Orientation",
)
active = fields.Boolean(default=True)
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
Comment thread
ancha-odoo marked this conversation as resolved.
required=True,
copy=False,
default="new",
readonly=True,
)
offer_ids = fields.One2many(
"estate.property.offers", "property_id", string="Offers"
)
_check_expected_price = models.Constraint(
"CHECK(expected_price > 0)", "Expected price must be positive."
)
_check_selling_price = models.Constraint(
"CHECK(selling_price > 0)", "Property selling price must be positive."
)

@api.constrains("selling_price")
def _check_selling_price(self):
if float_compare(self.selling_price, (self.expected_price * 0.9), 2) == -1:
raise ValidationError(
"Selling Price must not be less than 90% of expected price."
)

@api.depends("living_area", "garden_area")
def _compute_total_area(self):
for realEstateProperty in self:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need a for loop here?

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.

we need it because self is a recordset and it's length is not fixed.

realEstateProperty.total_area = (
realEstateProperty.living_area + realEstateProperty.garden_area
)

# @api.onchange("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_price(self):
self.best_price = max(self.offer_ids.mapped("price")) if self.offer_ids else 0

# @api.depends("offer_ids")
# def _compute_best_price(self):
# if self.offer_ids:
# price_list=[]
# price_list.append(offer.price)
# for i in range(len(price_list)):
# for j in range(len(price_list)):
# if price_list[i]>=price_list[j]:
# self.best_price= price_list[i]
# else:
# self.best_price=0
# self.best_price = 0
# if self.offer_ids:
# for offer in self.offer_ids:
# if offer.price > self.best_price:
# self.best_price = offer.price

@api.onchange("garden")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we pass multiple arguments here?

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.

in onchange() decorator we can pass multiple arguments but they must belong to the same object
e.g.
Image

def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = ""

def set_sold(self):
if self.state == "cancelled":
raise UserError("Cancelled Properties Cannot be Sold")
else:
self.state = "sold"
return True

def set_cancel(self):
if self.state == "sold":
raise UserError("Sold Properties cannot be Cancelled")
else:
self.state = "cancelled"
return True
54 changes: 54 additions & 0 deletions estate/models/estate_property_offers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from datetime import timedelta

from odoo import models, fields, api


class EstatePropertyOffers(models.Model):
_name = "estate.property.offers"
_description = "Property Offers"

price = fields.Float(string="Price")
status = fields.Selection(
Comment on lines +10 to +11

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 explicitly pass string here if you want to have the string name same as the field name.
You can have a look at the codebase regarding how the string value is calculated if you do not pass explicitly.

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.

👍

[("accepted", "Accepted"), ("refused", "Refused")],
string="Status",
copy="False",
)
partner_id = fields.Many2one("res.partner", string="Customer", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(string="Validity", default=7)
date_deadline = fields.Date(
string="Date Deadline",
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
)
_check_offer_price = models.Constraint(
"CHECK(price > 0)", "Offer price must be positive."
)

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

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

def set_accepted(self):
for record in self:
record.status = "accepted"
record.property_id.selling_price = record.price
record.property_id.buyer_id.name = record.partner_id.name
return True

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


class EstatePropertyTags(models.Model):
_name = "estate.property.tags"
_description = "Estate Property Tags"

name = fields.Char(string="Name", required=True)
property_id = fields.Many2one(
comodel_name="estate.property",
string="Property",
)
_check_tag_name = models.Constraint(
"UNIQUE(name)", "Property tag name must be unique."
)
12 changes: 12 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Types of estate property"

name = fields.Char(string="Name", required=True)
_check_property_type = models.Constraint(
"UNIQUE(name)",
"Property type 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_type,estate.property.type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag,estate.property.tag,model_estate_property_tags,base.group_user,1,1,1,1
access_estate_property_offer,estate.property.offer,model_estate_property_offers,base.group_user,1,1,1,1
128 changes: 128 additions & 0 deletions estate/views/estate_property.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</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.tags</field>
<field name="view_mode">list,form</field>
</record>


<!--List Property view-->


<record id="estate_property_view_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list>
<field name="name"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="postcode"/>
<field name="date_availability"/>
</list>
</field>
</record>

<!--custom Property form view-->

<record id="estate_property_view_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="property">
<header>
<button name="set_sold" type="object" string="Sold"/>
<button name="set_cancel" type="object" string="Cancel"/>
</header>

<div>
<h1>
<field name="name"/>
</h1>
</div>
<group>
<group>
<field name="state"/>
<field name="postcode"/>
<field name="date_availability"/>
<field name="tag_ids" widget="many2many_tags"/>

</group>


<group>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="best_price"/>
</group>
</group>
<notebook>
<page string="Description">
<group>
<field name="description"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="garage"/>
<field name="garden"/>
<field name="garden_area"/>
<field name="garden_orientation"/>
<field name="facades"/>
<field name="total_area"/>
</group>
</page>
<page string="Offers">
<field name="offer_ids">
<list edit="true">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="set_accepted" string="Accept" 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.

What is the working of the attribute type?
What are the alternatives for the values?

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.

the attribute "type" mentions what to do when the button is clicked
type object and type action are the values that can be used.
Type Object is by default type and it calls a python method while the type Action calls a xml view when the button is triggered.

<button name="set_refused" string="Refuse" type="object" icon="fa-close"/>
<field name="status"/>
</list>
</field>
</page>
<page string="Other Info">
<group>
<field name="salesman_id"/>
<field name="buyer_id"/>
</group>
</page>
</notebook>
</form>
</field>
</record>

<!--custom Property search view-->
<record id="estate_property_view_search" model="ir.ui.view">
<field name="name">estate.property.search</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<filter name="group_by_bedrooms" string="Bedrooms" context="{'group_by':'bedrooms'}"/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WDYM by context and domain?
Can you explain with a reference of some example?

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.

Domain is a list of conditions used to filter/search records based on specific criteria.

Context is a dictionary containing additional information, parameters, or flags that are passed along with an operation and can influence how Odoo behaves in a particular situation.

Eg. domain

when we want to filter the orders based on the order price greater than 5000

context

when tasks are created, by default it must be assigned to id = 11.

<filter name="filter" string="price" domain="[('expected_price', '>', 5000)]"/>
<filter
string="Bedrooms"
name="bedrooms"
domain="[('bedrooms', '=' , 2)]"/>


</search>
</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions estate/views/estate_property_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem
id="estate_menu_root"
name="Real Estate"
>
<menuitem
id="estate_first_level_menu"
name="Advertisements"
>
<menuitem
id="estate_property_menu_action"
action="estate_property_action"
/>
</menuitem>
Comment thread
ancha-odoo marked this conversation as resolved.
<menuitem id="estate_property_second_menu" name="Settings">
<menuitem id="estate_property_type_menu" action="estate_property_type_action"/>
<menuitem id="estate_property_tags_menu" action="estate_property_tag_action"/>
</menuitem>
</menuitem>

</odoo>
Loading