-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] estate: Added Estate module #842
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
arkp-odoo
wants to merge
10
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-training-arkp
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.
+719
−0
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82eb32a
[ADD] estate module/app added (chapter-2 done)
arkp-odoo db9d006
[ADD] estate: added security and enhanced UI
arkp-odoo 7695fbf
[ADD] estate: SQL constraints , compute and inverse , till ch-10 comp…
arkp-odoo cba5ac2
[ADD] estate: improvements in estate module also smart button added
arkp-odoo 52bfc84
[ADD] estate_account : New module created , generating invoice on pro…
arkp-odoo 4039991
[FIX] estate: intendation,whitespaces fixed
arkp-odoo eb71a5c
[FIX] estate: Fixed warnings
arkp-odoo c4659cf
[FIX] estate: Reviewed and aligned code with Odoo coding guidelines
arkp-odoo 81b8570
[FIX] estate: resolved EOF and extra space
arkp-odoo e8c6822
[FIX] estate: resolved errors and warnings of demo data
arkp-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,2 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
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,22 @@ | ||
{ | ||
'name': 'Estate', | ||
'version': '1.0', | ||
"category": "Real Estate/Brokerage", | ||
'data': [ | ||
'security/security.xml', | ||
'security/ir.model.access.csv', | ||
'views/estate_property_views.xml', | ||
'views/estate_property_type_views.xml', | ||
'views/estate_property_tag_views.xml', | ||
'views/inherited_model_view.xml', | ||
'views/estate_menu.xml', | ||
'data/estate_property_type.xml', | ||
], | ||
'demo': [ | ||
'demo/estate_property_demo.xml', | ||
'demo/estate_property_offer.xml', | ||
], | ||
'installable': True, | ||
'application': True, | ||
'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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_type_residential" model="estate.property.type"> | ||
<field name="name">Residential</field> | ||
</record> | ||
|
||
<record id="estate_property_type_commercial" model="estate.property.type"> | ||
<field name="name">Commercial</field> | ||
</record> | ||
|
||
<record id="estate_property_type_industrial" model="estate.property.type"> | ||
<field name="name">Industrial</field> | ||
</record> | ||
|
||
<record id="estate_property_type_land" model="estate.property.type"> | ||
<field name="name">Land</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,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="estate_property_demo_1" 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_avaiblity">2020-02-02</field> | ||
<field name="expected_price">1600000.00</field> | ||
<field name="bedrooms">6</field> | ||
<field name="living_area">100</field> | ||
<field name="facades">4</field> | ||
<field name="garage">1</field> | ||
<field name="garden">1</field> | ||
<field name="garden_area">100000</field> | ||
<field name="garden_orientation">south</field> | ||
<field name="property_type_id">1</field> | ||
</record> | ||
<record id="estate_property_demo_2" model="estate.property"> | ||
<field name="name">Trailer Home</field> | ||
<field name="state">cancelled</field> | ||
<field name="description">Home in trailer park.</field> | ||
<field name="postcode">54321</field> | ||
<field name="date_avaiblity">1970-01-01</field> | ||
<field name="expected_price">100000.00</field> | ||
<field name="bedrooms">1</field> | ||
<field name="living_area">10</field> | ||
<field name="facades">4</field> | ||
<field name="garage">0</field> | ||
<field name="offer_ids" | ||
eval="[ | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_2'), | ||
'price': 15900028999, | ||
'validity': 14, | ||
}), | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_2'), | ||
'price': 15900039999, | ||
'validity': 14, | ||
}), | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_3'), | ||
'price': 150009009999, | ||
'validity': 11, | ||
}), | ||
]" /> | ||
</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,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_offer_1" model="estate.property.offer"> | ||
<field name="price">9100000099</field> | ||
<field name="validity">14</field> | ||
<field name="property_id" ref="estate_property_demo_1" /> | ||
<field name="partner_id" ref="base.res_partner_12" /> | ||
</record> | ||
<record id="estate_property_offer_2" model="estate.property.offer"> | ||
<field name="price">9150000099</field> | ||
<field name="validity">14</field> | ||
<field name="property_id" ref="estate_property_demo_1" /> | ||
<field name="partner_id" ref="base.res_partner_12" /> | ||
</record> | ||
<record id="estate_property_offer_3" model="estate.property.offer"> | ||
<field name="price">91500000199</field> | ||
<field name="validity">11</field> | ||
<field name="property_id" ref="estate_property_demo_1" /> | ||
<field name="partner_id" ref="base.res_partner_2" /> | ||
</record> | ||
|
||
<function model="estate.property.offer" name="refuse_icon_action"> | ||
<value eval="[ref('estate_property_offer_1')]" /> | ||
</function> | ||
<function model="estate.property.offer" name="refuse_icon_action"> | ||
<value eval="[ref('estate_property_offer_2')]" /> | ||
</function> | ||
<function model="estate.property.offer" name="refuse_icon_action"> | ||
<value eval="[ref('estate_property_offer_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,6 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
from . import estate_property | ||
from . import estate_property_type | ||
from . import estate_property_tag | ||
from . import estate_property_offer | ||
from . import 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,95 @@ | ||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError | ||
from datetime import date | ||
from dateutil.relativedelta import relativedelta | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property" | ||
_description = "Estate Property is defined" | ||
_order = "id desc" | ||
_sql_constraints = [ | ||
('selling_price_positive', 'CHECK(selling_price>=0)', 'The selling price should be positive.'), | ||
('expected_price_positive', 'CHECK(expected_price>=0)', 'The expected price should be positive.') | ||
] | ||
|
||
name = fields.Char(required=True) | ||
description = fields.Text() | ||
postcode = fields.Char() | ||
date_avaiblity = fields.Date(copy=False, default=date.today() + relativedelta(months=3)) | ||
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() | ||
active = fields.Boolean(default=True) | ||
salesman_id = fields.Many2one("res.users", index=True, string="salesman", default=lambda self: self.env.user) | ||
buyer_id = fields.Many2one("res.partner", string="buyer", index=True, default=lambda self: self.env.user.partner_id.id) | ||
property_type_id = fields.Many2one("estate.property.type", string="property type") | ||
property_tag_ids = fields.Many2many("estate.property.tag", string="tags") | ||
offer_ids = fields.One2many("estate.property.offer", "property_id", string="offers") | ||
total_area = fields.Float(compute="_compute_total") | ||
best_offer = fields.Float(compute="_find_best") | ||
company_id = fields.Many2one("res.company", required=True, default=lambda self: self.env.company) | ||
|
||
@api.depends("garden_area", "living_area") | ||
def _compute_total(self): | ||
for record in self: | ||
record.total_area = record.garden_area + record.living_area | ||
|
||
@api.depends("offer_ids.price") | ||
def _find_best(self): | ||
for record in self: | ||
if record.offer_ids: | ||
record.best_offer = max(record.offer_ids.mapped('price')) | ||
else: | ||
record.best_offer = 0.0 | ||
|
||
garden_orientation = fields.Selection( | ||
string='Direction', | ||
selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], | ||
help="Orientation is used to locate garden's direction" | ||
) | ||
|
||
state = fields.Selection( | ||
selection=[('new', 'new'), ('Offer Received', 'Offer Received'), ('Offer Accepted', 'Offer Accepted'), ('sold', 'sold'), ('cancelled', 'Cancelled')], | ||
required=True, | ||
default='new', | ||
copy=False, | ||
) | ||
|
||
status = fields.Selection( | ||
selection=[ | ||
('new', 'New'), | ||
('sold', 'Sold'), | ||
('cancelled', 'Cancelled') | ||
], | ||
default='new', | ||
copy=False | ||
) | ||
|
||
Comment on lines
+63
to
+73
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. Same here as above. |
||
@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 sold_button_action(self): | ||
for record in self: | ||
if record.status == 'cancelled': | ||
raise UserError("Cancelled property cannot be marked as sold.") | ||
record.status = 'sold' | ||
record.state = 'sold' | ||
|
||
def cancel_button_action(self): | ||
for record in self: | ||
if record.status == 'sold': | ||
raise UserError("Sold property cannot be cancelled.") | ||
record.status = 'cancelled' | ||
record.state = '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,86 @@ | ||
from datetime import timedelta | ||
from odoo import api, fields, models | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tools.float_utils import float_compare | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = "estate.property.offer" | ||
_description = "estate property OFFER created" | ||
_order = "price desc" | ||
_sql_constraints = [ | ||
('offer_price_positive', 'CHECK(price>=0)', 'The offer price should be positive.') | ||
] | ||
|
||
price = fields.Float() | ||
status = fields.Selection( | ||
selection=[('accepted', 'Accepted'), ('refused', 'Refused')], | ||
copy=False, | ||
) | ||
partner_id = fields.Many2one("res.partner", string="Partner", index=True, required=True, default=lambda self: self.env.user.partner_id.id) | ||
property_id = fields.Many2one("estate.property", index=True, required=True) | ||
property_type_id = fields.Many2one('estate.property.type', string="property type", related="property_id.property_type_id", store=True) | ||
validity = fields.Integer(default=7) | ||
date_deadline = fields.Date( | ||
string="Deadline", | ||
compute="_compute_date_deadline", | ||
inverse="_inverse_date_deadline", | ||
store=True | ||
) | ||
|
||
@api.depends('create_date', 'validity') | ||
def _compute_date_deadline(self): | ||
for record in self: | ||
if record.create_date: | ||
create_date = record.create_date.date() | ||
else: | ||
create_date = fields.Date.today() | ||
record.date_deadline = create_date + timedelta(days=record.validity) | ||
|
||
def _inverse_date_deadline(self): | ||
for record in self: | ||
if record.create_date: | ||
create_date = record.create_date.date() | ||
else: | ||
create_date = fields.Date.today() | ||
if record.date_deadline: | ||
record.validity = (record.date_deadline - create_date).days | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for vals in vals_list: | ||
property_id = vals.get("property_id") | ||
price = vals.get("price", 0.0) | ||
if property_id: | ||
property_obj = self.env["estate.property"].browse(property_id) | ||
best_price = property_obj.best_offer or 0.0 | ||
if price < best_price: | ||
raise UserError( | ||
"Offer price must be greater than or equal to the best offer price.") | ||
records = super().create(vals_list) | ||
for record in records: | ||
if record.partner_id: | ||
record.property_id.state = "Offer Received" | ||
return records | ||
|
||
def refuse_icon_action(self): | ||
for record in self: | ||
record.status = 'refused' | ||
|
||
def accept_icon_action(self): | ||
for record in self: | ||
if any( | ||
offer.status == 'accepted' | ||
for offer in record.property_id.offer_ids | ||
): | ||
raise UserError("Only one offer can be accepted per property.") | ||
min_price = record.property_id.expected_price * 0.9 | ||
if float_compare(record.price, min_price, precision_digits=2) < 0: | ||
raise ValidationError("Offer must be at least 90% of the expected price to be accepted.") | ||
|
||
record.status = 'accepted' | ||
record.property_id.state = 'Offer Accepted' | ||
other_offers = record.property_id.offer_ids - record | ||
other_offers.write({'status': 'refused'}) | ||
record.property_id.selling_price = record.price | ||
record.property_id.buyer_id = record.partner_id |
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,13 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "estate property TAG created" | ||
_order = "name asc" | ||
_sql_constraints = [ | ||
('tag_name_unique', 'unique(name)', 'Tag name should 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,21 @@ | ||
from odoo import fields, models, api | ||
|
||
|
||
class EstatePropertyType(models.Model): | ||
_name = "estate.property.type" | ||
_description = "Estate Property type is defined" | ||
_order = "name asc" | ||
_sql_constraints = [ | ||
('property_type_unique', 'unique(name)', 'property type should be unique') | ||
] | ||
|
||
name = fields.Char(required=True) | ||
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") | ||
property_ids = fields.One2many('estate.property', 'property_type_id') | ||
offer_ids = fields.One2many('estate.property.offer', 'property_type_id', string='offers') | ||
offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count") | ||
|
||
@api.depends('property_ids.offer_ids') | ||
def _compute_offer_count(self): | ||
for record in self: | ||
record.offer_count = sum(len(property.offer_ids) for property in record.property_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,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = 'res.users' | ||
|
||
property_ids = fields.One2many('estate.property', 'salesman_id', domain=[('state', 'not in', ['sold', '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,10 @@ | ||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
access_property_manager,access_estate_property_manager,model_estate_property,estate_group_manager,1,1,1,0 | ||
access_property_type_manager,access_estate_property_type_manager,model_estate_property_type,estate_group_manager,1,1,1,1 | ||
access_property_tag_manager,access_estate_property_tag_manager,model_estate_property_tag,estate_group_manager,1,1,1,1 | ||
access_property_offer_manager,access_estate_property_offer_manager,model_estate_property_offer,estate_group_manager,1,1,1,1 | ||
access_res_users_manager,access_res_users_manager,model_res_users,estate_group_manager,1,1,1,1 | ||
access_property_agent,access_estate_property_agent,model_estate_property,estate_group_user,1,1,1,0 | ||
access_property_offer_agent,access_estate_property_offer_agent,model_estate_property_offer,estate_group_user,1,1,1,0 | ||
access_property_type_agent,access_estate_property_type_agent,model_estate_property_type,estate_group_user,1,0,0,0 | ||
access_property_tag_agent,access_estate_property_tag_agent,model_estate_property_tag,estate_group_user,1,0,0,0 |
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> | ||
<record id="estate_group_user" model="res.groups"> | ||
<field name="name">Agent</field> | ||
<field name="comment">Real estate agents can manage the properties under their care, or properties which are not specifically under the care of any agent.</field> | ||
<field name="category_id" ref="base.module_category_real_estate_brokerage"/> | ||
</record> | ||
|
||
<record id="estate_group_manager" model="res.groups"> | ||
<field name="name">Manager</field> | ||
<field name="comment">Real estate managers can configure the system (manage available types and tags) as well as oversee every property in the pipeline.</field> | ||
<field name="category_id" ref="base.module_category_real_estate_brokerage"/> | ||
<field name="implied_ids" eval="[(4, ref('estate_group_user'))]"/> | ||
</record> | ||
|
||
<record id="company_rule_id" model="ir.rule"> | ||
<field name="name">company: see or modify properties of my company only</field> | ||
<field name="model_id" ref="model_estate_property" /> | ||
<field name="perm_read" eval="True" /> | ||
<field name="perm_write" eval="True" /> | ||
<field name="perm_create" eval="True" /> | ||
<field name="perm_unlink" eval="False" /> | ||
<field name="groups" eval="[Command.link(ref('estate_group_user'))]" /> | ||
<field name="domain_force">[('company_id', '=', user.company_id.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.
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.
copyright info is missing
Refer this https://github.com/odoo/odoo/blob/cc5d7f3e068ca37488b0d716efacf36727401704/addons/account/__init__.py#L2
Apples through the diff