Skip to content
Draft
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
2 changes: 2 additions & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
19 changes: 19 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Real Estate",
"version": "1.0",
"author": "Odoo S.A.",
"depends": ["base"],
"application": True,
"category": "Tutorials",
"installable": True,
"license": "LGPL-3",
"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_property_offer_wizard_views.xml",
"views/estate_menus.xml",
],
}
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
101 changes: 101 additions & 0 deletions estate/models/estate_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


class EstateProperty(models.Model):
_name = "estate.property"
_description = "Real Estate Property"

@api.model
def _default_date_availability(self):
return fields.Date.today() + relativedelta(months=3)

active = fields.Boolean(default=True)
name = fields.Char(required=True, default="Unknown")
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(copy=False, default=_default_date_availability)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
bedrooms = fields.Integer(default=2)
living_area = fields.Integer()
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
]
)
state = fields.Selection(
[
("new", "New"),
("offer_received", "Offer Received"),
("offer_accepted", "Offer Accepted"),
("sold", "Sold"),
("cancelled", "Cancelled"),
],
string="State",
required=True,
copy=False,
default="new",
)
property_type_id = fields.Many2one("estate.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 expected price must not be a negative value!",
)

_check_selling_price = models.Constraint(
"CHECK(selling_price > 0)",
"The selling price must not be a negative value!",
)

@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

@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 = ""

def action_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError("Cancelled Property cannot be Sold")
record.state = "sold"

def action_cancel(self):
for record in self:
if record.state == "sold":
raise UserError("Sold Property cannot be Cancelled")
record.state = "cancelled"
69 changes: 69 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from dateutil.relativedelta import relativedelta
from odoo import models, fields, api


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

price = fields.Float()
status = fields.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)
date_deadline = fields.Date(
compute="compute_date_deadline", inverse="inverse_date_deadline"
)

_check_price = models.Constraint("CHECK(price > 0)", "Price must be positive")

@api.depends("validity", "create_date")
def compute_date_deadline(self):
for record in self:
if record.create_date:
record.date_deadline = record.create_date.date() + relativedelta(
days=record.validity
)
else:
record.date_deadline = False

def inverse_date_deadline(self):
for record in self:
if record.create_date and record.date_deadline:
record.validity = (
record.date_deadline - record.create_date.date()
).days

def action_accept(self):
self.ensure_one()
accepted_offer = self.env["estate.property.offer"].search(
[
("property_id", "=", self.property_id.id),
("status", "=", "accepted"),
("id", "!=", self.id),
],
limit=1,
)

if accepted_offer:
return {
"type": "ir.actions.act_window",
"name": "Accept Offer",
"res_model": "estate.property.offer.wizard",
"view_mode": "form",
"target": "new",
"context": {"default_offer_id": self.id},
}

self.status = "accepted"
self.property_id.selling_price = self.price
self.property_id.buyer_id = self.partner_id

def action_refuse(self):
for record in self:
record.status = "refused"
record.property_id.selling_price = 0.0
record.property_id.buyer_id = None
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 = "Real Estate Property Tag"

name = fields.Char(required=True)

_unique_name = models.Constraint(
"UNIQUE(name)",
"The name of the property tag 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 = "Real Estate Property Type"

name = fields.Char(required=True)

_unique_name = models.Constraint(
"UNIQUE(name)",
"The name of the property type must be unique",
)
6 changes: 6 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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
access_estate_property_offer_wizard_user,access.estate.property.offer.wizard.user,model_estate_property_offer_wizard,base.group_user,1,1,1,1
29 changes: 29 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<menuitem
id="estate_menu_root"
name="Real Estate">
<menuitem
id="estate_advertisements_menu"
name="Advertisements">
<menuitem
id="estate_property_menu_action"
action="estate_property_action"/>
</menuitem>
<menuitem
id="estate_property_type_menu"
name="Settings">
<menuitem
id="estate_property_type_menu_action"
action="estate_property_type_action"/>
<menuitem
id="estate_property_tag_menu_action"
action="estate_property_tag_action"/>
<menuitem
id="estate_property_offer_menu_action"
action="estate_property_offer_action"/>
</menuitem>
</menuitem>

</odoo>
46 changes: 46 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record
id="estate_property_offer_action"
model="ir.actions.act_window">
<field name="name">Property Offer</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">list,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>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="property_id"/>
<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="validity"/>
<field name="date_deadline"/>
<field name="property_id"/>
<field name="status"/>
</group>
</sheet>
</form>
</field>
</record>

</odoo>
36 changes: 36 additions & 0 deletions estate/views/estate_property_offer_wizard_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="estate_property_offer_wizard_view_form" model="ir.ui.view">

<field name="name">estate.property.offer.wizard.form</field>
<field name="model">estate.property.offer.wizard</field>
<field name="arch" type="xml">
<form string="Confirmation">

<div>
Another offer is already accepted for this property.
Do you want to replace it?
</div>

<footer>
<button
name="action_keep_previous"
string="Keep Previous"
type="object"
class="btn-secondary"
/>

<button
name="action_accept_new"
string="Accept New"
type="object"
class="btn-primary"
/>
</footer>
</form>
</field>

</record>

</odoo>
12 changes: 12 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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>
12 changes: 12 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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>
Loading