Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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": "Real Estate",
"author": "Odoo S.A.",
"license": "LGPL-3",
"depends": ["base"],

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 if we don't write base 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.

If we don't write base, Odoo will still load it automatically. However, writing it explicitly is a best practice to make the module dependency clear.

"data": [
"security/estate_security.xml",
"security/ir.model.access.csv",
"views/estate_property_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_tag_views.xml",
"views/estate_property_offer_views.xml",
"views/estate_menus.xml",
"data/estate_demo.xml",
],
"application": True,
"installable": True,
}
72 changes: 72 additions & 0 deletions estate/data/estate_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="estate_property_type_residential" model="estate.property.type">
<field name="name">Residential</field>
</record>
<record id="estate_property_type_commercial" model="estate.property.type">
<field name="name">commercial</field>
</record>

<record id="estate_property_tag_cozy" model="estate.property.tag">
<field name="name">Cozy</field>
<field name="description">Cozy property tag</field>
</record>
<record id="estate_property_tag_cool" model="estate.property.tag">
<field name="name">Cool</field>
<field name="description">Cool property tag</field>
</record>
<record id="estate_property_tag_nice" model="estate.property.tag">
<field name="name">Nice</field>
<field name="description">Nice property tag</field>
</record>

<record id="estate_property_demo_1" model="estate.property">
<field name="name">vrushibh Apartment</field>
<field name="expected_price">75000.00</field>
<field name="bedrooms">4</field>
<field name="living_area">250</field>
<field name="postcode">35000</field>
<field name="date_availability">2026-09-15</field>
<field name="property_type_id" ref="estate_property_type_residential"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_cool'), ref('estate_property_tag_nice')])]"/>
</record>

<record id="estate_property_demo_2" model="estate.property">
<field name="name">Cozy Apartment</field>
<field name="expected_price">200000.00</field>
<field name="bedrooms">2</field>
<field name="living_area">85</field>
<field name="postcode">380001</field>
<field name="property_type_id" ref="estate_property_type_commercial"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_property_tag_cool'), ref('estate_property_tag_nice')])]"/>
</record>

<record id="estate_property_demo_3" model="estate.property">
<field name="name">nice Apartment</field>
<field name="expected_price">206000.00</field>
<field name="bedrooms">2</field>
<field name="living_area">85</field>
<field name="postcode">380001</field>
<field name="property_type_id" ref="estate_property_type_commercial"/>
</record>

<record id="estate_property_demo_4" model="estate.property">
<field name="name">cool Apartment</field>
<field name="expected_price">206000.00</field>
<field name="bedrooms">2</field>
<field name="living_area">85</field>
<field name="postcode">380001</field>
<field name="property_type_id" ref="estate_property_type_commercial"/>
</record>

<record id="estate_property_demo_5" model="estate.property">
<field name="name">jumbo Apartment</field>
<field name="expected_price">206000.00</field>
<field name="bedrooms">2</field>
<field name="living_area">85</field>
<field name="postcode">380001</field>
<field name="property_type_id" ref="estate_property_type_commercial"/>
</record>

</odoo>
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_tag
from . import estate_property_type
from . import estate_property_offer
99 changes: 99 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from dateutil.relativedelta import relativedelta

from odoo import api, fields, models


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

name = fields.Char(required=True, string="Property Name")
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
default=lambda self: fields.Date.context_today(self) + relativedelta(months=3),
)
expected_price = fields.Float(required=True, copy=False, default=0.0)
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(
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
],
Comment thread
vrushibh marked this conversation as resolved.
string="Garden Orientation",
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
required=True,
copy=False,
default="new",
string="State",
)
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
salesperson_id = fields.Many2one(
"res.users",
string="Salesperson",
default=lambda self: self.env.user,
)
tag_ids = fields.Many2many("estate.property.tag", string="Property Tags")
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")

total_area = fields.Integer(
string="Total Area (sqm)",
compute="_compute_total_area",
help="Total area of the property (living area + garden area)",
)
best_price = fields.Float(
string="Best Offer",
compute="_compute_best_price",
help="The highest offer received for this property",
store="true",
)
squre_area = fields.Integer(
string="Squre Area",
compute="_compute_total_squre",
)

@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("total_area")
def _compute_total_squre(self):
for record in self:
record.squre_area = record.total_area * record.total_area

@api.depends("offer_ids.price")
def _compute_best_price(self):
for record in self:
prices = record.offer_ids.mapped("price")
if prices:
record.best_price = max(prices)
else:
record.best_price = 0.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
48 changes: 48 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from datetime import timedelta

from odoo import api, fields, models


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

price = fields.Float(required=True)
status = fields.Selection(
selection=[
('accepted', 'Accepted'),
('rejected', 'Rejected'),
],
copy=False,
string="Status",
)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(string="Validity", default=7)
date_deadline = fields.Date(
string="Deadline",
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
)

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

def _inverse_date_deadline(self):
for record in self:
if record.create_date:
create_date = record.create_date.date()
else:
create_date = fields.Date.today()
if record.date_deadline:
record.validity = (record.date_deadline - create_date).days

@api.onchange("date_deadline")
def _onchange_date_deadline(self):
self._inverse_date_deadline()
19 changes: 19 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from random import randint

from odoo import fields, models


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"
_rec_name = 'name'

def _default_color(self):
return randint(1, 11)

name = fields.Char(required=True)
description = fields.Char(required=True)
color = fields.Integer(
string='Color Index',
default=lambda self: self._default_color(),
)
17 changes: 17 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, fields, models


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"
_rec_names_search = ["name", "code"]

name = fields.Char(required=True, string="Property Type")
code = fields.Char(string="Code")

@api.depends("name", "code")
def _compute_display_name(self):
for record in self:
record.display_name = (
f"{record.name} [{record.code}]" if record.code else record.name
)
27 changes: 27 additions & 0 deletions estate/security/estate_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="module_category_real_estate" model="ir.module.category">
<field name="name">Real Estate</field>
<field name="sequence">10</field>
</record>

<record id="res_groups_privilege_estate" model="res.groups.privilege">
<field name="name">Access Level</field>
<field name="category_id" ref="module_category_real_estate"/>
</record>

<record id="estate_group_agent" model="res.groups">
<field name="name">Agent</field>
<field name="privilege_id" ref="res_groups_privilege_estate"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="estate_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="privilege_id" ref="res_groups_privilege_estate"/>
<field name="implied_ids" eval="[(4, ref('estate_group_agent'))]"/>
<field name="user_ids" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>

</odoo>
9 changes: 9 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_estate_property_agent,access_estate_property_agent,model_estate_property,estate_group_agent,1,1,1,0
access_estate_property_manager,access_estate_property_manager,model_estate_property,estate_group_manager,1,1,1,1
access_estate_property_type_agent,access_estate_property_type_agent,model_estate_property_type,estate_group_agent,1,1,1,1
access_estate_property_type_manager,access_estate_property_type_manager,model_estate_property_type,estate_group_manager,1,1,1,1
access_estate_property_tag_agent,access_estate_property_tag_agent,model_estate_property_tag,estate_group_agent,1,1,1,1
access_estate_property_tag_manager,access_estate_property_tag_manager,model_estate_property_tag,estate_group_manager,1,1,1,1
access_estate_property_offer_agent,access_estate_property_offer_agent,model_estate_property_offer,estate_group_agent,1,1,1,1
access_estate_property_offer_manager,access_estate_property_offer_manager,model_estate_property_offer,estate_group_manager,1,1,1,1
Binary file added estate/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<menuitem
id="estate_menu_root"
name="Real Estate"
sequence="10"
web_icon="estate,static/description/icon.png"/>

<menuitem
id="estate_property_menu_advertisements"
name="Advertisements"
parent="estate_menu_root"
sequence="10"/>

<menuitem
id="estate_property_menu"
name="Properties"
parent="estate_property_menu_advertisements"
action="estate_property_action"
sequence="10"/>

<menuitem
id="estate_property_menu_settings"
name="Settings"
parent="estate_menu_root"
sequence="20"/>

<menuitem
id="estate_property_type_menu"
name="Property Types"
parent="estate_property_menu_settings"
action="estate_property_type_action"
sequence="10"/>

<menuitem
id="estate_property_offers_menu"
name="Offers Type"
parent ="estate_property_menu_settings"
action="estate_property_offers_action"
/>
<menuitem
id="estate_property_tag_menu"
name="Tag Types"
parent ="estate_property_menu_settings"
action="estate_property_tag_action"
/>

</odoo>
Loading