Skip to content
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
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
'name': "Real Estate",
'version': '1.0',
'license': 'LGPL-3',
'summary': 'Real Estate advertisement tutorial module',
'depends': ['base'],
'author': "Harsh Maniya",
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_menus.xml',
],
'category': 'Sales/Real Estate',
'installable': True,
'auto_install': False,
'description': """Real estate management tutorial module with properties, offers, types and tags.""",

Choose a reason for hiding this comment

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

Please adapt this -> #1049 (comment)

}
4 changes: 4 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
128 changes: 128 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
from dateutil.relativedelta import relativedelta
from datetime import date
from odoo import models, fields, api
from odoo.exceptions import UserError,ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero
Comment on lines +1 to +5

Choose a reason for hiding this comment

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

Suggested change
from dateutil.relativedelta import relativedelta
from datetime import date
from odoo import models, fields, api
from odoo.exceptions import UserError,ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero
from dateutil.relativedelta import relativedelta
from datetime import date
from odoo import models, fields, api
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"

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
default=lambda sself: date.today() + relativedelta(months=3),
copy=False
)
expected_price = fields.Float(string="Expected Price", required=True)

Choose a reason for hiding this comment

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

Please follow this -> #1049 (comment)

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()
garden_orientation = fields.Selection(
selection=[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West'),
],
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled'),
],
required=True,
copy=False,
default='new',
)
property_type_id = fields.Many2one(
"estate.property.type",
)
salesperson_id = fields.Many2one(
"res.users",
default=lambda self: self.env.user,
)
buyer_id = fields.Many2one(
"res.partner",
copy=False,
)
tag_ids = fields.Many2many(
"estate.property.tag",
)
offer_ids = fields.One2many(
"estate.property.offer",
"property_id",
)
total_area = fields.Float(
compute="_compute_total_area"
)
best_price = fields.Float(
compute="_compute_best_price",
)
_expected_price = models.Constraint(
'CHECK(expected_price >= 0)',
'The expected price must be positive.',
)
_selling_price = models.Constraint(
'CHECK(selling_price >= 0)',
'The selling price must be 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_price(self):
for record in self:
prices = record.offer_ids.mapped('price')
record.best_price = max(prices) if prices else 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 = None

def action_cancel(self):
for rec in self:
if rec.state == "sold":
raise UserError("Sold properties cannot be cancelled.")
else:
rec.state = "cancelled"
return True
Comment on lines +104 to +110

Choose a reason for hiding this comment

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

I think action_cancel_property will be good.

It's good to make the error message translatable.
raise exceptions.UserError(_("Sold properties cannot be cancelled."))

We can use filtered() here.

if self.filtered(lamda x: x.state=="sold")


def action_set_sold(self):
for rec in self:
if rec.state == "cancelled":
raise UserError("Canceled properties cannot be sold.")
else:
rec.state = "sold"
Comment on lines +112 to +117

Choose a reason for hiding this comment

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

Same here.

return True
@api.constrains("selling_price", "expected_price")

Choose a reason for hiding this comment

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

Should be above one empty line.

def _check_selling_price(self):
for rec in self:
if rec.selling_price == 0:
return False
if float_compare(rec.selling_price, rec.expected_price * 0.9, precision_digits=2) < 0:
raise ValidationError(

Choose a reason for hiding this comment

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

Same here, it should be translatable.

"The selling price must be at least 90% of the expected price!\n"
"You must reduce the expected price if you want to accept this offer."
)
63 changes: 63 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from dateutil.relativedelta import relativedelta
from odoo import models, fields, api
from odoo.exceptions import UserError
Comment on lines +1 to +3

Choose a reason for hiding this comment

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

Suggested change
from dateutil.relativedelta import relativedelta
from odoo import models, fields, api
from odoo.exceptions import UserError
from dateutil.relativedelta import relativedelta
from odoo import models, fields, api
from odoo.exceptions import UserError



class EstatePropertyOffer(models.Model):
_name = "estate.property.offer"
_description = "Real Estate Property Offer"

price = fields.Float(string="Price")
status = fields.Selection(
[
("accepted", "Accepted"),
("refused", "Refused"),
],
copy=False,
)
partner_id = fields.Many2one(
"res.partner",
required=True,
)
property_id = fields.Many2one(
"estate.property",
required=True,
)
validity = fields.Integer(
default=7,
)
date_deadline = fields.Date(
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
store=True,
)

@api.depends("validity")
def _compute_date_deadline(self):
for rec in self:
create = rec.create_date or fields.Date.today()
rec.date_deadline = (create + relativedelta(days=rec.validity))

def _inverse_date_deadline(self):
for rec in self:
create = rec.create_date or fields.Date.today()
rec.validity = (rec.date_deadline - fields.Date.today(create)).days

def action_accept(self):
for offer in self:
if offer.property_id.buyer_id:
raise UserError('Only one offer can be accepted for a property.')
offer.status = 'accepted'
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id
return True

def action_refuse(self):
for offer in self:
offer.status = 'refused'
return True

_offer_price = models.Constraint(

Choose a reason for hiding this comment

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

It is good to declare constraint after the immediate declaration of all fields.

'CHECK (price > 0)',
'Offer price must be greater than 0',
)
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 models, fields


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Real Estate Property Tag"

name = fields.Char(required=True)

_unique_name = models.Constraint(
'unique(name)',
'The tag name must be unique.',
)
13 changes: 13 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import models, fields


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Real Estate Property Type"

name = fields.Char(required=True)

_unique_name = models.Constraint(
'unique(name)',
'The property type name must be unique.',
)
5 changes: 5 additions & 0 deletions estate/security/ir.model.access.csv
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_user,access_estate_property_user,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type_user,access_estate_property_type_user,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag_user,access_estate_property_tag_user,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer_user,access_estate_property_offer_user,model_estate_property_offer,base.group_user,1,1,1,1
16 changes: 16 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<menuitem id="menu_estate_root" name="Real Estate"/>
<menuitem id="menu_estate_advertisements" name="Advertisements" parent="menu_estate_root" sequence="10"/>
<menuitem id="menu_estate_properties" name="Properties" parent="menu_estate_advertisements" action="action_estate_property" sequence="10"/>

<menuitem id="menu_estate_settings" name="Settings" parent="menu_estate_root" sequence="20"/>

<menuitem id="menu_estate_property_types" name="Property Types"
parent="menu_estate_settings"
action="action_estate_property_type"
sequence="10"/>

<menuitem id="menu_estate_property_tags" name="Property Tags"
parent="menu_estate_settings"
action="action_estate_property_tag"/>
Comment on lines +2 to +15

Choose a reason for hiding this comment

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

Indentation issue and empty line before . if you want to leave an empty line, then you should follow the same for others too.

</odoo>
35 changes: 35 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
<button name="action_refuse" string="Refuse" type="object" icon="fa-close" />
<field name="status"/>
</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="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
10 changes: 10 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<odoo>
<record id="action_estate_property_tag" model="ir.actions.act_window">
<field name="name">Property Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p>Create and manage tags for your properties.</p>
</field>
</record>
</odoo>
7 changes: 7 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo>
<record id="action_estate_property_type" model="ir.actions.act_window">
<field name="name">Property Types</field>
<field name="res_model">estate.property.type</field>
<field name="view_mode">list,form</field>
</record>
</odoo>
Loading