-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[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
Open
tshe-odoo
wants to merge
7
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorials-tshe
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b378de7
[ADD] estate: define property model, security, actions, and menu
tshe-odoo c53de94
[ADD] estate: add list, form, and search views with filters and group by
tshe-odoo 343fdf9
[ADD] estate: property relations:-type, tags, offers, buyer, salesperson
tshe-odoo 0e57fac
[ADD] estate: add compute/inverse fields and onchange for property au…
tshe-odoo f9d70ab
[ADD] estate: add buttons and logic to manage property and offer stat…
tshe-odoo 6e7c75f
[IMP] estate: add validation rules to enforce price constraints and u…
tshe-odoo 1a0c139
[IMP] estate: improve property screens to guide users and reduce errors
tshe-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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" | ||
_order = "id desc" | ||
|
||
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", | ||
string="Status", | ||
) | ||
property_type_ids = 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." | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from odoo import fields, models, api, exceptions | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = "estate.property.offers" | ||
_description = "Estate Property Offer" | ||
_order = "price desc" | ||
_sql_constraints = [ | ||
("postive_price", "CHECK(price > 0)", "Prices must be positive") | ||
] | ||
|
||
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_ids", required=True | ||
) | ||
validity = fields.Integer(default=7) | ||
date_deadline = fields.Date( | ||
compute="_compute_deadline", inverse="_inverse_deadline", store=True | ||
) | ||
|
||
# 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" | ||
|
||
# if one offer is accepted then other offers are refused automatically | ||
|
||
other_record = self.env["estate.property.offers"].search( | ||
[ | ||
("property_id", "=", record.property_id.id), | ||
("id", "!=", record.id), | ||
] | ||
) | ||
other_record.write({"status": "refused"}) | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "Estate Property Tag" | ||
_order = "name" | ||
_sql_constraints = [("unique_tag", "UNIQUE(name)", "Tag name must be unique")] | ||
|
||
name = fields.Char(required=True) | ||
color = fields.Integer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from odoo import fields, models, api | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Property Type" | ||
_order = "sequence, name" | ||
_sql_constraints = [("unique_type", "UNIQUE(name)", "Type name must be unique")] | ||
|
||
name = fields.Char(required=True) | ||
property_ids = fields.One2many( | ||
"estate.property", "property_type_ids", string="Properties" | ||
) | ||
sequence = fields.Integer("Sequence", default=1) | ||
offers_ids = fields.One2many( | ||
"estate.property.offers", "property_type_id", string="Offers" | ||
) | ||
offer_count = fields.Integer(compute="_compute_offers_count") | ||
|
||
@api.depends("offers_ids") | ||
def _compute_offers_count(self): | ||
for record in self: | ||
record.offer_count = len(record.offers_ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<field name="domain">[('property_type_id','=',active_id)]</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 editable="bottom" decoration-danger="status=='refused'" decoration-success="status=='Accepted'"> | ||
<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" invisible="status in ['Accepted','refused']"/> | ||
<button name="action_refused" type="object" string="Refused" icon="fa-times" invisible="status in ['Accepted','refused']"/> | ||
</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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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> | ||
|
||
<record id="estate_property_tag_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 editable="bottom"> | ||
<field name="name" /> | ||
</list> | ||
</field> | ||
</record> | ||
</odoo> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.