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 estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
'name': 'Real Estate',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',

'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/estate_property_offer_views.xml',
'views/estate_property_views.xml',
'views/estate_menus.xml',
],
'installable': True,
'application': True,
'author': "Odoo",
'license': 'AGPL-3'
}
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import property, property_offer, property_tag, property_type
101 changes: 101 additions & 0 deletions estate/models/property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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 Property(models.Model):
_name = 'estate.property'
_description = "Estate property"

name = fields.Char(string="Title", required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
string="Available From",
default=lambda self: fields.Date.today() + relativedelta(months=3),
copy=False,
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer(string="Living Area (sqm)")
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
selection=[('north', 'North'), ('south', 'South'), ('east', 'East'), ('west', 'West')]
)
state = fields.Selection(
default="new",
string="Status",
selection=[
('new', 'New'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),
('sold', 'Sold'),
('cancelled', 'Cancelled'),
],
required=True,
copy=False,
)
active = fields.Boolean(default=True)
property_type_id = fields.Many2one('estate.property.type', string="Property Type")
partner_id = fields.Many2one('res.partner', string="Buyer", readonly=True)
user_id = fields.Many2one('res.users', string="Salesman", default=lambda self: self.env.user)
tag_ids = fields.Many2many('estate.property.tag', string="Property Tags")
offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
total_area = fields.Integer(string="Total Area (sqm)", compute='_compute_total_area')
best_offer = fields.Float(default=0.0, compute="_compute_best_offer")

_expected_price_strictly_pos = models.Constraint(
"CHECK(expected_price > 0)", "The expected price must be strictly positive."
)
_selling_price_pos = 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')
def _compute_best_offer(self):
for record in self:
record.best_offer = max(record.offer_ids.mapped('price'))

@api.onchange('garden')
def _onchange_garden(self):
self.garden_area = 10 if self.garden else 0
self.garden_orientation = 'north' if self.garden else ''

@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) and
float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1
):
raise ValidationError(
self.env._(
"The selling price must be at least 90% of the expected price! "
"You must reduce the expected price if you want to accept this offer."
)
)

def action_set_sold(self):
if self.state == 'cancelled':
raise UserError(self.env._("Cancelled properties cannot be sold."))

self.state = 'sold'
return True

def action_set_cancelled(self):
if self.state == 'sold':
raise UserError(self.env._("Sold properties cannot be cancelled."))

self.state = 'cancelled'
return True
46 changes: 46 additions & 0 deletions estate/models/property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from dateutil.relativedelta import relativedelta

from odoo import api, fields, models


class PropertyOffer(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', required=True)
property_id = fields.Many2one('estate.property', required=True)
validity = fields.Integer(default=7, string="Validity (days)")
deadline = fields.Date(compute='_compute_deadline', inverse='_inverse_deadline')

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

@api.depends('validity')
def _compute_deadline(self):
for record in self:
create_date = record.create_date or fields.Date.today()
record.deadline = create_date + relativedelta(days=record.validity)

def _inverse_deadline(self):
for record in self:
record.validity = (record.deadline - fields.Date.to_date(record.create_date)).days

def action_confirm(self):
self.status = 'accepted'
for offer in self.property_id.offer_ids:
if offer.id == self.id:
continue

offer.status = 'refused'

self.property_id.partner_id = self.partner_id
self.property_id.selling_price = self.price

return True

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


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

name = fields.Char(required=True)

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


class PropertyType(models.Model):
_name = 'estate.property.type'
_description = "Property Type"

name = fields.Char(required=True)

_name_uniq = models.Constraint("UNIQUE(name)", "The 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
12 changes: 12 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_property_menu_root" name="Real Estate">
<menuitem id="estate_property_advertisements_menu" name="Advertisements">
<menuitem id="estate_property_model_menu_action" action="estate_property_model_action"/>
</menuitem>
<menuitem id="estate_property_settings_menu" name="Settings">
<menuitem id="estate_property_type_model_menu_action" action="estate_property_type_model_action"/>
<menuitem id="estate_property_tag_model_menu_action" action="estate_property_tag_model_action"/>
</menuitem>
</menuitem>
</odoo>
43 changes: 43 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_type_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 string="Property Offer">
<sheet>
<group>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
</group>
</group>
</sheet>
</form>
</field>
</record>

<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="Property Offer">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="deadline"/>
<button name="action_confirm" type="object" title="Accept" icon="fa-check"/>
<button name="action_refuse" type="object" title="Refuse" icon="fa-times"/>
<field name="status"/>
</list>
</field>
</record>

<record id="estate_property_offer_model_action" model="ir.actions.act_window">
<field name="name">Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list,form</field>
</record>
</odoo>
32 changes: 32 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_tag_model_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 string="Property Tag">
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="estate_property_tag_view_list" model="ir.ui.view">
<field name="name">estate.property.tag.list</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<list string="Property Tag">
<field name="name"/>
</list>
</field>
</record>

<record id="estate_property_tag_model_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>
34 changes: 34 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<odoo>
<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 string="Property Type">
<sheet>
<div class="oe_title">
<h1 class="mb32">
<field name="name" class="mb16"/>
</h1>
</div>
</sheet>
</form>
</field>
</record>

<record id="estate_property_type_view_list" model="ir.ui.view">
<field name="name">estate.property.type.list</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<list string="Property Type">
<field name="name"/>
</list>
</field>
</record>

<record id="estate_property_type_model_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>
Loading