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
20 changes: 20 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Real Estate",
"depends": ["base"],
"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/demo_types.xml",
"data/demo_tags.xml",
"data/demo_property.xml",
],
"application": True,
"author": "dhruvi kalariya",
"license": "LGPL-3",
"installable": True,
}
38 changes: 38 additions & 0 deletions estate/data/demo_property.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="demo_property1" model="estate.property">
<field name="name">House in ahemedabad</field>
<field name="expected_price">700000</field>
<field name="description">near sg highway</field>
<field name="postcode">123456</field>
<field name="expected_price">123456</field>
<field name="bedrooms">3</field>
<field name="living_area">180</field>
<field name="facades">2</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">120</field>
<field name="garden_orientation">south</field>
<field name="active">True</field>
<field name="property_type_id" ref="estate_demo_types1"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_demo_tag_cozy'), ref('estate_demo_tag_luxury')])]"></field>
</record>

<record id="demo_property2" model="estate.property">
<field name="name">Flat in surat</field>
<field name="expected_price">500000</field>
<field name="description">near station</field>
<field name="postcode">543210</field>
<field name="expected_price">123456</field>
<field name="bedrooms">3</field>
<field name="living_area">180</field>
<field name="facades">2</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">120</field>
<field name="garden_orientation">west</field>
<field name="active">True</field>
<field name="property_type_id" ref="estate_demo_types1"/>
<field name="tag_ids" eval="[(6, 0, [ref('estate_demo_tag_cozy')])]"></field>
</record>
</odoo>
22 changes: 22 additions & 0 deletions estate/data/demo_tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="estate_demo_tag_renovated" model="estate.property.tag">
<field name="name">Renovated</field>
</record>

<record id="estate_demo_tag_cozy" model="estate.property.tag">
<field name="name">Cozy</field>
</record>

<record id="estate_demo_tag_luxury" model="estate.property.tag">
<field name="name">Luxury</field>
</record>

<record id="estate_demo_tag_pool" model="estate.property.tag">
<field name="name">With Pool</field>
</record>

<record id="estate_demo_tag_view" model="estate.property.tag">
<field name="name">Sea View</field>
</record>
</odoo>
14 changes: 14 additions & 0 deletions estate/data/demo_types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="estate_demo_types" model="estate.property.type">
<field name="name">Residential</field>
</record>

<record id="estate_demo_types1" model="estate.property.type">
<field name="name">Commercial</field>
</record>

<record id="estate_demo_types2" model="estate.property.type">
<field name="name">Industrial</field>
</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_type
from . import estate_property_tag
from . import estate_property_offer
124 changes: 124 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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


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

name = fields.Char(string="Title", required=True, default="Unknown")
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
date_availability = fields.Date(
string="Available From",
copy=False,
default=lambda self: fields.Date.context_today(self) + relativedelta(months=3),
)
expected_price = fields.Float(
string="Expected Price", required=True, digits=(16, 2)
)
selling_price = fields.Float(string="Selling Price", readonly=True, copy=False)
bedrooms = fields.Integer(string="Bedrooms", default=2)
living_area = fields.Integer(string="Living Area (sqm)")
facades = fields.Integer(string="Facades")
garage = fields.Boolean(string="Garage")
garden = fields.Boolean(string="Garden")
garden_area = fields.Integer(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
],
string="Garden Orientation",
)
active = fields.Boolean(string="Active", default=True)
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
string="Status",
copy=False,
default="new",
readonly=True,
)
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False)
salesperson_id = fields.Many2one(
"res.users",
string="Salesperson",
default=lambda self: self.env.user,
)
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
total_area = fields.Integer(
string="Total Area (sqm)", compute="_compute_total_area"
)
best_price = fields.Float(string="Best Price", compute="_compute_best_price")

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

@api.constrains("expected_price", "selling_price")
def _check_price_difference(self):
for record in self:
if (
not float_is_zero(record.selling_price, precision_digits=2)
and float_compare(
record.selling_price,
record.expected_price * 0.9,
precision_digits=2,
)
< 0
):
raise ValidationError(
"The selling price cannot be lower than 90% of the expected price."
)

@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 record in self:
record.best_price = (
max(record.offer_ids.mapped("price")) if record.offer_ids else 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

def action_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError("You can not sold a cancelled property.")
record.state = "sold"
return True

def action_cancel(self):
for record in self:
if record.state == "sold":
raise UserError("You can not cancel a sold property.")
record.state = "cancelled"
return True
75 changes: 75 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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(string="Price")

_check_price = models.Constraint(
"CHECK(price > 0)", "An offer price must be strictly positive."
)
status = fields.Selection(
[
("accepted", "Accepted"),
("rejected", "Rejected"),
],
string="Status",
copy=False,
)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one(
"estate.property", string="Property", required=True, ondelete="cascade"
)
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 offer in self:
start_date = (
offer.create_date.date() if offer.create_date else fields.Date.today()
)
offer.date_deadline = start_date + timedelta(days=offer.validity)

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

@api.onchange("date_deadline")
def _onchange_date_deadline(self):
self._inverse_date_deadline()

@api.model_create_multi
def create(self, vals_list):
offers = super().create(vals_list)
for offer in offers:
if offer.property_id.state == "new":
offer.property_id.state = "offer_received"
return offers

def action_accept(self):
for offer in self:
offer.status = "accepted"
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id
offer.property_id.state = "offer_accepted"
return True

def action_reject(self):
for offer in self:
offer.status = "rejected"
return True
18 changes: 18 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import randint

from odoo import fields, models


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

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

name = fields.Char(string="Name", required=True)
color = fields.Integer(
string="Color Index", default=lambda self: self._default_color()
)

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


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

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

_check_name = models.Constraint("UNIQUE(name)", "Type name must be unique")
28 changes: 28 additions & 0 deletions estate/security/estate_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="model_category_real_estate" model="ir.module.category">
<field name="name">Real Estate</field>
</record>

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

<record id="res_groups_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="res_groups_buyer" model="res.groups">
<field name="name">Buyer</field>
<field name="privilege_id" ref="res_groups_privilege_estate"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="res_groups_owner" model="res.groups">
<field name="name">Owner</field>
<field name="privilege_id" ref="res_groups_privilege_estate"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
</odoo>
20 changes: 20 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_estate_property,estate_property_access,model_estate_property,base.group_user,1,1,1,1
access_estate_property_agent,estate_property_agent,model_estate_property,estate.res_groups_agent,1,1,1,1
access_estate_property_buyer,estate_property_buyer,model_estate_property,estate.res_groups_buyer,1,0,0,0
access_estate_property_owner,estate_property_owner,model_estate_property,estate.res_groups_owner,1,1,1,1

access_estate_property_type,estate_property_type_access,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_type_agent,estate_property_type_agent,model_estate_property_type,estate.res_groups_agent,1,1,1,1
access_estate_property_type_buyer,estate_property_type_buyer,model_estate_property_type,estate.res_groups_buyer,1,0,0,0
access_estate_property_type_owner,estate_property_type_owner,model_estate_property_type,estate.res_groups_owner,1,1,1,1

access_estate_property_tag,estate_property_tag_access,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_tag_agent,estate_property_tag_agent,model_estate_property_tag,estate.res_groups_agent,1,1,1,1
access_estate_property_tag_buyer,estate_property_tag_buyer,model_estate_property_tag,estate.res_groups_buyer,1,0,0,0
access_estate_property_tag_owner,estate_property_tag_owner,model_estate_property_tag,estate.res_groups_owner,1,1,1,1

access_estate_property_offer,estate_property_offer_access,model_estate_property_offer,base.group_user,1,1,1,1
access_estate_property_offer_agent,estate_property_offer_agent,model_estate_property_offer,estate.res_groups_agent,1,1,1,1
access_estate_property_offer_buyer,estate_property_offer_buyer,model_estate_property_offer,estate.res_groups_buyer,1,0,0,0
access_estate_property_offer_owner,estate_property_offer_owner,model_estate_property_offer,estate.res_groups_owner,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.
Loading