Skip to content

[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
wants to merge 10 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions estate/__init__.py
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
22 changes: 22 additions & 0 deletions estate/__manifest__.py
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',
}
18 changes: 18 additions & 0 deletions estate/data/estate_property_type.xml
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>
49 changes: 49 additions & 0 deletions estate/demo/estate_property_demo.xml
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>
32 changes: 32 additions & 0 deletions estate/demo/estate_property_offer.xml
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>
6 changes: 6 additions & 0 deletions estate/models/__init__.py
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
95 changes: 95 additions & 0 deletions estate/models/estate_property.py
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

Choose a reason for hiding this comment

The 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'
86 changes: 86 additions & 0 deletions estate/models/estate_property_offer.py
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
13 changes: 13 additions & 0 deletions estate/models/estate_property_tag.py
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()
21 changes: 21 additions & 0 deletions estate/models/estate_property_type.py
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)
7 changes: 7 additions & 0 deletions estate/models/res_users.py
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'])])
10 changes: 10 additions & 0 deletions estate/security/ir.model.access.csv
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
26 changes: 26 additions & 0 deletions estate/security/security.xml
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>
Loading