-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] estate_property: added real estate module #840
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
ksoz-odoo
wants to merge
4
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-ksoz
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.
+629
−0
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d256e4c
[ADD] estate_property: initial creation of app and estate_property model
ksoz-odoo 9695307
[ADD] estate_property: security files and search, list, filter functi…
ksoz-odoo 3408e0b
[ADD] estate_property: offer model add, computed fields and relations
ksoz-odoo 64182b3
[ADD] estate_property: added sql constraints, specific views action …
ksoz-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 |
---|---|---|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
|
||
.vscode/ |
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,3 @@ | ||
{ | ||
"Odoo.selectedConfiguration": -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 @@ | ||
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,21 @@ | ||
{ | ||
'name': 'Estate', | ||
'version': '1.0', | ||
'license': 'LGPL-3', | ||
'summary': 'Real estate management module', | ||
'description': 'Manage properties, owners, and sales in your real estate agency', | ||
'category': 'Real Estate', | ||
'author': 'ksoz', | ||
'depends': ['base'], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/estate_property_offer_views.xml', | ||
'views/estate_property_types_views.xml', | ||
'views/estate_property_views.xml', | ||
'views/estate_property_tags_views.xml', | ||
"views/estate_res_users_views.xml", | ||
'views/estate_menus.xml', | ||
], | ||
'installable': True, | ||
'application': True, | ||
} |
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 @@ | ||
from . import estate_property | ||
from . import estate_property_type | ||
from . import estate_property_tags | ||
from . import estate_property_offer | ||
from . import estate_res_users |
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,119 @@ | ||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tools.float_utils import float_compare, float_is_zero | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Real Estate Property" | ||
_order = "id desc" | ||
|
||
name = fields.Char(required=True) | ||
description = fields.Text(string="Description") | ||
postcode = fields.Char(string="PostCode") | ||
date_availability = fields.Date( | ||
string="Available From", | ||
copy=False, | ||
default=lambda self: fields.Date.add(fields.Date.today(), months=3), | ||
) | ||
expected_price = fields.Float(required=True, string="Expected Price") | ||
selling_price = fields.Float(string="Selling Price") | ||
bedrooms = fields.Integer(string="Bedroom") | ||
living_area = fields.Integer(string="Living Area") | ||
facades = fields.Integer(string="Facades") | ||
garage = fields.Boolean(string="Garage") | ||
garden = fields.Boolean(string="Garden") | ||
garden_area = fields.Integer(string="Garden Area") | ||
garden_orientation = fields.Selection( | ||
[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")], | ||
string="Garden Orientation", | ||
) | ||
ksoz-odoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
active = fields.Boolean(default=True) | ||
state = fields.Selection( | ||
[ | ||
("new", "New"), | ||
("offer_received", "Offer Received"), | ||
("offer_accepted", "Offer Accepted"), | ||
("sold", "Sold"), | ||
("cancelled", "Cancelled"), | ||
], | ||
string="Status", | ||
copy=False, | ||
required=True, | ||
default="new", | ||
) | ||
property_type_id = fields.Many2one("estate.property.type", string="Property Type") | ||
seller_id = fields.Many2one( | ||
"res.users", string="Salesman", default=lambda self: self.env.user | ||
) | ||
buyer_id = fields.Many2one("res.partner", string="Buyer", copy=False) | ||
tag_ids = fields.Many2many("estate.property.tag", string="Tags") | ||
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
total_area = fields.Integer(compute="_compute_total_area") | ||
best_offer = fields.Float(compute="_compute_best_offer") | ||
|
||
_sql_constraints = [ | ||
( | ||
"expected_price", | ||
"CHECK(expected_price >= 0)", | ||
"The expected price must be strictly positive.", | ||
) | ||
] | ||
|
||
@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_offer(self): | ||
for record in self: | ||
if record.offer_ids: | ||
record.best_offer = max(record.offer_ids.mapped("price")) | ||
else: | ||
record.best_offer = 0.0 | ||
|
||
@api.onchange("garden") | ||
def _onchange_garden(self): | ||
if self.garden: | ||
self.garden_area = 10 | ||
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = False | ||
|
||
def action_on_sold(self): | ||
for record in self: | ||
if record.state == "cancelled": | ||
raise UserError("A cancelled property cannot be sold") | ||
record.state = "sold" | ||
return True | ||
|
||
def action_on_cancelled(self): | ||
for record in self: | ||
if record.state == "sold": | ||
raise UserError("A sold property cannot be cancelled.") | ||
record.state = "cancelled" | ||
return True | ||
|
||
@api.constrains("selling_price", "expected_price") | ||
def _check_selling_price(self): | ||
for record in self: | ||
if float_is_zero(record.selling_price, precision_digits=2): | ||
continue | ||
|
||
min_acceptable = record.expected_price * 0.9 | ||
|
||
if ( | ||
float_compare(record.selling_price, min_acceptable, precision_digits=2) | ||
< 0 | ||
): | ||
raise ValidationError( | ||
"Selling price must be at least 90% of the expected price." | ||
) | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def _check_before_delete(self): | ||
for record in self: | ||
if record.state not in ('new', 'cancelled'): | ||
raise UserError("You can only delete properties that are 'New' or 'Cancelled'.") |
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,78 @@ | ||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = "estate.property.offer" | ||
_description = "Offers for estate property" | ||
_order = "price desc" | ||
|
||
price = fields.Float() | ||
partner_id = fields.Many2one("res.partner", string="Partner", required=True) | ||
property_id = fields.Many2one("estate.property", string="Property", required=True) | ||
validity = fields.Integer(string="Validity (days)", default=7) | ||
date_deadline = fields.Date( | ||
string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline", | ||
) | ||
status = fields.Selection( | ||
selection=[("accepted", "Accepted"), ("refused", "Refused")], string="Status", copy=False, | ||
) | ||
property_type_id = fields.Many2one( | ||
'estate.property.type', related='property_id.property_type_id', string="Property Type", store=True | ||
) | ||
|
||
_sql_constraints = [ | ||
( | ||
"check_offer_price_positive", | ||
"CHECK(price > 0)", | ||
"Offer price must be strictly positive.", | ||
), | ||
] | ||
|
||
@api.depends("validity") | ||
def _compute_date_deadline(self): | ||
for record in self: | ||
start_date = record.create_date or fields.Date.context_today(record) | ||
record.date_deadline = fields.Date.add(start_date, days=record.validity) | ||
|
||
def _inverse_date_deadline(self): | ||
for record in self: | ||
start_date = record.create_date or fields.Date.context_today(record) | ||
if record.date_deadline: | ||
delta = record.date_deadline - start_date.date() | ||
record.validity = delta.days | ||
else: | ||
record.validity = 0 | ||
|
||
def action_on_accepted(self): | ||
for offer in self: | ||
accepted_offers = offer.property_id.offer_ids.filtered( | ||
lambda o: o.status == "accepted" | ||
) | ||
if accepted_offers: | ||
raise UserError("An offer has already been accepted for this property.") | ||
|
||
offer.status = "accepted" | ||
offer.property_id.selling_price = offer.price | ||
offer.property_id.buyer_id = offer.partner_id | ||
offer.property_id.state = "offer_accepted" | ||
return True | ||
|
||
def action_on_refused(self): | ||
for offer in self: | ||
offer.status = "refused" | ||
return True | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for vals in vals_list: | ||
prop = self.env['estate.property'].browse(vals.get('property_id')) | ||
|
||
if prop.offer_ids: | ||
max_prop = max(prop.offer_ids.mapped('price')) | ||
if vals['price'] < max_prop: | ||
raise UserError(f"The offer price must be higher than the current best offer of {max_prop}.") | ||
|
||
prop.state = 'offer_received' | ||
|
||
return super().create(vals_list) |
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 EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "Tags For Estate Properties" | ||
_order = "name" | ||
|
||
name = fields.Char(required=True, string="Tag") | ||
color = fields.Integer('Color') | ||
|
||
_sql_constraints = [ | ||
("unique_tag_name", "UNIQUE(name)", "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,25 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Types of Real Estate Properties" | ||
_order = "sequence,name" | ||
|
||
name = fields.Char(required=True, string="Property Type") | ||
property_ids = fields.One2many( | ||
"estate.property", "property_type_id", string="Properties" | ||
) | ||
sequence = fields.Integer("Sequence") | ||
offer_ids = fields.One2many( | ||
"estate.property.offer", "property_type_id", string="Offers" | ||
) | ||
offer_count = fields.Integer(string="Offers Count", compute="_compute_offer_count") | ||
|
||
_sql_constraints = [ | ||
("unique_type_name", "UNIQUE(name)", "Property type name must be unique."), | ||
] | ||
|
||
def _compute_offer_count(self): | ||
for record in self: | ||
record.offer_count = len(record.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,9 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = "res.users" | ||
|
||
property_ids = fields.One2many( | ||
'estate.property', 'seller_id', string="Properties", domain="[('state', 'in', ['new', 'offer_received'])]" | ||
) |
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,access_estate_property,model_estate_property,base.group_user,1,1,1,1 | ||
access_estate_property_type,estate.property.type,model_estate_property_type,base.group_user,1,1,1,1 | ||
access_estate_property_tag,estate.property.tag,model_estate_property_tag,base.group_user,1,1,1,1 | ||
access_estate_property_offer,estate.property.offer.user,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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<menuitem id="estate_menu_root" name="Real Estate" /> | ||
|
||
<menuitem id="estate_menu_first_level" name="Properties" parent="estate_menu_root" /> | ||
<menuitem id="estate_menu_property_action" action="action_estate_property" | ||
parent="estate_menu_first_level" /> | ||
|
||
<menuitem | ||
id="estate_menu_settings" | ||
name="Settings" | ||
parent="estate_menu_root"/> | ||
|
||
<menuitem | ||
id="estate_menu_property_type_action" | ||
name="Property Types" | ||
action="action_estate_property_type" | ||
parent="estate_menu_settings" /> | ||
|
||
<menuitem | ||
id="estate_menu_property_tag_action" | ||
name="Property Tags" | ||
action="action_estate_property_tag" | ||
parent="estate_menu_settings" | ||
/> | ||
</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,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_estate_property_offer_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="Offers" editable="bottom" decoration-danger="status == 'refused'" | ||
decoration-success="status == 'accepted'"> | ||
<field name="price" /> | ||
<field name="partner_id" /> | ||
<field name="status" /> | ||
<field name="date_deadline" /> | ||
<field name="validity" /> | ||
<button name="action_on_accepted" type="object" icon="fa-check" | ||
title="Accept Offer" invisible="status in ('accepted','refused')" /> | ||
<button name="action_on_refused" type="object" icon="fa-times" | ||
title="Refuse Offer" invisible="status in ('accepted','refused')" /> | ||
</list> | ||
</field> | ||
</record> | ||
|
||
<record id="view_estate_property_offer_form" model="ir.ui.view"> | ||
<field name="name">estate.property.offer.form</field> | ||
<field name="model">estate.property.offer</field> | ||
<field name="arch" type="xml"> | ||
<form string="Offer"> | ||
<sheet> | ||
<group> | ||
<field name="price" /> | ||
<field name="partner_id" /> | ||
<field name="status" /> | ||
<field name="validity" /> | ||
<field name="date_deadline" /> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_estate_property_offer" model="ir.actions.act_window"> | ||
<field name="name">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> | ||
</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.
Uh oh!
There was an error while loading. Please reload this page.