Skip to content
Empty file added DO_NOT_REMOVE_THIS.txt
Empty file.
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
25 changes: 25 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
'name': "Estate",
'summary': """
App module created specifically for the Server Framework 101 tutorial.
""",
'description': """
App module created specifically for the Server Framework 101 tutorial.
""",
'author': "Odoo ALMAG",
'website': "https://www.odoo.com",
'category': 'Tutorials',
'version': '0.1',
'depends': ['base', 'web'],
'application': True,
'installable': True,

Choose a reason for hiding this comment

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

Here installable is not mandatory as application is set to true. When application is set, installable is automatically set.

Copy link
Author

Choose a reason for hiding this comment

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

is having it set bad?

'data': [
'data/ir.model.access.csv',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_views.xml',
'views/estate_menus.xml',
],
'licence': 'AGPL-3'
}
5 changes: 5 additions & 0 deletions estate/data/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
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
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
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
105 changes: 105 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from odoo import api, fields, models
from dateutil.relativedelta import relativedelta
from datetime import date
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare, float_is_zero


class EstatePropertyModel(models.Model):
_name = 'estate.property'
_description = "Real Estate property database"
name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(copy=False, default=lambda self: date.today() + relativedelta(months=3))
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
active = fields.Boolean(default=True)
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
selection=[
('north', "North"),
('east', "East"),
('south', "South"),
('west', "West"),
],
string="Garden Orientation",
default='south',
)
state = fields.Selection(
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancel', "Cancelled"),
],
required=True,
copy=False,
default='new',
)

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', string="Total Area (sqm)")
best_price = fields.Float(compute='_compute_best_price', string="Best Offer")

_expected_price_check = models.Constraint('CHECK(expected_price > 0)', "The expected price must be strictly positive.")
_selling_price_check = 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:
offers = record.offer_ids.mapped('price')
if offers:
record.best_price = max(offers)
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

def action_sold(self):
for record in self:
if record.state == "cancel":
raise UserError("Canceled properties cannot be sold.")
record.state = "sold"
return True

def action_cancel(self):
for record in self:
if record.state == "sold":
raise UserError("Sold properties cannot be canceled.")
record.state = "cancel"
return True

@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
if not float_is_zero(record.selling_price, precision_digits=2):
if 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!")
43 changes: 43 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odoo import api, fields, models
from datetime import timedelta


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

price = fields.Float()
status = fields.Selection(
selection=[('accepted', "Accepted"), ('refused', "Refused")],
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_date_deadline', inverse='_inverse_date_deadline')

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

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

def _inverse_date_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(self):
for record in self:
record.status = 'accepted'
record.property_id.buyer_id = record.partner_id
record.property_id.selling_price = record.price
return True

def action_refuse(self):
for record in self:
record.status = 'refused'
return True
10 changes: 10 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


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

name = fields.Char(required=True)

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


class EstatePropertyTypeModel(models.Model):
_name = 'estate.property.type'
_description = "Real Estate property types database"

name = fields.Char(required=True)

_name_check = models.Constraint('UNIQUE(name)', "The name must be unique.")
11 changes: 11 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<menuitem id="estate_menu_root" name="Real Estate"/>
<menuitem id="estate_first_level_menu" name="Advertisements" parent="estate_menu_root"/>
<menuitem id="estate_property_menu_action" action="estate_property_action" parent="estate_first_level_menu"/>
<menuitem id="estate_menu_config" name="Settings" parent="estate_menu_root"/>
<menuitem id="estate_property_type_menu_action" action="estate_property_type_action" parent="estate_menu_config"/>
<menuitem id="estate_property_tag_menu_action" action="estate_property_tag_action" parent="estate_menu_config"/>
</data>
</odoo>
18 changes: 18 additions & 0 deletions estate/views/estate_property_offer_views.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_offer_view_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" type="object" icon="fa-check" title="Accept"/>
<button name="action_refuse" type="object" icon="fa-times" title="Refuse"/>
<field name="status"/>
</list>
</field>
</record>
</odoo>
8 changes: 8 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="estate_property_tag_action" 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>
</record>
</odoo>
8 changes: 8 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="estate_property_type_action" 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>
110 changes: 110 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="estate_property_view_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list string="Properties">
<field name="name"/>
<field name="postcode"/>
<field name="bedrooms"/>
<field name="living_area" string="Living Area (sqm)"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="date_availability" string="Available From"/>
</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="Property">
<header>
<button name="action_sold" type="object" string="Sold" statusbar_visible="new,offer_received,offer_accepted"/>
<button name="action_cancel" type="object" string="Cancel" statusbar_visible="new,offer_received,offer_accepted"/>
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold"/>
</header>
<sheet>
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
<field name="tag_ids" widget="many2many_tags"/>
</div>
<group>
<group>
<field name="state"/>
<field name="postcode"/>
<field name="property_type_id"/>
</group>
<group>
<field name="expected_price"/>
<field name="best_price"/> <field name="selling_price"/>
<field name="date_availability"/>
</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="Property Search">
<field name="name" string="Property Name"/>
<field name="postcode"/>
<field name="expected_price"/>
<field name="bedrooms"/>
<field name="living_area" string="Living Area (sqm)" filter_domain="[('living_area', '>=', self)]"/>
<field name="facades"/>
<separator/>
<filter string="Available" name="available" domain="['|', ('state', '=', 'new'), ('state', '=', 'offer_received')]"/>
<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
<group>
<filter string="Postcode" name="postcode" context="{'group_by': 'postcode'}"/>
</group>
</search>
</field>
</record>

<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create your first property advertisement!
</p>
</field>
</record>
</data>
</odoo>