Skip to content
Open
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
15 changes: 15 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Real Estate",
"application": True,
"installable": True,
"category": "Real Estate/Brokerage",
"data": [
"security/ir.model.access.csv",
"views/estate_property_views.xml",
"views/estate_property_offer_views.xml",
"views/estate_property_type_views.xml",
"views/estate_property_tag_views.xml",
"views/estate_menus.xml",
],
"license": "LGPL-3",
}
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
123 changes: 123 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from datetime import timedelta
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero


class EstateModel(models.Model):
_name = "estate.property"
_description = "Real Estate Advertisement Model"
_order = "id desc"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
copy=False,
default=fields.Date.today() + timedelta(days=90),
)
active = fields.Boolean(default=True)
expected_price = fields.Float(required=True)
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()
state = fields.Selection(

Choose a reason for hiding this comment

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

state field should display in the header of the form view.

Choose a reason for hiding this comment

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

Can you please make these changes?

string="State",
default="new",
required=True,
copy=False,
selection=[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
)
garden_orientation = fields.Selection(
string="Garden Orientation",
selection=[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
],
help="Select the direction the garden faces",
)
property_type_id = fields.Many2one("estate.property.type")
buyer = fields.Many2one("res.partner", readonly=True)
salesman = fields.Many2one("res.users")
tag_ids = fields.Many2many("estate.property.tag")
offer_ids = fields.One2many("estate.property.offer", inverse_name="property_id")
total_area = fields.Float(compute="_compute_total_area", store=True)
best_price = fields.Float(compute="_compute_best_price", store=True, default=0.0)

_sql_constraints = [
(
"check_property_expected_price",
"CHECK(expected_price > 0)",
"Property Expected Price must be a valid value",
),
(
"check_property_selling_price",
"CHECK(selling_price >= 0)",
"Property Selling Price must be positive",
),
]

@api.constrains("selling_price", "expected_price")
def _check_selling_price_percentage(self):
for record in self:
if float_is_zero(record.selling_price, precision_rounding=0.01):
continue
if (
float_compare(
record.selling_price,
(record.expected_price * 0.9),
precision_rounding=0.01,
)
< 0
):
raise ValidationError(
"Selling Price of the property can not be less than 90 percent 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:
self.write(
{
"best_price": max(record.offer_ids.mapped("price"), default=0.0),
}
)
if record.best_price > 0.0:
record.state = "offer_received"

@api.onchange("garden")
def _set_garden_default_values(self):
if self.garden:
self.write({"garden_area": 10, "garden_orientation": "north"})
else:
self.write({"garden_area": 0, "garden_orientation": ""})

def action_property_sold(self):

Choose a reason for hiding this comment

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

Without any offer accepted should not to able to change status to sold.

if float_is_zero(self.selling_price, precision_rounding=0.01):
raise UserError(
"Atleast one offer must be accepted before selling the property"
)
self.state = "sold"

def action_property_cancelled(self):
self.state = "cancelled"
for offer in self.offer_ids:
if not offer.status:
offer.status = "refused"
79 changes: 79 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from datetime import timedelta
from odoo import api, fields, models
from odoo.exceptions import UserError


class EstateOfferModel(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer Model"
_order = "price desc"

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)
property_type_id = fields.Many2one(
"estate.property.type", related="property_id.property_type_id", required=True
)
validity = fields.Integer(
default=7,
help="offer validity period in days; the offer will be automatically refused when this expires.",
)
date_deadline = fields.Date(
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
default=fields.Date.today() + timedelta(days=7),
)

_sql_constraints = [
(
"check_property_offer_price",
"CHECK(price > 0)",
"Property Offer Price must be a valid value",
)
]

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

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

def action_offer_confirm(self):
if self.status in ["accepted", "refused"]:
raise UserError(f"Offer is already {self.status}")

# update the current selected offer
self.status = "accepted"
self.property_id.write(
{
"state": "offer_accepted",
"buyer": self.partner_id,
"selling_price": self.price,
}
)

# update the rest offers status to "refused"
refused_offers = self.property_id.offer_ids - self
refused_offers.write(
{
"status": "refused",
}
)

def action_offer_cancel(self):
for record in self:
if record.status in ["accepted", "refused"]:
raise UserError(f"Offer is already {record.status}")
record.status = "refused"
14 changes: 14 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import fields, models


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

name = fields.Char(required=True)
color = fields.Integer(string="Color", default=0)

_sql_constraints = [
("check_property_tag_name", "UNIQUE(name)", "Property Tag Name must be unique")
]
31 changes: 31 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from odoo import api, fields, models


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

name = fields.Char(required=True)
property_ids = fields.One2many("estate.property", "property_type_id")
sequence = fields.Integer(
"Sequence", default=1, help="Used to change the sequence of Property Types"
)
offer_ids = fields.One2many(
"estate.property.offer", inverse_name="property_type_id"
)
offer_count = fields.Integer(
default=0, readonly=True, compute="_compute_offers_by_type"
)

_sql_constraints = [
(
"check_property_type_name",
"UNIQUE(name)",
"Property Type Name must be unique",
)
]

@api.depends("offer_ids")
def _compute_offers_by_type(self):
self.offer_count = len(self.offer_ids)
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_user,model_estate_property,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type_user,model_estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag_user,model_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer_user,model_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
19 changes: 19 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>

<odoo>

<menuitem id="estate_menu_root" name="Real Estate">

<menuitem id="estate_advertisements_menu" name="Advertisements">
<menuitem id="estate_property_adv_menu_action" action="action_estate_property" name="Property" />
</menuitem>

<menuitem id="estate_settings_menu" name="Settings">
<menuitem id="estate_property_menu_action" action="action_estate_property" name="Property" />
<menuitem id="estate_property_type_menu_action" action="action_estate_property_type" name="Property Types" />
<menuitem id="estate_property_tag_menu_action" action="action_estate_property_tag" name="Property Tags" />
</menuitem>

</menuitem>

</odoo>
33 changes: 33 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>

<odoo>

<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</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create the first property Type
</p>
</field>
</record>

<record id="list_view_estate_property_offer" model="ir.ui.view">
<field name="name">Estate Properties Offer list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list editable="bottom" decoration-danger="status == 'refused'" decoration-success="status == 'accepted'">
<field name="price" string="Price" />
<field name="partner_id" string="Partner" />
<field name="validity" string="Validity" />
<field name="date_deadline" string="Deadline" />
<button name="action_offer_confirm" type="object" icon="fa-check" invisible="status == 'refused' or status == 'accepted'" />
<button name="action_offer_cancel" type="object" icon="fa-times" invisible="status in ['refused', 'accepted']" />
<field name="status" string="Status" readonly="True"/>
</list>
</field>
</record>

</odoo>
27 changes: 27 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>

<odoo>

<record id="action_estate_property_tag" model="ir.actions.act_window">
<field name="name">Property Tag</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create the first property Tag
</p>
</field>
</record>

<record id="list_estate_property_tag" model="ir.ui.view">
<field name="name">Property Tag List</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list editable="bottom">
<field name="name" string="Tag Name"/>
<field name="color" string="Color" options="{'color_field' : 'color'}"/>
</list>
</field>
</record>

</odoo>
Loading