Skip to content
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
15 changes: 15 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
'name': 'Real Estate',
'depends': ['base'],
'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',
],
'application': True,
'author': 'Dilya Anvarbekova',
'license': 'LGPL-3',
}
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
91 changes: 91 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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 = 'Estate Property Information'

name = fields.Char(string='Property Name', required=True)
description = fields.Text(string='Description')
postcode = fields.Char(string='Postcode')
date_availability = fields.Date(string='Available From', copy=False, default=(fields.Date.add(fields.Date.today(), months=3)))
expected_price = fields.Float(string='Expected Price', required=True)
selling_price = fields.Float(string='Selling Price', readonly=True, copy=False)
bedrooms = fields.Integer(string='Bedrooms', default=2)
living_area = fields.Integer(string='Living Area (sqm)')
facades = fields.Integer(string='Number of Facades')
garage = fields.Boolean(string='Garage')
garden = fields.Boolean(string='Garden')
garden_area = fields.Integer(string='Garden Area')
garden_orientation = fields.Selection([('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')], string='Garden Orientation')
active = fields.Boolean(string='Active', default=True)
state = fields.Selection([
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled')
], string='Status', default='new', required=True, copy=False
)
property_type_id = fields.Many2one('estate.property.type', string='Property Type')
buyer_id = fields.Many2one('res.partner', string='Buyer', copy=False)
salesperson_id = fields.Many2one('res.users', string='Salesperson', default=lambda self: self.env.user)
tag_ids = fields.Many2many('estate.property.tag', string='Tags')
offer_ids = fields.One2many('estate.property.offer', 'property_id', string='Offers')

total_area = fields.Integer(compute="_compute_total_area")
best_price = fields.Float(compute="_compute_best_price")

_check_expected_price = models.Constraint(
'CHECK(expected_price > 0)',
"The property expected selling price must be strictly positive."
)
_check_selling_price = models.Constraint(
'CHECK(selling_price >= 0)',
"The property 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:
if record.offer_ids:
record.best_price = max(record.offer_ids.mapped('price'))
else:
record.best_price = 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 = False

@api.constrains('selling_price', 'expected_price')
def _check_selling_price_expected_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=2) \
and float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) < 0:
raise ValidationError("The selling price must be at least 90% of the expected price.")

def action_cancel_property(self):
for record in self:
if record.state == 'sold':
raise UserError("Sold properties cannot be cancelled.")
else:
record.state = 'cancelled'

def action_sell_property(self):
for record in self:
if record.state == 'cancelled':
raise UserError("Cancelled properties cannot be sold.")
else:
record.state = 'sold'
46 changes: 46 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


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

price = fields.Float(string='Price')
status = fields.Selection([('accepted', 'Accepted'), ('refused', 'Refused')], string='Status', copy=False)
partner_id = fields.Many2one('res.partner', string='Partner', required=True)
property_id = fields.Many2one('estate.property', string='Property', required=True)

validity = fields.Integer(string="Validity (days)", default=7)
date_deadline = fields.Date(string="Deadline", compute="_compute_deadline", inverse="_inverse_deadline")

_check_offer_price = models.Constraint(
'CHECK(price > 0)',
'The offer price must be strictly positive.'
)

@api.depends('validity')
def _compute_deadline(self):
for record in self:
start_date = record.create_date.date() if record.create_date else fields.Date.today()
record.date_deadline = fields.Date.add(start_date, days=record.validity)

def _inverse_deadline(self):
for record in self:
start_date = record.create_date.date() if record.create_date else fields.Date.today()
record.validity = (record.date_deadline - start_date).days

def action_accept_offer(self):
for record in self:
if "accepted" in record.property_id.offer_ids.mapped('status'):
raise UserError("An offer has already been accepted for this property.")
record.status = 'accepted'
record.property_id.selling_price = record.price
record.property_id.state = 'offer_accepted'
record.property_id.buyer_id = record.partner_id

def action_refuse_offer(self):
for record in self:
if record.status == 'accepted':
raise UserError("You cannot refuse an accepted offer.")
record.status = 'refused'
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 = 'Estate Property Tag Information'

name = fields.Char(string='Tag Name', required=True)

_check_tag_name_unique = 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 = 'Estate Property Type Information'

name = fields.Char(string='Property Type', required=True)

_check_type_name_unique = 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,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_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,1,1,1,1
13 changes: 13 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_menu_advertisements" name="Advertisements">
<menuitem id="estate_property_menu_action" action="estate_property_action_view"/>
</menuitem>

<menuitem id="estate_menu_settings" name="Settings">
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action_view"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action_view"/>
</menuitem>
</menuitem>
</odoo>
37 changes: 37 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<odoo>
<record id="estate_property_offer_view_tree" 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="Estate Property Offers">
<field name="price" string="Price"/>
<field name="partner_id" string="Partner"/>
<field name="validity" string="Validity (days)"/>
<field name="date_deadline" string="Deadline"/>
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check"/>
<button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times"/>
<field name="status"/>
</list>
</field>
</record>

<record id="estate_property_offer_view_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>
<sheet>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="status"/>
</group>
<group>
<field name="validity" />
<field name="date_deadline" />
</group>
</sheet>
</form>
</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<odoo>
<record id="estate_property_tag_action_view" model="ir.actions.act_window">
<field name="name">Estate Property Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">list,form</field>
</record>

<record id="estate_property_tag_view_form" model="ir.ui.view">
<field name="name">estate.property.tag.form</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<form>
<sheet>
<h1>
<field name="name" string="Tag" />
</h1>
</sheet>
</form>
</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<odoo>
<record id="estate_property_type_action_view" model="ir.actions.act_window">
<field name="name">Estate Property Types</field>
<field name="res_model">estate.property.type</field>
<field name="view_mode">list,form</field>
</record>

<record id="estate_property_type_view_form" model="ir.ui.view">
<field name="name">estate.property.type.form</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form>
<sheet>
<h1>
<field name="name" string="Type" />
</h1>
</sheet>
</form>
</field>
</record>
</odoo>
99 changes: 99 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<odoo>
<record id="estate_property_action_view" model="ir.actions.act_window">
<field name="name">Estate Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</field>
</record>

<record id="estate_property_view_tree" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list string="Estate Properties">
<field name="name"/>
<field name="postcode"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="date_availability"/>
<field name="property_type_id"/>
</list>
</field>
</record>

<record id="estate_property_view_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form string="Estate Property">
<header>
<button name="action_cancel_property" type="object" string="CANCEL" />
<button name="action_sell_property" type="object" string="SOLD" />
</header>
<sheet>
<h1>
<field name="name"/>
</h1>
<field name="tag_ids" widget="many2many_tags"/>
<group>
<group>
<field name="state"/>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="date_availability"/>
</group>
<group>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="best_price" />
</group>
</group>
<notebook>
<page string="Description">
<group>
<field name="description"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="facades"/>
<field name="garage"/>
<field name="garden"/>
<field name="garden_area"/>
<field name="garden_orientation"/>
<field name="total_area" />
</group>
</page>
<page string="Offers">
<field name="offer_ids"/>
</page>
<page string="Other Info">
<group>
<field name="salesperson_id"/>
<field name="buyer_id"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id="estate_property_view_search" model="ir.ui.view">
<field name="name">estate.property.search</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<search string="Estate Property Search">
<field name="name" string="Title"/>
<field name="postcode"/>
<field name="expected_price"/>
<field name="living_area"/>
<field name="bedrooms"/>
<field name="facades"/>
<filter name="available" string="Available" domain="['|', ('state', '=', 'new'), ('state', '=', 'offer_received')]"/>
<group>
<filter string="Postcode" name="postcode" context="{'group_by':'postcode'}"/>
</group>
</search>
</field>
</record>
</odoo>