-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] estate: Manage Your Properties, Maximize Your Returns
-create new estate model -create offer for a property and relation between properties like one2Many , many2Many, many2One -create computed fields -create action fields and action buttons for sold & cancle and offer accept & refused -create views for property, type, tag and offer -create security for all the the above model
- Loading branch information
aneg-odoo
committed
Sep 24, 2024
1 parent
5308379
commit ea4b032
Showing
22 changed files
with
692 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
from . import models | ||
from . import demo |
This file contains 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 @@ | ||
{ | ||
"name": "Real_Estate", | ||
"depends": ["base"], | ||
"Description": "Estate Module by aneg", | ||
"category": "Real Estate", | ||
"license": "LGPL-3", | ||
"summary": "Real_Estate module for different purpose", | ||
"author": "aneg_odoo", | ||
"version": "0.1", | ||
"application": True, | ||
"installable": True, | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/estate_property_offer.xml", | ||
"views/estate_property_views.xml", | ||
"views/estate_property_type.xml", | ||
"views/estate_property_tag.xml", | ||
"views/estate_menus.xml", | ||
"views/res_users_view.xml", | ||
"data/estate.property.type.csv", | ||
], | ||
"demo": [ | ||
"demo/estate_demo.xml", | ||
"demo/estate_offer_demo.xml", | ||
], | ||
} |
This file contains 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 | ||
id4,Residential | ||
id1,Commercial | ||
id2,Industrial | ||
id3,Land |
This file contains 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,59 @@ | ||
<odoo> | ||
|
||
<record id="estate_demo_data3" model="estate.property"> | ||
<field name="property_type" ref="id4" /> | ||
<field name="name">Big Villa</field> | ||
<field name="status">new</field> | ||
<field name="myestate_model">A nice and big villa</field> | ||
<field name="postcode">12345</field> | ||
<field name="date_availability">2020-02-02</field> | ||
<field name="expected_price">1600</field> | ||
<field name="selling_price">144000</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="estate_demo_data5" model="estate.property"> | ||
<field name="property_type" ref="id4" /> | ||
<field name="name">Trailor Home</field> | ||
<field name="status">cancelled</field> | ||
<field name="myestate_model">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="estate_demo_data4" model="estate.property"> | ||
<field name="property_type" ref="id4" /> | ||
<field name="name">Trailor Home3</field> | ||
<field name="status">cancelled</field> | ||
<field name="myestate_model">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_id" | ||
eval="[ | ||
Command.create({ | ||
'partner_id': ref('base.res_partner_12'), | ||
'price': '15000002', | ||
'validity':14, | ||
}), | ||
]" /> | ||
</record> | ||
</odoo> |
This file contains 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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="estate_property_offer_demo_1" model="estate.property.offer"> | ||
<field name="partner_id" ref="base.res_partner_12" /> | ||
<field name="property_id" ref="estate.estate_demo_data3" /> | ||
<field name="price">10000</field> | ||
<field name="validity">14</field> | ||
<field name="date_deadline" eval="(datetime.now()+timedelta(days=14))" /> | ||
</record> | ||
<record id="estate_property_offer_demo_2" model="estate.property.offer"> | ||
<field name="partner_id" ref="base.res_partner_12" /> | ||
<field name="property_id" ref="estate.estate_demo_data3" /> | ||
<field name="price">15000000</field> | ||
<field name="validity">14</field> | ||
<field name="date_deadline" eval="(datetime.now()+timedelta(days=14))" /> | ||
</record> | ||
<record id="estate_property_offer_demo_3" model="estate.property.offer"> | ||
<field name="partner_id" ref="base.res_partner_2" /> | ||
<field name="property_id" ref="estate.estate_demo_data3" /> | ||
<field name="price">15000001</field> | ||
<field name="validity">14</field> | ||
<field name="date_deadline" eval="(datetime.now()+timedelta(days=14))" /> | ||
</record> | ||
<function model="estate.property.offer" name="action_confirm"> | ||
<value eval="[ref('estate_property_offer_demo_3')]" /> | ||
</function> | ||
|
||
</odoo> |
This file contains 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 res_users |
This file contains 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,112 @@ | ||
from odoo import api, models, fields | ||
from datetime import datetime | ||
from dateutil.relativedelta import relativedelta | ||
from odoo.exceptions import UserError, ValidationError | ||
|
||
|
||
class estateproperty(models.Model): | ||
_name = "estate.property" #: name of the Model | ||
_description = "estate_model" | ||
_order = "id desc" | ||
|
||
name = fields.Char("Title", default="Unknown") | ||
myestate_model = fields.Text("Description") | ||
postcode = fields.Char("Postcode") | ||
date_availability = fields.Date( | ||
"Available From", copy=False, default=datetime.now() + relativedelta(months=3) | ||
) | ||
expected_price = fields.Float("Expected Price", default=0) | ||
selling_price = fields.Float("Selling Price", copy=False) | ||
bedrooms = fields.Integer("Bedrooms", default=3) | ||
living_area = fields.Integer("Living Area (sqm)", default=2) | ||
facades = fields.Integer("Facades", default=2) | ||
garage = fields.Boolean("Garage") | ||
garden = fields.Boolean("Garden") | ||
garden_area = fields.Integer("Garden Area (sqm)", default=0) | ||
garden_orientation = fields.Selection( | ||
[("north", "north"), ("south", "south"), ("east", "east"), ("west", "west")] | ||
) | ||
active = fields.Boolean("Active", default=True) | ||
status = fields.Selection( | ||
[ | ||
("new", "New"), | ||
("offer received", "Offer Received"), | ||
("offer accepted", "Offer Accepted"), | ||
("sold", "Sold"), | ||
("cancelled", "Cancelled"), | ||
], | ||
default="new", | ||
copy=False, | ||
) | ||
last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now) | ||
property_type = fields.Many2one("estate.property.type", string="Property Type") | ||
sale_id = fields.Many2one( | ||
"res.users", string="Salesman", default=lambda self: self.env.user | ||
) | ||
Buyer_id = fields.Many2one("res.users", string="Buyer", copy=False) | ||
property_tag = fields.Many2many("estate.property.tag", string="Property Tag") | ||
offer_id = fields.One2many("estate.property.offer", "property_id", string="Offers") | ||
total = fields.Float(compute="_compute_total", string="Total Area (sqm)") | ||
best_price = fields.Float(compute="_compute_price", string="Best offer") | ||
|
||
_sql_constraints = [ | ||
( | ||
"check_sellingprice_expectedprice_not_negative", | ||
"CHECK(selling_price >= 0.0 and expected_price >= 0.0)", | ||
"The selling price and expected_price should be greater than 0.", | ||
), | ||
] | ||
|
||
@api.depends("living_area", "garden_area") | ||
def _compute_total(self): | ||
for ele in self: | ||
ele.total = ele.living_area + ele.garden_area | ||
|
||
@api.depends("offer_id.price") | ||
def _compute_price(self): | ||
for ele in self: | ||
ele.best_price = max(ele.mapped("offer_id.price"), default=0) | ||
|
||
@api.onchange("garden") | ||
def _onchange_garden(self): | ||
if self.garden: | ||
self.garden_area = 100 | ||
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = None | ||
|
||
def sold_button(self): | ||
if self.status == "cancelled": | ||
raise UserError("Cancelled Properties cannot be sold") | ||
else: | ||
self.status = "sold" | ||
|
||
def cancel_button(self): | ||
if self.status == "sold": | ||
raise UserError("sold Properties cannot be cancelled") | ||
else: | ||
self.status = "cancelled" | ||
|
||
@api.constrains("selling_price", "expected_price") | ||
def validate_selling_price(self): | ||
for record in self: | ||
if ( | ||
record.selling_price < (0.9 * record.expected_price) | ||
and record.selling_price != 0.0 | ||
): | ||
raise ValidationError( | ||
"the selling price cannot be lower than 90% of the expected price." | ||
) | ||
|
||
@api.ondelete(at_uninstall=False) | ||
def _prevent_property_deletion(self): | ||
for record in self: | ||
if record.status not in ("new", "Cancelled"): | ||
raise UserError("Only new and cancelled properties can be deleted") | ||
|
||
# def check_limit(self, vals): | ||
# self.status = "offer received" | ||
|
||
# if vals.get("price") <= self.best_price: | ||
# raise ValidationError("the offer must be higher than best price") |
This file contains 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,60 @@ | ||
from odoo import api, models, fields | ||
from datetime import date, timedelta | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class EstatePropertyOffer(models.Model): | ||
_name = "estate.property.offer" | ||
_description = "Estate Property Offer" | ||
_order = "price desc" | ||
|
||
price = fields.Float("Price") | ||
status = fields.Selection( | ||
[("Accepted", "Accepted"), ("Refused", "Refused")], readonly=True | ||
) | ||
partner_id = fields.Many2one("res.partner") | ||
property_id = fields.Many2one("estate.property") | ||
property_type_id = fields.Many2one(related="property_id.property_type", store=True) | ||
validity = fields.Integer(string="Validity(days)", default=7) | ||
date_deadline = fields.Date( | ||
string="Deadline", compute="_compute_deadline", inverse="_inverse_deadline" | ||
) | ||
_sql_constraints = [ | ||
( | ||
"check_offerprice_not_negative", | ||
"CHECK(price >= 0.0)", | ||
"The offer price should be greater than 0", | ||
), | ||
] | ||
|
||
@api.depends("validity") | ||
def _compute_deadline(self): | ||
for ele in self: | ||
if not ele.create_date: | ||
ele.create_date = date.today() | ||
ele.date_deadline = ele.create_date + timedelta(days=ele.validity) | ||
|
||
def _inverse_deadline(self): | ||
for ele in self: | ||
ele.validity = abs((ele.date_deadline - ele.create_date.date()).days) | ||
|
||
def action_confirm(self): | ||
for record in self: | ||
record.status = "Accepted" | ||
record.property_id.selling_price = record.price | ||
|
||
def action_cancel(self): | ||
for record in self: | ||
record.status = "Refused" | ||
# record.property_id.selling_price = 0 | ||
|
||
@api.model | ||
def create(self, vals): | ||
# self.env["estate.property"].browse(vals["property_id"]).check_limit(vals) | ||
# return super().create(vals) | ||
record = super().create(vals) | ||
if record.property_id: | ||
record.property_id.status = "offer received" | ||
if record.price < record.property_id.best_price: | ||
raise ValidationError("the offer must be higher than the best price") | ||
return record |
This file contains 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 models, fields | ||
|
||
|
||
class EstatePropertyTag(models.Model): | ||
_name = "estate.property.tag" | ||
_description = "EstatePropertyTag" | ||
_order = "name" | ||
|
||
name = fields.Char(string="tag", required=True) | ||
_sql_constraints = [ | ||
("uniq_propertytag", "unique(name)", "A property tag name must be unique"), | ||
] | ||
color = fields.Integer("color index") |
This file contains 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 @@ | ||
from odoo import models, fields, api | ||
|
||
|
||
class EstateProperty(models.Model): | ||
_name = "estate.property.type" | ||
_description = "EstatePropertyType" | ||
_order = "name" | ||
|
||
name = fields.Char("Property Types", required=True) | ||
_sql_constraints = [ | ||
("uniq_propertytype", "unique(name)", "A property type name must be unique"), | ||
] | ||
property_ids = fields.One2many("estate.property", "property_type") | ||
offer_ids = fields.One2many( | ||
comodel_name="estate.property.offer", inverse_name="property_type_id" | ||
) | ||
offer_count = fields.Integer(compute="_num_of_offers", string="Offer Count") | ||
sequence = fields.Integer( | ||
"Sequence", default=1, help="To manually reorder property types" | ||
) | ||
|
||
api.depends("offer_id") | ||
|
||
def _num_of_offers(self): | ||
for record in self: | ||
record.offer_count = len(record.offer_ids) |
This file contains 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 models, fields | ||
from datetime import datetime | ||
|
||
|
||
class Resusers(models.Model): | ||
_inherit = "res.users" | ||
property_ids = fields.One2many( | ||
"estate.property", | ||
"sale_id", | ||
domain=lambda self: [("date_availability", "<=", datetime.now())], | ||
) |
This file contains 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 | ||
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1 | ||
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1 | ||
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 | ||
estate.access_estate_property_offer,access_estate_property_offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 |
This file contains 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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<menuitem id="test_menu_root" name="Real Estate"> | ||
<menuitem id="test_first_level_menu" name="Advertisement"> | ||
<menuitem id="test_model_menu_action" action="test_model_action" /> | ||
</menuitem> | ||
<menuitem id="test_second_level_menu" name="Settings"> | ||
<menuitem id="test_model_menu_action3" action="action_estate_property_type" /> | ||
<menuitem id="test_model_menu_action2" action="action_estate_property_tag" /> | ||
</menuitem> | ||
</menuitem> | ||
</odoo> |
Oops, something went wrong.