Skip to content
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',
'version': '1.0',
'category': 'Real Estate',
'depends': ['base'],
'author': 'snrav-odoo',
'license': 'LGPL-3',
'description': 'Real estate purchase & sales',
'data': [
'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_property_menu.xml'
],
'application': True,
}
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
105 changes: 105 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from dateutil.relativedelta import relativedelta
from odoo import models, api, fields, exceptions
from odoo.exceptions import ValidationError
Comment on lines +1 to +3

Choose a reason for hiding this comment

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

Suggested change
from dateutil.relativedelta import relativedelta
from odoo import models, api, fields, exceptions
from odoo.exceptions import ValidationError
from dateutil.relativedelta import relativedelta
from odoo import models, api, fields, exceptions
from odoo.exceptions import ValidationError



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

Choose a reason for hiding this comment

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

Should be one line empty after it.

_check_expected_price = models.Constraint(
"CHECK(expected_price > 0)", "Expected price must be strictly positive."
)
_check_selling_price = models.Constraint(
"CHECK(selling_price >= 0)", "Selling price must be positive."
)
Comment on lines +9 to +14

Choose a reason for hiding this comment

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

It is good if we can declare it after the field declaration. You can refer odoo codebase.

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
copy=False,
default=lambda self: fields.Date.context_today(self) + relativedelta(months=3),
)
expected_price = fields.Float(required=True)
selling_price = fields.Float()
bedrooms = fields.Integer(default=2)
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area (sqft)")
garden_orientation = fields.Selection([
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
])
state = fields.Selection(
selection=[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
string="Status",
default="new",
)
active = fields.Boolean(default=False)

Choose a reason for hiding this comment

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

Why default False?

property_type_id = fields.Many2one("estate.property.type", string="Property Type", required=True)
customer = fields.Many2one("res.partner", string="Customer", copy=False)
salesperson = 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="Offer")
total_area = fields.Integer(compute="_total_area")

Choose a reason for hiding this comment

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

It is good that we can start the compute method with _compute_fieldname.So others can easily identify by the name.

best_price = fields.Integer(compute="_best_price")

@api.depends("living_area", "garden_area")
def _total_area(self):
for record in self:
record.total_area = record.living_area + record.garden_area

@api.depends("offer_ids.price")
def _best_price(self):
for record in self:
if not record.mapped("offer_ids.price"):
record.best_price = 0
else:
record.best_price = max(record.mapped("offer_ids.price"))

@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_sold_property(self):
for record in self:
if record.state == "cancelled":
raise exceptions.UserError("Properties which are Cancelled cannot be Sold")
else:
record.state = "sold"
Comment on lines +81 to +85

Choose a reason for hiding this comment

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

It's good to make the error message translatable.
raise exceptions.UserError(_("Properties which are Cancelled cannot be Sold"))

We can use filtered() here.

if self.filtered(lamda x: x.state=="cancelled")

return True

def action_cancel_offer(self):
for record in self:
if record.state == "sold":
raise exceptions.UserError("Properties which are Sold cannot be Cancelled")

Choose a reason for hiding this comment

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

It's good to make the error message translatable.
raise exceptions.UserError(_("Properties which are Sold cannot be Cancelled"))

We can use filtered() here.

if self.filtered(lamda x: x.state=="sold")

else:
record.state = "cancelled"
return True

@api.constrains("selling_price", "expected_price")
def _check_selling_price_percentage_criteria(self):
for record in self:
selling_price_percentage = (record.selling_price / record.expected_price) * 100
if selling_price_percentage >= 90 or selling_price_percentage == 0:
pass
else:
raise ValidationError(
"The selling price cannot be lower then 90% of the expected price."
)
43 changes: 43 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dateutil.relativedelta import relativedelta
from odoo import models, api, fields


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Estate Property Offer"
_check_price = models.Constraint(
"CHECK(price > 0)", "Price of an offer must be positive"
)
price = fields.Float()
status = fields.Selection(
selection=[("accepted", "Accepted"), ("refused", "Refused")], copy=False
)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(default=7)
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_date")

@api.depends("validity")
def _compute_deadline(self):
for record in self:
base_date = record.create_date or fields.Date.today()
record.date_deadline = base_date + relativedelta(days=record.validity)

def _inverse_date(self):
for record in self:
base_date = record.create_date or fields.Date.today()
record.validity = (record.date_deadline - fields.Date.to_date(base_date)).days

def action_accept(self):
for record in self:
record.status = "accepted"
record.property_id.selling_price = record.price
record.property_id.customer = record.partner_id
return True

def action_refuse(self):
for record in self:
record.status = "refused"
record.property_id.selling_price = 0.00
record.property_id.customer = None
return True
10 changes: 10 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class EstatePropertyTags(models.Model):
_name = "estate.property.tag"
_description = "Estate Property Tag"
_check_tag_name = models.Constraint(
"UNIQUE(name)", "Property tag should be unique."
)
name = fields.Char(required=True)
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 models, fields


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Estate Property Type"
_check_type_name = models.Constraint(
"UNIQUE(name)", "Property type should be unique."
)
name = fields.Char(required=True)
6 changes: 6 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
estate.access_estate_property,"access_estate_property",estate.model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_type,"access_estate_property_type",estate.model_estate_property_type,base.group_user,1,1,1,1
estate.access_estate_property_tag,"access_estate_property_tag",estate.model_estate_property_tag,base.group_user,1,1,1,1
estate.access_estate_property_offer,"access_estate_property_offer",estate.model_estate_property_offer,base.group_user,1,1,1,1

36 changes: 36 additions & 0 deletions estate/views/estate_property_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<odoo>
<menuitem
id="estate_property_menu_root"
name="Real Estate"
/>
<menuitem
id="estate_property_menu_advertisement"
name="Advertisement"
parent="estate_property_menu_root"
/>
<menuitem
id="estate_property_menu_type"
name="Properties"
parent="estate_property_menu_advertisement"
action="main_action_estate"
/>
<menuitem
id="estate_menu_configuration"
name="Settings"
parent="estate_property_menu_root"
/>
<menuitem
id="configuration_menu_property_types"
name="Property Types"
parent="estate_menu_configuration"
action="action_estate_property_type"
/>
<menuitem
id="configuration_menu_property_tags"
name="Property Tags"
parent="estate_menu_configuration"
action="action_estate_property_tag"
/>
</odoo>

43 changes: 43 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<odoo>
<record id="action_estate_property_offer" 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>

<record id="action_estate_offer_view_list" model="ir.ui.view">

Choose a reason for hiding this comment

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

Indentation issue.Should be one tab.

<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list string="Channel">
<field name="price"/>
<field name="partner_id"/>
<field name="validity" string="Validity(days)"/>
<field name="date_deadline"/>
<button name="action_accept" string="Accept" type="object" icon="fa-check" />
<button name="action_refuse" string="Refuse" type="object" icon="fa-times" />
<field name="status"/>
</list>
</field>
</record>

<record id="action_estate_offer_view_form" model="ir.ui.view">

Choose a reason for hiding this comment

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

Indentation issue.Should be one tab.

<field name="name">estate.property.offer.form</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<form string="Offer">
<sheet>
<group>
<field name="price" />
<field name="partner_id" />
<field name="status" />
<field name="validity" string="Validity(days)"/>
<field name="date_deadline"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>

24 changes: 24 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<odoo>
<record id="action_estate_property_tag" model="ir.actions.act_window">
<field name="name">Properties Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create your first Property Tag!
</p>
</field>
</record>

<record id="action_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="Tag">
<field name="name"/>
</list>
</field>
</record>
</odoo>

25 changes: 25 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<odoo>
<record id="action_estate_property_type" model="ir.actions.act_window">
<field name="name">Properties Types</field>
<field name="res_model">estate.property.type</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create your first Property Type!
</p>
</field>
</record>


<record id="action_estate_property_type_view_list" model="ir.ui.view">
<field name="name">estate.property.type.list</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<list string="Types">
<field name="name" string="Type"/>
</list>
</field>
</record>
</odoo>

Loading