Skip to content
Open
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 real_estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions real_estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Real Estate Application",
"summary": "This is a custom real estate application for understanding Odoo",
"description": "This is a custom real estate application for understanding Odoo",
"author": "Odoo S.A.",
"website": "https://www.odoo.com",
"category": "Tutorials",
"version": "0.1",
"application": True,
"data": [
"data/res_estate_data.xml",
"security/ir.model.access.csv",
"views/estate_property_templates.xml",
"views/estate_property_offers_templates.xml",
"views/estate_property_type_templates.xml",
"views/estate_property_tags_templates.xml",
"views/estate_menu.xml",
],
"assets": {},
"license": "AGPL-3",
}
103 changes: 103 additions & 0 deletions real_estate/data/res_estate_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="type_1" model="estate.property.type">
<field name="name">House</field>
</record>
<record id="type_2" model="estate.property.type">
<field name="name">Apartment</field>
</record>
<record id="type_3" model="estate.property.type">
<field name="name">Castle</field>
</record>
<record id="property_1" model="estate.property">
<field name="name">Property 1</field>
<field name="description">Description 1</field>
<field name="postcode">1000</field>
<field name="expected_price">10000</field>
<field name="selling_price">0</field>
<field name="active">True</field>
<field name="bedrooms">2</field>
<field name="living_area">2</field>
<field name="facades">2</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">22</field>
<field name="state">new</field>
<field name="garden_orientation">north</field>
<field name="property_type" ref="type_1"/>
<!-- <field name="tags">-->
<!-- <record id="tag_1" model="estate.property.tags">-->
<!-- <field name="name">cozy</field>-->
<!-- </record>-->
<!-- <record id="tag_2" model="estate.property.tags">-->
<!-- <field name="name">small</field>-->
<!-- </record>-->
<!-- </field>-->
<field name="offer_ids">
<record id="offer_1" model="estate.property.offers">
<field name="price">20000.00</field>
<field name="partner_id" ref="base.partner_admin"/>
</record>
<record id="offer_2" model="estate.property.offers">
<field name="price">10000.00</field>
<field name="partner_id" ref="base.partner_admin"/>
</record>
</field>
</record>
<record id="property_2" model="estate.property">
<field name="name">Property 2</field>
<field name="description">Description 2</field>
<field name="postcode">2000</field>
<field name="expected_price">10000</field>
<field name="selling_price">0</field>
<field name="active">True</field>
<field name="bedrooms">2</field>
<field name="living_area">2</field>
<field name="facades">2</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">22</field>
<field name="state">new</field>
<field name="garden_orientation">north</field>
<field name="property_type" ref="type_2"/>
<!-- <field name="tags">-->
<!-- <record id="tag_3" model="estate.property.tags">-->
<!-- <field name="name">big</field>-->
<!-- </record>-->
<!-- </field>-->
<field name="offer_ids">
<record id="offer_3" model="estate.property.offers">
<field name="price">20000.00</field>
<field name="partner_id" ref="base.partner_admin"/>
</record>
<record id="offer_4" model="estate.property.offers">
<field name="price">10000.00</field>
<field name="partner_id" ref="base.partner_admin"/>
</record>
</field>
</record>
<record id="property_3" model="estate.property">
<field name="name">Property 3</field>
<field name="description">Description 3</field>
<field name="postcode">1040</field>
<field name="expected_price">10000</field>
<field name="selling_price">0</field>
<field name="active">True</field>
<field name="bedrooms">2</field>
<field name="living_area">2</field>
<field name="facades">2</field>
<field name="garage">True</field>
<field name="garden">True</field>
<field name="garden_area">22</field>
<field name="state">new</field>
<field name="garden_orientation">north</field>
<field name="property_type" ref="type_3"/>
<!-- <field name="tags">-->
<!-- <record id="tag_4" model="estate.property.tags">-->
<!-- <field name="name">expensive</field>-->
<!-- </record>-->
<!-- </field>-->
</record>
</data>
</odoo>
4 changes: 4 additions & 0 deletions real_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_tags
from . import estate_property_offers
116 changes: 116 additions & 0 deletions real_estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from datetime import date

from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare, float_is_zero


class Estate(models.Model):
_name = "estate.property"
_description = "Real_Estate_Property"
_order = "id desc"

name = fields.Char(string="Name", required=True)
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
date_availability = fields.Date(
string="Date Availability",
default=lambda self: date.today() + relativedelta(months=3),
copy=False,
)
expected_price = fields.Float(string="Expected Price", required=True)
selling_price = fields.Float(string="Selling Price", readonly=True, copy=False)
active = fields.Boolean(string="Active", default=True)
bedrooms = fields.Integer(string="Bedrooms", default=2)
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")
state = fields.Selection(
string="State",
selection=[
('new', "New"),
('offered', "Offer Received"),
('accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
required=True,
copy=False,
)
garden_orientation = fields.Selection(
[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
]
)
sales_person = fields.Many2one(
'res.users',
string="Sales Person",
copy=False,
default=lambda self: self.env.user,
)
buyer = fields.Many2one('res.partner', string="Buyer")
property_type = fields.Many2one(
comodel_name="estate.property.type",
string="Property Type",
)
tags = fields.Many2many('estate.property.tags', string="Tags")
offer_ids = fields.One2many('estate.property.offers', 'property_id', string="Offers")
total_area = fields.Integer(compute='_compute_total_area')
best_offer = fields.Float(compute='_compute_best_offer')

@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')
def _compute_best_offer(self):
for record in self:
offers = record.offer_ids.mapped('price')
if offers:
record.best_offer = max(offers)
else:
record.best_offer = 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 = 0

def action_set_sold(self):
for record in self:
if record.state == 'cancelled':
raise UserError("This property cannot be sold.")

Choose a reason for hiding this comment

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

Mark your strings as translatable using self.env._ method

record.state = 'sold'
return True

def action_set_cancel(self):
for record in self:
if record.state == 'sold':
raise UserError("This property is sold.")
record.state = 'cancelled'
return True

@api.constrains('expected_price')
def _check_expected_price(self):
for record in self:
if record.expected_price <= 0:
raise ValidationError("Expected price cannot be negative.")

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
if record.selling_price < 0:
raise ValidationError("Selling price cannot be negative.")
if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1:
raise ValidationError("The selling price cannot be lower than 90% of the expected price!")
49 changes: 49 additions & 0 deletions real_estate/models/estate_property_offers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from datetime import date

from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
from odoo.exceptions import ValidationError


class EstatePropertyOffers(models.Model):
_name = "estate.property.offers"
_description = "Real Estate Property Offers"
_order = "price desc"

price = fields.Float(string="Price")
status = fields.Selection(
string="Status",
selection=[('accepted', "Accepted"), ('rejected', "Rejected")],
copy=False,
readonly=True,
)
partner_id = fields.Many2one(comodel_name='res.partner', required=True)
property_id = fields.Many2one(comodel_name='estate.property', required=True)
property_type_id = fields.Many2one(related='property_id.property_type', store=True)
validity = fields.Integer(string="Validity", default=7)
date_deadline = fields.Date(compute='_compute_date_deadline')

@api.depends('create_date', 'validity')
def _compute_date_deadline(self):
for record in self:
start_date = record.create_date if record.create_date else date.today()
record.date_deadline = start_date + relativedelta(days=record.validity)

def action_accept_offer(self):
for record in self:
record.status = 'accepted'
record.property_id.state = 'accepted'
record.property_id.buyer = record.partner_id
record.property_id.selling_price = record.price
return True

def action_reject_offer(self):
for record in self:
record.status = 'rejected'
return True

@api.constrains('price')
def _check_price(self):
for record in self:
if record.price <= 0:
raise ValidationError("Offer price cannot be negative.")
15 changes: 15 additions & 0 deletions real_estate/models/estate_property_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class EstatePropertyTags(models.Model):
_name = "estate.property.tags"
_description = "Real Estate Property Tags"
_order = "name asc"

name = fields.Char(string="Name", required=True)
color = fields.Integer(string="Color")

_name_uniq = models.Constraint(
'unique (name)',
"This tag is already available",
)
Comment on lines +12 to +15

Choose a reason for hiding this comment

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

Probably fits a single line

16 changes: 16 additions & 0 deletions real_estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import api, fields, models


class EstatePropertyType(models.Model):
_name = "estate.property.type"

Choose a reason for hiding this comment

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

These are tech strings 😉

_description = "Real Estate Property Type"

name = fields.Char(string="Name", required=True)
property_ids = fields.One2many('estate.property', 'property_type')
offer_ids = fields.One2many(comodel_name="estate.property.offers", inverse_name="property_type_id", string="Offers")
offer_count = fields.Integer(compute='_compute_offer_count')

@api.depends('offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
5 changes: 5 additions & 0 deletions real_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,access.estate.property,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type,access.estate.property.type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tags,access.estate.property.tags,model_estate_property_tags,base.group_user,1,1,1,1
access_estate_property_offers,access.estate.property.offers,model_estate_property_offers,base.group_user,1,1,1,1
7 changes: 7 additions & 0 deletions real_estate/views/estate_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo>
<menuitem id="estate_menu_root" name="Real Estate"/>
<menuitem id="estate_menu_action" action="test_model_action" parent="estate_menu_root" sequence="1"/>
<menuitem id="estate_menu_config" name="Settings" parent="estate_menu_root"/>
<menuitem id="estate_property_type_menu_action" action="property_type_action" parent="estate_menu_config"/>
<menuitem id="estate_property_tag_menu_action" action="property_tag_action" parent="estate_menu_config"/>
</odoo>
22 changes: 22 additions & 0 deletions real_estate/views/estate_property_offers_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<odoo>
<record id="property_offer_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offers</field>
<field name="view_mode">list,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>
<record id="property_offers_view_tree" model="ir.ui.view">
<field name="name">estate.property.offers.list</field>
<field name="model">estate.property.offers</field>
<field name="arch" type="xml">
<list string="Property Offer" editable="bottom" decoration-success="status=='accepted'" decoration-danger="status=='rejected'">
<field name="price"/>
<field name="partner_id" string="Partner"/>
<field name="property_type_id" string="Type"/>
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check" invisible="status"/>
<button name="action_reject_offer" string="Reject" type="object" icon="fa-times" invisible="status"/>
</list>
</field>
</record>
</odoo>
17 changes: 17 additions & 0 deletions real_estate/views/estate_property_tags_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>
<record id="property_tag_action" model="ir.actions.act_window">
<field name="name">Property Tags</field>
<field name="res_model">estate.property.tags</field>
<field name="view_mode">list,form</field>
</record>
<record id="property_type_tag_tree" model="ir.ui.view">
<field name="name">estate.property.tags.list</field>
<field name="model">estate.property.tags</field>
<field name="arch" type="xml">
<list string="Estate" editable="bottom">
<field name="name"/>
</list>
</field>
</record>
</odoo>
Loading