-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[ADD] estate : Real Estate Advertisement App #927
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
satp-odoo
wants to merge
11
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-tutorials-satp
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
11 commits
Select commit
Hold shift + click to select a range
6b97ae5
[ADD] estate: created estate advertisement module
satp-odoo 42f72a9
[ADD] estate: defined estate property model
satp-odoo ae10966
[ADD] estate: added security access configuration
satp-odoo 25213fe
[ADD] estate: added menus options and new fields
satp-odoo 8afd388
[ADD] estate: customized form and list view and added filtering options
satp-odoo dec6f49
[ADD] estate: added relational models and property types, tags, buyer…
satp-odoo 830bfc6
[ADD] estate: added auto computed fields to property and offer views
satp-odoo d02d21f
[ADD] estate: added Cancel and Sold buttons to property, Accept/Refus…
satp-odoo 5782473
[ADD] estate : add data constraints from prices and uniqueness
satp-odoo 1d2d753
[IMP] estate : add statusbar, helper text and refined sold constrains
satp-odoo 9b50772
[IMP] estate: UI Enhancements, Ordering, Filters, and Constraints
satp-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,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", | ||
} |
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_offer |
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,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( | ||
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): | ||
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. 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" |
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,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" |
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,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") | ||
] |
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,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) |
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,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 |
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,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> |
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,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> |
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,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> |
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.
state field should display in the header of the form view.
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.
Can you please make these changes?