Skip to content

Commit

Permalink
[ADD] estate: Manage Your Properties, Maximize Your Returns
Browse files Browse the repository at this point in the history
-create new estate model
-create offer for a property and relation between properties like one2Many ,
many2Many, many2One
-create computed fields
-create action fields and action buttons for sold & cancle and offer accept &
refused
-create views for property, type, tag and offer
-create security for all the the above model
  • Loading branch information
aneg-odoo committed Sep 23, 2024
1 parent 5308379 commit 374f472
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 0 deletions.
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
21 changes: 21 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Real_Estate",
"depends": ["base"],
"Description": "Estate Module by aneg",
"category": "Real Estate",
"license": "LGPL-3",
"summary": "Real_Estate module for different purpose",
"author": "aneg_odoo",
"version": "0.1",
"application": True,
"installable": True,
"data": [
"security/ir.model.access.csv",
"views/estate_property_offer.xml",
"views/estate_property_views.xml",
"views/estate_property_type.xml",
"views/estate_property_tag.xml",
"views/estate_menus.xml",
"views/res_users_view.xml",
],
}
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
112 changes: 112 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from odoo import api, models, fields
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError, ValidationError


class estateproperty(models.Model):
_name = "estate.property" #: name of the Model
_description = "estate_model"
_order = "id desc"

name = fields.Char("Title", default="Unknown")
myestate_model = fields.Text("Description")
postcode = fields.Char("Postcode")
date_availability = fields.Date(
"Available From", copy=False, default=datetime.now() + relativedelta(months=3)
)
expected_price = fields.Float("Expected Price", default=0)
selling_price = fields.Float("Selling Price", copy=False)
bedrooms = fields.Integer("Bedrooms", default=3)
living_area = fields.Integer("Living Area (sqm)", default=2)
facades = fields.Integer("Facades", default=2)
garage = fields.Boolean("Garage")
garden = fields.Boolean("Garden")
garden_area = fields.Integer("Garden Area (sqm)", default=0)
garden_orientation = fields.Selection(
[("north", "north"), ("south", "south"), ("east", "east"), ("west", "west")]
)
active = fields.Boolean("Active", default=True)
status = fields.Selection(
[
("new", "New"),
("offer received", "Offer Received"),
("offer accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
default="new",
copy=False,
)
last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now)
property_type = fields.Many2one("estate.property.type", string="Property Type")
sale_id = fields.Many2one(
"res.users", string="Salesman", default=lambda self: self.env.user
)
Buyer_id = fields.Many2one("res.users", string="Buyer", copy=False)
property_tag = fields.Many2many("estate.property.tag", string="Property Tag")
offer_id = fields.One2many("estate.property.offer", "property_id", string="Offers")
total = fields.Float(compute="_compute_total", string="Total Area (sqm)")
best_price = fields.Float(compute="_compute_price", string="Best offer")

_sql_constraints = [
(
"check_sellingprice_expectedprice_not_negative",
"CHECK(selling_price >= 0.0 and expected_price >= 0.0)",
"The selling price and expected_price should be greater than 0.",
),
]

@api.depends("living_area", "garden_area")
def _compute_total(self):
for ele in self:
ele.total = ele.living_area + ele.garden_area

@api.depends("offer_id.price")
def _compute_price(self):
for ele in self:
ele.best_price = max(ele.mapped("offer_id.price"), default=0)

@api.onchange("garden")
def _onchange_garden(self):
if self.garden:
self.garden_area = 100
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = None

def sold_button(self):
if self.status == "cancelled":
raise UserError("Cancelled Properties cannot be sold")
else:
self.status = "sold"

def cancel_button(self):
if self.status == "sold":
raise UserError("sold Properties cannot be cancelled")
else:
self.status = "cancelled"

@api.constrains("selling_price", "expected_price")
def validate_selling_price(self):
for record in self:
if (
record.selling_price < (0.9 * record.expected_price)
and record.selling_price != 0.0
):
raise ValidationError(
"the selling price cannot be lower than 90% of the expected price."
)

@api.ondelete(at_uninstall=False)
def _prevent_property_deletion(self):
for record in self:
if record.status not in ("new", "Cancelled"):
raise UserError("Only new and cancelled properties can be deleted")

def check_limit(self, vals):
self.status = "offer received"

if vals.get("price") <= self.best_price:
raise ValidationError("the offer must be higher than best price")
53 changes: 53 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from odoo import api, models, fields
from datetime import date, timedelta


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

price = fields.Float("Price")
status = fields.Selection(
[("Accepted", "Accepted"), ("Refused", "Refused")], readonly=True
)
partner_id = fields.Many2one("res.partner")
property_id = fields.Many2one("estate.property")
property_type_id = fields.Many2one(related="property_id.property_type", store=True)
validity = fields.Integer(string="Validity(days)", default=7)
date_deadline = fields.Date(
string="Deadline", compute="_compute_deadline", inverse="_inverse_deadline"
)
_sql_constraints = [
(
"check_offerprice_not_negative",
"CHECK(price >= 0.0)",
"The offer price should be greater than 0",
),
]

@api.depends("validity")
def _compute_deadline(self):
for ele in self:
if not ele.create_date:
ele.create_date = date.today()
ele.date_deadline = ele.create_date + timedelta(days=ele.validity)

def _inverse_deadline(self):
for ele in self:
ele.validity = abs((ele.date_deadline - ele.create_date.date()).days)

def action_confirm(self):
for record in self:
record.status = "Accepted"
record.property_id.selling_price = record.price

def action_cancel(self):
for record in self:
record.status = "Refused"
record.property_id.selling_price = 0

@api.model
def create(self, vals):
self.env["estate.property"].browse(vals["property_id"]).check_limit(vals)
return super().create(vals)
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 = "EstatePropertyTag"
_order = "name"

name = fields.Char(string="tag", required=True)
_sql_constraints = [
("uniq_propertytag", "unique(name)", "A property tag name must be unique"),
]
color = fields.Integer("color index")
26 changes: 26 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import models, fields, api


class EstateProperty(models.Model):
_name = "estate.property.type"
_description = "EstatePropertyType"
_order = "name"

name = fields.Char("Property Types", required=True)
_sql_constraints = [
("uniq_propertytype", "unique(name)", "A property type name must be unique"),
]
property_ids = fields.One2many("estate.property", "property_type")
offer_ids = fields.One2many(
comodel_name="estate.property.offer", inverse_name="property_type_id"
)
offer_count = fields.Integer(compute="_num_of_offers", string="Offer Count")
sequence = fields.Integer(
"Sequence", default=1, help="To manually reorder property types"
)

api.depends("offer_id")

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


class Resusers(models.Model):
_inherit = "res.users"
property_ids = fields.One2many(
"estate.property",
"sale_id",
domain=lambda self: [("date_availability", "<=", datetime.now())],
)
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
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
estate.access_estate_property_tag,access_estate_property_tag,estate.model_estate_property_tag,base.group_user,1,1,1,1
estate.access_estate_property_offer,access_estate_property_offer,estate.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" encoding="utf-8"?>
<odoo>
<menuitem id="test_menu_root" name="Real Estate">
<menuitem id="test_first_level_menu" name="Advertisement">
<menuitem id="test_model_menu_action" action="test_model_action" />
</menuitem>
<menuitem id="test_second_level_menu" name="Settings">
<menuitem id="test_model_menu_action3" action="action_estate_property_type" />
<menuitem id="test_model_menu_action2" action="action_estate_property_tag" />
</menuitem>
</menuitem>
</odoo>
30 changes: 30 additions & 0 deletions estate/views/estate_property_offer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<odoo>
<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">properties offer </field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('property_type_id', '=', active_id)]</field>
</record>
<record id="estate_property_offer_tree_view" model="ir.ui.view">
<field name="name">estate.property.offer.tree.view</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<tree editable="top" create="1" delete="1" multi_edit="1"
decoration-danger="status=='Refused'"
decoration-success="status=='Accepted'">
<field name="price" />
<field name="partner_id" />
<field name="validity" />
<field
name="date_deadline" />
<button name="action_confirm" type="object"
icon="fa-check" title="refuse" string=""
invisible="status =='Accepted' or status=='Refused'" />
<button
name="action_cancel" type="object" icon="fa-times" title="refuse" string=""
invisible="status =='Accepted' or status=='Refused'" />
<field name="status" optional="hide" />
</tree>
</field>
</record>
</odoo>
16 changes: 16 additions & 0 deletions estate/views/estate_property_tag.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<record id="action_estate_property_tag" model="ir.actions.act_window">
<field name="name">Property Tags</field>
<field name="res_model">estate.property.tag</field>
<field name="view_mode">tree,form</field>
</record>
<record id="estate_property_tag_tree_view" model="ir.ui.view">
<field name="name">estate.property.tag.tree.view</field>
<field name="model">estate.property.tag</field>
<field name="arch" type="xml">
<tree string="property_tags" editable="top" create="1" delete="1" multi_edit="1">
<field name="name" />
</tree>
</field>
</record>
</odoo>
54 changes: 54 additions & 0 deletions estate/views/estate_property_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<odoo>
<record id="action_estate_property_type" model="ir.actions.act_window">
<field name="name">Property Types</field>
<field name="res_model">estate.property.type</field>
<field name="view_mode">tree,form</field>
</record>

<record id="estate_property_type_tree_view" model="ir.ui.view">
<field name="name">state.property.type.tree.view</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<tree string="manual odering of property types">
<field name="sequence" widget="handle" />
<field name="name" />
</tree>
</field>
</record>
<record id="estate_property_type_form_view" model="ir.ui.view">
<field name="name">estate.property.type.form.view</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form string="estate property type form">
<sheet>
<div class="d-flex justify-content-end">
<header>
<button name="%(estate.estate_property_offer_action)d" type="action"
class="oe_stat_button"
icon="fa-money" string="Offers">
<field name="offer_count" string="Offer Count" />
</button>
</header>
</div>
<div>
<h1>
<field name="name" />
</h1>
<notebook>
<page string="Properties">
<field name="property_ids" options='{"format": false}'>
<tree>
<field name="name" />
<field name="expected_price" />
<field name="status" />
</tree>
</field>
</page>
</notebook>
</div>
</sheet>
</form>
</field>

</record>
</odoo>
Loading

0 comments on commit 374f472

Please sign in to comment.