Skip to content

[ADD] estate: added real estate module #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: 18.0
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion awesome_gallery/models/ir_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class ActWindowView(models.Model):

view_mode = fields.Selection(selection_add=[
('gallery', "Awesome Gallery")
], ondelete={'gallery': 'cascade'})
], ondelete={'gallery': 'cascade'})
Comment on lines 8 to +10

Choose a reason for hiding this comment

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

why this change ?

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

Choose a reason for hiding this comment

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

Licensing is missing

11 changes: 11 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
'name': "Real Estate",
'summary': "This is real estate module",
'category': "Tutorials",
'description': "This is real estate module",
'author': "Dhruvrajsinh Zala (zadh)",
'installable': True,
'application': True,
'data': ['security/ir.model.access.csv', 'views/estate_property_views.xml', 'views/estate_property_offers.xml', 'views/estate_property_type_views.xml', 'views/estate_property_tags.xml', 'views/res_users_views.xml', 'views/estate_menus.xml'],

Choose a reason for hiding this comment

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

Indentation is not correct

'license': 'AGPL-3'
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import esatate_property_type
from . import estate_property_tags
from . import estate_property_offer
from . import inherited_res_users
30 changes: 30 additions & 0 deletions estate/models/esatate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odoo import models, fields, api


class EstatePropertyTyeps(models.Model):
_name = "estate.property.types"
_description = "Types of Estate Property"
_order = "sequence, name"

_sql_constraints = [
("_unique_type_name", "UNIQUE(name)", "Property type name must be unique.")
]

name = fields.Char(required=True)
property_ids = fields.One2many(
"estate.property", "property_type_id", string="Properties"
)
sequence = fields.Integer(default=1)

offer_ids = fields.One2many(
"estate.property.offer", "property_type_id", string="Offers"
)

offer_count = fields.Integer(
string="Offer Count", compute="_compute_offer_count", store=True
)

@api.depends("offer_ids")
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
131 changes: 131 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from dateutil.relativedelta import relativedelta
from odoo import models, fields, api, _
from odoo.tools.float_utils import float_compare, float_is_zero
from odoo.exceptions import UserError, ValidationError


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

_sql_constraints = [
(
"_check_expected_price",
"CHECK(expected_price > 0)",
"The expected price must be positive.",
),
(
"_check_selling_price",
"CHECK(selling_price >= 0)",
"The selling price must be positive.",
),
]

name = fields.Char(required=True, string="Title")
description = fields.Text()
postcode = fields.Char()
Comment on lines +26 to +27

Choose a reason for hiding this comment

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

Missing the string property

date_availability = fields.Date(
default=lambda self: fields.Date.today() + relativedelta(months=3),
copy=False,
string="Available From",
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
Comment on lines +33 to +35

Choose a reason for hiding this comment

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

Same missing the string property is missing in the field definition

living_area = fields.Integer(string="Living Area (sqm)")
total_area = fields.Float(compute="_compute_total_area", store=True)
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area (sqm)")
active = fields.Boolean(default=True)
garden_orientation = fields.Selection(
[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")],
string="Garden Orientation",
)
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
required=True,
copy=False,
default="new",
)
property_type_id = fields.Many2one("estate.property.types", 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.tags", string="Tags")

offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")

best_price = fields.Float(compute="_get_best_offer_price", store=True)

@api.ondelete(at_uninstall=False)
def _unlink_except_state_new_or_cancelled(self):
for record in self:
if record.state not in ["new", "cancelled"]:
raise UserError(
_("You can only delete properties in 'New' or 'Cancelled' state.")
)

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

@api.onchange("garden")
def _onchange_garden(self):
for record in self:
if record.garden:
record.garden_area = 10
record.garden_orientation = "north"
else:
record.garden_area = 0
record.garden_orientation = ""

def action_set_state_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError(_("Cancelled property cannot be sold."))
else:
record.state = "sold"
return True

def action_set_state_cancel(self):
for record in self:
if record.state == "sold":
raise UserError(_("Sold property cannot be cancelled."))
else:
record.state = "cancelled"
return True

@api.constrains("selling_price", "expected_price")
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=2):
if (
float_compare(
record.selling_price,
record.expected_price * 0.9,
precision_digits=2,
)
< 0
):
Comment on lines +119 to +126

Choose a reason for hiding this comment

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

Can be inlined

raise ValidationError(
_(
"The selling price cannot be lower than 90% of the expected price"
)
)
Comment on lines +127 to +131

Choose a reason for hiding this comment

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

can be inlined

93 changes: 93 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from odoo import fields, models, api, _
from odoo.exceptions import UserError
from datetime import timedelta, datetime


class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Offers of Estate Property"
_order = "price desc"
_sql_constraints = [
("_check_offer_price", "CHECK(price > 0)", "The Offer price must be positive.")
]

price = fields.Float()
status = fields.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)
property_type_id = fields.Many2one(
"estate.property.types",
related="property_id.property_type_id",
string="Property Type",
required=True,
)
validity = fields.Integer(default=7)
date_deadline = fields.Date(
compute="_compute_deadline", inverse="_inverse_deadline", store=True
)

@api.model_create_multi
def create(self, vals):
for val in vals:
property_id = val["property_id"]
offer_price = val["price"]
is_state_new = (
self.env["estate.property"].browse(property_id).state == "new"
)

result = self.read_group(
domain=[("property_id", "=", property_id)],
fields=["price:max"],
groupby=[],
)

max_price = result[0]["price"] if result else 0

if max_price >= offer_price:
raise UserError(
_(
"You cannot create an offer with a lower or equal amount than an existing offer for this property."
)
)
Comment on lines +49 to +53

Choose a reason for hiding this comment

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

Can be inlined


if is_state_new:
self.env["estate.property"].browse(property_id).state = "offer_received"

return super().create(vals)

@api.depends("validity")
def _compute_deadline(self):
for record in self:
create_date = record.create_date or datetime.now()
record.date_deadline = create_date + timedelta(days=record.validity)

def _inverse_deadline(self):
for record in self:
create_date = record.create_date or datetime.now()
if record.date_deadline:
delta = record.date_deadline - create_date.date()
record.validity = delta.days

def action_accept_offer(self):
for record in self:
existing = self.search(
[
("property_id", "=", record.property_id.id),
("status", "=", "accepted"),
]
)
if existing:
raise UserError(_("Another offer has been already accepted."))
record.status = "accepted"
record.property_id.state = "offer_accepted"
record.property_id.selling_price = record.price
record.property_id.buyer_id = record.partner_id.id

def action_refuse_offer(self):
for record in self:
if record.status == "accepted":
raise UserError(_("Accepted Offer cannot be Refused"))
else:
record.status = "refused"
14 changes: 14 additions & 0 deletions estate/models/estate_property_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import fields, models


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

_sql_constraints = [
("_unique_tag_name", "UNIQUE(name)", "Tag name must be unique.")
]

name = fields.Char(required=True)
color = fields.Integer(default=3)
12 changes: 12 additions & 0 deletions estate/models/inherited_res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models, fields


class InheritedResUsers(models.Model):
_inherit = "res.users"

property_ids = fields.One2many(
"estate.property",
"salesperson_id",
string="Available Properties",
domain=[("state", "in", ["new", "offer_received"])],
)
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
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
estate.access_estate_property_types,access_estate_property_types,estate.model_estate_property_types,base.group_user,1,1,1,1
estate.access_estate_property_tags,access_estate_property_tags,estate.model_estate_property_tags,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

Choose a reason for hiding this comment

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

End of file line is missing

13 changes: 13 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<odoo>
<menuitem id="menu_estate_root" name="Real Estate">

<menuitem id="menu_estate_properties" name="Advertisements">
<menuitem id="estate_property_menu_action" name="Properties" action="estate_property_action"/>
</menuitem>

<menuitem id="menu_estate_properties_settings" name="Settings">
<menuitem id="estate_property_types" name="Property Types" action="estate_property_type_action"/>
<menuitem id="estate_property_tags" name="Property Tags" action="estate_property_tags_action"/>
</menuitem>
</menuitem>
</odoo>

Choose a reason for hiding this comment

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

End of file is missing

27 changes: 27 additions & 0 deletions estate/views/estate_property_offers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>


<record id="estate_property_offers_list" model="ir.ui.view">
<field name="name">estate.property.offer.list</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list string="Property Tags">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_accept_offer" type="object" title="Accept" icon="fa-check" invisible="status in (
'accepted','refused')"/>
<button name="action_refuse_offer" type="object" title="Refuse" icon="fa-times" invisible="status in (
'accepted','refused')"/>
</list>
</field>
Comment on lines +15 to +24

Choose a reason for hiding this comment

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

Indentation is off

</record>

</odoo>

Choose a reason for hiding this comment

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

End of file line is missing

35 changes: 35 additions & 0 deletions estate/views/estate_property_tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<odoo>
<record id="estate_property_tags_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>




Comment on lines +6 to +10

Choose a reason for hiding this comment

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

Why this extra space is left here ?

<record id="view_estate_property_tags_list" model="ir.ui.view">
<field name="name">estate.property.tags.list</field>
<field name="model">estate.property.tags</field>
<field name="arch" type="xml">
<list string="Property Tags">
<field name="name"/>
</list >
</field>
</record>


<record id="estate_properties_tags_form" model="ir.ui.view">
<field name="name">estate.property.tags.form</field>
<field name="model">estate.property.tags</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Property Tags">
<group>
<field name="name"/>
</group>
</form>
</field>

</record>
</odoo>
Loading