-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[ADD] estate: real estate module #928
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
base: 18.0
Are you sure you want to change the base?
Changes from 6 commits
b378de7
c53de94
343fdf9
0e57fac
f9d70ab
6e7c75f
1a0c139
5bb7d7a
3804985
3341c41
609b834
aa85774
e32063a
0647ad3
78912a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Real Estate", | ||
"category": "Real Estate/Brokerage", | ||
"application": True, | ||
"installable": True, | ||
"depends": ["base"], | ||
"data": [ | ||
"security/estate_security.xml", | ||
"security/ir.model.access.csv", | ||
"views/estate_property_offers_views.xml", | ||
"views/estate_property_tag_views.xml", | ||
"views/estate_property_type_views.xml", | ||
"views/estate_property_views.xml", | ||
"views/estate_menus.xml", | ||
], | ||
"license": "LGPL-3", | ||
} |
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_offers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from odoo import api, fields, models, exceptions | ||
from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Estate Property" | ||
|
||
name = fields.Char(required=True) | ||
description = fields.Text() | ||
postcode = fields.Char() | ||
date_availaility = fields.Date( | ||
default=(fields.Date.add(fields.Date.today(), days=90)), copy=False | ||
) | ||
|
||
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() | ||
garden_orientation = fields.Selection( | ||
string="Type", | ||
selection=[ | ||
("North", "north"), | ||
("South", "south"), | ||
("East", "east"), | ||
("West", "west"), | ||
], | ||
help="Type is used to know the direction of the Garden ", | ||
) | ||
active = fields.Boolean(default=True) | ||
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 = fields.Many2one("estate.property.type", string="Property Type") | ||
salesman = fields.Many2one("res.users", default=lambda self: self.env.user) | ||
buyer = fields.Many2one("res.partner", readonly=True, copy=False) | ||
tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
offers_ids = fields.One2many("estate.property.offers", "property_id") | ||
total_area = fields.Integer(compute="_compute_area") | ||
best_price = fields.Float(compute="_compute_bestprice") | ||
|
||
_sql_constraints = [ | ||
( | ||
"check_positive_prices", | ||
"CHECK(expected_price > 0 AND selling_price > 0)", | ||
"Prices must be positive", | ||
) | ||
] | ||
|
||
# it's calculate the total area | ||
@api.depends("living_area", "garden_area") | ||
def _compute_area(self): | ||
for area in self: | ||
area.total_area = area.living_area + area.garden_area | ||
|
||
# it's taking the best offer from among all | ||
@api.depends("offers_ids.price") | ||
def _compute_bestprice(self): | ||
for record in self: | ||
record.best_price = max(record.offers_ids.mapped("price"), default=0) | ||
|
||
# change the values on the basis of the garden True or False | ||
@api.onchange("garden") | ||
def _onchnage_garden(self): | ||
if self.garden: | ||
self.garden_area = 10 | ||
self.garden_orientation = "North" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = "" | ||
|
||
def action_cancel(self): | ||
for record in self: | ||
if record.state != "sold": | ||
record.state = "cancelled" | ||
else: | ||
raise exceptions.UserError("A sold property cannot be cancelled") | ||
|
||
def action_sold(self): | ||
for record in self: | ||
if record.state != "cancelled": | ||
record.state = "sold" | ||
else: | ||
raise exceptions.UserError("A cancelled property cannot be set as sold") | ||
|
||
@api.constrains("expected_price", "selling_price") | ||
def _check_selling_price(self): | ||
for record in self: | ||
if not float_is_zero(record.selling_price, precision_digits=2): | ||
min_acceptable_price = record.expected_price * 0.9 | ||
if ( | ||
float_compare( | ||
record.selling_price, min_acceptable_price, precision_digits=2 | ||
) | ||
< 0 | ||
): | ||
raise exceptions.UserError( | ||
"Selling price must be at least 90% of the expected price." | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,61 @@ | ||||||
from odoo import fields, models, api, exceptions | ||||||
|
||||||
|
||||||
class EstatePropertyOffer(models.Model): | ||||||
_name = "estate.property.offers" | ||||||
_description = "Estate Property Offer" | ||||||
|
||||||
price = fields.Float() | ||||||
status = fields.Selection( | ||||||
[("Accepted", "accepted"), ("refused", "Refused")], copy=False | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
partner_id = fields.Many2one("res.partner", required=True) | ||||||
property_id = fields.Many2one("estate.property", required=True) | ||||||
validity = fields.Integer(default=7) | ||||||
date_deadline = fields.Date( | ||||||
compute="_compute_deadline", inverse="_inverse_deadline", store=True | ||||||
) | ||||||
|
||||||
_sql_constraints = [ | ||||||
("postive_price", "CHECK(price > 0)", "Prices must be positive") | ||||||
] | ||||||
|
||||||
# date_deadline | ||||||
@api.depends("create_date", "validity") | ||||||
def _compute_deadline(self): | ||||||
for record in self: | ||||||
if record.create_date: | ||||||
record.date_deadline = fields.Date.add( | ||||||
record.create_date, days=record.validity | ||||||
) | ||||||
# if user adding new data then their is no available of create_date then use today | ||||||
else: | ||||||
record.date_deadline = fields.Date.add( | ||||||
fields.Date.today(), days=record.validity | ||||||
) | ||||||
|
||||||
def _inverse_deadline(self): | ||||||
for record in self: | ||||||
if record.create_date: | ||||||
record.validity = ( | ||||||
record.date_deadline - record.create_date.date() | ||||||
).days | ||||||
else: | ||||||
record.validity = ( | ||||||
record.date_deadline - record.fields.Date.today() | ||||||
).days | ||||||
|
||||||
def action_accepted(self): | ||||||
for record in self: | ||||||
# selling price is default 0 and field is readonly then when the selling_price 0 so their is no offer is accepted yet | ||||||
if record.property_id.selling_price == 0: | ||||||
record.status = "Accepted" | ||||||
record.property_id.selling_price = record.price | ||||||
record.property_id.buyer = record.partner_id | ||||||
record.property_id.state = "offer_accepted" | ||||||
else: | ||||||
raise exceptions.UserError("Already One Offer is Accepted") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need of usererror, we can hide the accept and refuse buttons. |
||||||
|
||||||
def action_refused(self): | ||||||
for record in self: | ||||||
record.status = "refused" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not be able to refuse, once this offer is approved. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "Estate Property Tag" | ||
|
||
name = fields.Char(required=True) | ||
|
||
_sql_constraints = [("unique_tag", "UNIQUE(name)", "Tag name must be unique")] |
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 = "Property Type" | ||
|
||
name = fields.Char(required=True) | ||
|
||
_sql_constraints = [("unique_type", "UNIQUE(name)", "Type name must be unique")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="estate_group_user" model="res.groups"> | ||
<field name="name">Agent</field> | ||
<field name="category_id" ref="base.module_category_real_estate_brokerage" /> | ||
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" /> | ||
<field name="users" eval="[(4, ref('base.user_root'))]"/> | ||
</record> | ||
|
||
<record id="estate_group_manager" model="res.groups"> | ||
<field name="name">Manager</field> | ||
<field name="category_id" ref="base.module_category_real_estate_brokerage" /> | ||
<field name="implied_ids" eval="[(4, ref('estate_group_user'))]" /> | ||
<field name="users" eval="[(4, ref('base.user_admin'))]"/> | ||
<field name="comment">The user will be able to approve document created by employees.</field> | ||
</record> | ||
</odoo> |
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 | ||
access_estate_property_user,estate.property user,model_estate_property,estate.estate_group_user,1,0,0,0 | ||
access_estate_property_admin,estate.property admin,model_estate_property,estate.estate_group_manager,1,1,1,1 | ||
access_estate_property_type_admin,estate.property.type admin,model_estate_property_type,estate.estate_group_manager,1,1,1,1 | ||
access_estate_property_tag_admin,estate.property.tag admin,model_estate_property_tag,estate.estate_group_manager,1,1,1,1 | ||
access_estate_property_offers_admin,estate.property.offers admin,model_estate_property_offers,estate.estate_group_manager,1,1,1,1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<menuitem id="estate_menu_root" name="Real Estate"> | ||
<menuitem id="estate_first_level_menu" name="Advertisements"> | ||
<menuitem id="estate_property_menu_action" action="estate_property_action" /> | ||
</menuitem> | ||
|
||
<menuitem id="estate_setting" name="Setting"> | ||
<menuitem id="estate_setting_menu_action" action="estate_property_type_action" /> | ||
<menuitem id="estate_setting_tag_action" action="estate_property_tag_action" /> | ||
</menuitem> | ||
</menuitem> | ||
|
||
|
||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_offers_action" model="ir.actions.act_window"> | ||
<field name="name">Property Offers</field> | ||
<field name="res_model">estate.property.offers</field> | ||
<field name="view_mode">list,form</field> | ||
</record> | ||
|
||
<record id="estate_property_offers_list_view" model="ir.ui.view"> | ||
<field name="name">estate.property.offers.list</field> | ||
<field name="model">estate.property.offers</field> | ||
<field name="arch" type="xml"> | ||
<list> | ||
<field name="partner_id" /> | ||
<field name="price" /> | ||
<field name="validity" /> | ||
<field name="date_deadline" /> | ||
<button name="action_accepted" type="object" string="Accepted" icon="fa-check" /> | ||
<button name="action_refused" type="object" string="Refused" icon="fa-times" /> | ||
<field name="status" /> | ||
</list> | ||
</field> | ||
</record> | ||
|
||
<record id="estate_property_offers_form_view" model="ir.ui.view"> | ||
<field name="name">estate.property.offers.form</field> | ||
<field name="model">estate.property.offers</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<group> | ||
<field name="partner_id" /> | ||
<field name="price" /> | ||
<field name="validity" /> | ||
<field name="date_deadline" /> | ||
</group> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_tag_action" model="ir.actions.act_window"> | ||
<field name="name">Property Tag</field> | ||
<field name="res_model">estate.property.tag</field> | ||
<field name="view_mode">list,form</field> | ||
</record> | ||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_type_action" model="ir.actions.act_window"> | ||
<field name="name">Property Types</field> | ||
<field name="res_model">estate.property.type</field> | ||
<field name="view_mode">list,form</field> | ||
</record> | ||
</odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
state=cancelled
then we should hidesold
button.