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
16 changes: 16 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
'name': 'Real Estate',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/estate_property_offer_views.xml',
'views/estate_property_views.xml',
'views/estate_property_type_views.xml',
'views/estate_property_tag_views.xml',
'views/res_users_views.xml',
'views/estate_menus.xml',
],
'application': True,
'author': 'Dilya Anvarbekova',
'license': 'LGPL-3',
}
5 changes: 5 additions & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import estate_property
from . import estate_property_type
from . import estate_property_tag
from . import estate_property_offer
from . import res_users
103 changes: 103 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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'
_order = 'id desc'

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.")

@api.ondelete(at_uninstall=False)
def _check_state_on_delete(self):
for record in self:
if record.state not in ["new", "cancelled"]:
raise UserError("Cannot delete a property that is not new or cancelled.")

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'
57 changes: 57 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


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

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)
property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', string='Property Type', store=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.model
def create(self, vals_list):
for vals in vals_list:
prop = self.env['estate.property'].browse(vals.get('property_id'))
if prop.offer_ids:
if vals.get('price') < min(prop.offer_ids.mapped('price')):
raise UserError("The new offer price cannot be lower than existing offers.")
prop.state = 'offer_received'
return super().create(vals_list)

@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'
15 changes: 15 additions & 0 deletions estate/models/estate_property_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import models, fields


class EstatePropertyTag(models.Model):
_name = 'estate.property.tag'
_description = 'Estate Property Tag Information'
_order = 'name asc'

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

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


class EstatePropertyType(models.Model):
_name = 'estate.property.type'
_description = 'Estate Property Type Information'
_order = 'sequence, name asc'

name = fields.Char(string='Property Type', required=True)
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
sequence = fields.Integer(string='Sequence', default=1)
offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers")

offer_count = fields.Integer(compute='_compute_offer_count', string='Offer Count')

_check_type_name_unique = models.Constraint(
'UNIQUE(name)',
'The property type name must be unique.'
)

@api.depends('property_ids.offer_ids')
def _compute_offer_count(self):
for record in self:
record.offer_count = len(record.offer_ids)
12 changes: 12 additions & 0 deletions estate/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import fields, models


class ResUsers(models.Model):
_inherit = 'res.users'

property_ids = fields.One2many(
'estate.property',
'salesperson_id',
string='Assigned Properties',
domain=[('state', 'in', ['new', 'offer_received'])]
)
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>
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 @@
<odoo>
<record id="action_estate_property_offers" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>

<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" editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
<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" invisible="status != False"/>
<button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times" invisible="status != False"/>
</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>
31 changes: 31 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<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_tree" 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 Tags" editable="bottom">
<field name="name"/>
</list>
</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>
52 changes: 52 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<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_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 Types" multi_edit="1">
<field name="sequence" widget="handle"/>
<field name="name" readonly="1"/>
<field name="offer_count" readonly="1"/>
</list>
</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>
<div class="oe_button_box" name="button_box">
<button name="%(action_estate_property_offers)d"
type="action"
class="oe_stat_button"
icon="fa-money">
<field name="offer_count" string="Offers" widget="statinfo"/>
</button>
</div>
<h1>
<field name="name" string="Type" />
</h1>
<notebook>
<page string="Properties">
<field name="property_ids">
<list string="Properties">
<field name="name"/>
<field name="expected_price"/>
<field name="state"/>
</list>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
</odoo>
Loading