-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Implementation of the Odoo Estate module as outlined in the official tutorial #847
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
kums-odoo
wants to merge
10
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-kums
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.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18a45be
[ADD] estate: initial module for real estate properties
kums-odoo 63b8f9c
[ADD] estate: initial module with security and basic views
kums-odoo 7e42acb
[IMP] estate: Add new features relations, computed fields, and actions
kums-odoo 5eb85ca
[IMP] estate: add data constraints and UI Changes
kums-odoo 7e5c59e
[IMP] estate: add inheritance and module interaction features
kums-odoo 65537da
[FIX] estate: code style fixes
kums-odoo 4cd0123
[IMP] estate: interact with external modules and code cleanup
kums-odoo 532c013
[IMP] estate: add module data and restrict data access
kums-odoo db8e46e
[IMP] estate, estate_account: implement and extend PDF property reports
kums-odoo fcaef25
[ADD] estate: add unit tests for property business logic
kums-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,24 @@ | ||
{ | ||
"name": "Real Estate", | ||
"category": "Real Estate/Brokerage", | ||
"application": True, | ||
"installable": True, | ||
"data": [ | ||
"security/security.xml", | ||
"security/ir.model.access.csv", | ||
"data/property_type.xml", | ||
"views/estate_property_views.xml", | ||
"views/estate_property_tag_views.xml", | ||
"views/estate_property_offer_views.xml", | ||
"views/estate_property_type_views.xml", | ||
"views/estate_menus.xml", | ||
"views/inherit_res_users_view.xml", | ||
"report/estate_property_templates.xml", | ||
"report/estate_property_reports.xml" | ||
], | ||
"demo": [ | ||
"demo/property.xml", | ||
"demo/property_offer.xml", | ||
], | ||
"license": "AGPL-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,22 @@ | ||
|
||
<odoo> | ||
<data noupdate="0"> | ||
|
||
<record id="property_type_residential" model="estate.property.type"> | ||
<field name="name">Residential</field> | ||
</record> | ||
|
||
<record id="property_type_commercial" model="estate.property.type"> | ||
<field name="name">Commercial</field> | ||
</record> | ||
|
||
<record id="property_type_industrial" model="estate.property.type"> | ||
<field name="name">Industrial</field> | ||
</record> | ||
|
||
<record id="property_type_land" model="estate.property.type"> | ||
<field name="name">Land</field> | ||
</record> | ||
|
||
</data> | ||
</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,66 @@ | ||
|
||
<odoo> | ||
<record id="property_id1" model="estate.property"> | ||
<field name="name">Big Villa</field> | ||
<field name="state">new</field> | ||
<field name="description">A nice and big villa</field> | ||
<field name="postcode">12345</field> | ||
<field name="date_availability">2020-02-02</field> | ||
<field name="expected_price">1600000</field> | ||
<field name="bedrooms">6</field> | ||
<field name="living_area">100</field> | ||
<field name="facades">4</field> | ||
<field name="garage">True</field> | ||
<field name="garden">True</field> | ||
<field name="garden_area">100000</field> | ||
<field name="garden_orientation">south</field> | ||
</record> | ||
|
||
<record id="property_id2" model="estate.property"> | ||
<field name="name">Trailer home</field> | ||
<field name="state">cancelled</field> | ||
<field name="description">Home in a trailer park</field> | ||
<field name="postcode">54321</field> | ||
<field name="date_availability">1970-01-01</field> | ||
<field name="expected_price">100000</field> | ||
<field name="selling_price">120000</field> | ||
<field name="bedrooms">1</field> | ||
<field name="living_area">10</field> | ||
<field name="facades">4</field> | ||
<field name="garage">False</field> | ||
</record> | ||
|
||
<record id="property_id3" model="estate.property"> | ||
<field name="name">Small home</field> | ||
<field name="state">new</field> | ||
<field name="description">Home in a trailer park</field> | ||
<field name="postcode">54321</field> | ||
<field name="date_availability">1970-01-01</field> | ||
<field name="expected_price">100000</field> | ||
<field name="selling_price">120000</field> | ||
<field name="bedrooms">1</field> | ||
<field name="living_area">10</field> | ||
<field name="facades">4</field> | ||
<field name="garage">False</field> | ||
<field name="offer_ids" eval="[ | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_12'), | ||
'price': 1200000, | ||
'validity': 14, | ||
'date_deadline': (datetime.now() + timedelta(days=14)).date(), | ||
}), | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_12'), | ||
'price': 1300000, | ||
'validity': 14, | ||
'date_deadline': (datetime.now() + timedelta(days=14)).date(), | ||
}), | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_10'), | ||
'price': 1500000, | ||
'validity': 14, | ||
'date_deadline': (datetime.now() + timedelta(days=14)).date(), | ||
}) | ||
]"/> | ||
</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,39 @@ | ||
<odoo> | ||
<record id="offer_azure_villa_1" model="estate.property.offer"> | ||
<field name="price">10000</field> | ||
<field name="validity">14</field> | ||
<field name="partner_id" ref="base.res_partner_12"/> | ||
<field name="property_id" ref="property_id1"/> | ||
<field name="date_deadline" eval="datetime.now().date() + timedelta(days=14)"/> | ||
</record> | ||
|
||
<record id="offer_azure_villa_2" model="estate.property.offer"> | ||
<field name="price">1500000</field> | ||
<field name="validity">14</field> | ||
<field name="partner_id" ref="base.res_partner_12"/> | ||
<field name="property_id" ref="property_id1"/> | ||
<field name="date_deadline" eval="datetime.now().date() + timedelta(days=14)"/> | ||
</record> | ||
|
||
<record id="offer_azure_villa_3" model="estate.property.offer"> | ||
<field name="price">1500001</field> | ||
<field name="validity">14</field> | ||
<field name="partner_id" ref="base.res_partner_12"/> | ||
<field name="property_id" ref="property_id1"/> | ||
<field name="date_deadline" eval="datetime.now().date() + timedelta(days=14)"/> | ||
</record> | ||
|
||
<function model="estate.property.offer" name="action_offer_confirm"> | ||
<value eval="[ref('offer_azure_villa_2')]"/> | ||
</function> | ||
|
||
<function model="estate.property.offer" name="action_offer_refuse"> | ||
<value eval="[ref('offer_azure_villa_1')]"/> | ||
</function> | ||
|
||
<function model="estate.property.offer" name="action_offer_refuse"> | ||
<value eval="[ ref('offer_azure_villa_3')]"/> | ||
</function> | ||
</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,5 @@ | ||
from . import estate_property | ||
from . import estate_property_type | ||
from . import estate_property_tag | ||
from . import estate_property_offer | ||
from . import inherited_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,183 @@ | ||
from odoo import fields, models, api | ||
from odoo.exceptions import UserError, ValidationError | ||
from dateutil.relativedelta import relativedelta | ||
from datetime import date | ||
from odoo.tools.float_utils import float_compare | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Estate Model" | ||
|
||
name = fields.Char(string="Name") | ||
description = fields.Text(string="Description") | ||
postcode = fields.Text(string="Postcode") | ||
date_availability = fields.Date( | ||
string="Date Availability", | ||
copy=False, | ||
default=lambda self: date.today() + relativedelta(months=3), | ||
) | ||
expected_price = fields.Float(string="Expected Price") | ||
selling_price = fields.Integer(string="Selling Price") | ||
bedrooms = fields.Integer(string="Bedrooms") | ||
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( | ||
string="Type", | ||
selection=[ | ||
("north", "North"), | ||
("south", "South"), | ||
("east", "East"), | ||
("west", "West"), | ||
], | ||
) | ||
|
||
active = fields.Boolean(default=True, string="Active") | ||
|
||
state = fields.Selection( | ||
selection=[ | ||
("new", "New"), | ||
("offer_received", "Offer Received "), | ||
("offer_accepted", "Offer Accepted"), | ||
("sold", "Sold"), | ||
("cancelled", "Cancelled"), | ||
], | ||
string="State", | ||
default="new", | ||
copy=False, | ||
) | ||
|
||
# property will have Many to one relation with property type since many properties can belong to one property type | ||
|
||
property_type_id = fields.Many2one("estate.property.type", "Property Type") | ||
|
||
user_id = fields.Many2one( | ||
"res.users", | ||
string="Salesperson", | ||
copy=False, | ||
) | ||
|
||
partner_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_property_area", string="Total Area" | ||
) | ||
|
||
best_price = fields.Integer(compute="_compute_best_price", string="Best Price") | ||
|
||
status = fields.Char(default="new", string="Status") | ||
|
||
company_id = fields.Many2one( | ||
"res.company", | ||
string="Company", | ||
default=lambda self: self.env.company, | ||
required=True, | ||
) | ||
|
||
_order = "id desc" | ||
|
||
_sql_constraints = [ | ||
( | ||
"check_expected_price", | ||
"CHECK(expected_price > 0)", | ||
"Expected price must be strictly positive", | ||
), | ||
( | ||
"check_selling_price", | ||
"CHECK(selling_price >= 0)", | ||
"Selling price should be positive", | ||
), | ||
] | ||
|
||
@api.depends("garden_area", "living_area") | ||
def _compute_total_property_area(self): | ||
for area in self: | ||
area.total_area = area.garden_area + area.living_area | ||
|
||
@api.depends("offer_ids.price") | ||
def _compute_best_price(self): | ||
for record in self: | ||
offers_list = record.mapped("offer_ids.price") | ||
if offers_list: | ||
record.best_price = max(offers_list) | ||
else: | ||
record.best_price = 0 | ||
|
||
# on change of garden status , update gardern area and its orientation | ||
|
||
@api.onchange("garden") | ||
def _onchange_garden_status(self): | ||
if self.garden: | ||
self.garden_area = 10 | ||
self.garden_orientation = "north" | ||
return | ||
self.garden_area = 0 | ||
self.garden_orientation = "" | ||
|
||
# acts when property is sold | ||
# In case property is cancelled it cannot be sold | ||
def action_sell_property(self): | ||
# dictionary for the property status | ||
property_sell_status_dict = {"new": True, "sold": True, "cancelled": False} | ||
for record in self: | ||
if self.state != "offer_accepted": | ||
raise UserError("Property has no offer yet!!!") | ||
if property_sell_status_dict[record.status]: | ||
record.status = "sold" | ||
record.state = "sold" | ||
else: | ||
raise UserError("Cancelled property cannot be sold.") | ||
|
||
# action in case of cancel property button | ||
# If property is sold than Cannot be cancelled | ||
|
||
def action_cancel_property_selling(self): | ||
property_cancel_status_dict = { | ||
"new": True, | ||
"cancelled": True, | ||
"sold": False, | ||
} | ||
for record in self: | ||
if property_cancel_status_dict[record.status]: | ||
record.status = "cancelled" | ||
else: | ||
raise UserError("Sold property cannot be cancelled.") | ||
|
||
# constrains for the selling price | ||
|
||
@api.constrains("selling_price", "expected_price") | ||
def _check_selling_price(self): | ||
for data in self: | ||
# if call will come after selling price change than it will allow updated price to work | ||
if data.selling_price <= 0: | ||
return | ||
|
||
price_float_ratio = data.selling_price / data.expected_price | ||
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2) | ||
if ratio_diffrence == -1: | ||
data.selling_price = 0 | ||
raise ValidationError( | ||
"The selling price cannot be lower than 90% of the expected price" | ||
) | ||
|
||
# delete opration for the process | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def _unlink_if_state_new_or_cancelled(self): | ||
for data in self: | ||
if not bool(data.state == "new" or data.state == "cancelled"): | ||
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. and you changed it in the last commit better to do it in the original commit. |
||
raise UserError( | ||
"Can't delete property which is not in new or cancelled state!" | ||
) |
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.