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
129 changes: 0 additions & 129 deletions .gitignore

This file was deleted.

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 @@
# __manifest__.py
{ # noqa: B018
"author": "Odoo S.A.",
"name": "estate",
"depends": ["base"],
"application": 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_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
82 changes: 82 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from odoo.tools.date_utils import add
from odoo.exceptions import UserError
from odoo import api, fields, models


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

active = fields.Boolean('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)

name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(copy=False, default=lambda self: add(fields.Date.today(), months=3), string="Available From")
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()
has_garage = fields.Boolean()
has_garden = fields.Boolean()
garden_area = fields.Integer(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
string='Type',
selection=[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West')
]
)
Comment on lines +31 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Having the selection list in one line is okay but when we have such multiple values we style it like this.
Also it's better to have the keys of the selection tuples to be all lower case letters to avoid confusion when used later in the code.

Suggested change
garden_orientation = fields.Selection(
string='Type',
selection=[('North', 'North'), ('South', 'South'), ('East', 'East'), ('West', 'West')]
)
garden_orientation = fields.Selection(
string='Garden Orientation',
selection=[
('north', 'North'),
('south', 'South'),
('east', 'East'),
('west', 'West')
]
)

property_type_id = fields.Many2one("estate.property.type", string="Property Type")
buyer = fields.Many2one('res.partner', copy=False)
salesperson = fields.Many2one('res.users', default=lambda self: self.env.user, string="Salesman")
tag_ids = fields.Many2many('estate.property.tag')
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_offer", string="Best Offer")

@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_offer(self):
for record in self:
prices = record.offer_ids.mapped("price")
record.best_price = max(prices) if prices else 0.0

@api.onchange("has_garden")
def _onchange_has_garden(self):
if self.has_garden:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = None

def mark_order_as_sold(self):
for record in self:
if record.state == "cancelled":
raise UserError("Cancelled properties cannot be sold")
else:
record.state = "sold"
return True

def mark_order_as_cancelled(self):
for record in self:
if record.state == "sold":
raise UserError("Sold properties cannot be cancelled")
else:
record.state = "cancelled"
return True
50 changes: 50 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from odoo.tools.date_utils import add
from odoo.exceptions import UserError
from odoo import api, fields, models


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

price = fields.Float()
status = fields.Selection([
('accepted', 'Accepted'),
('refused', 'Refused')
], copy=False)
partner_id = fields.Many2one("res.partner", required=True, string="Partner")
property_id = fields.Many2one("estate.property", required=True)
validity = fields.Integer(default=7, string="Validity (days)")
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline", string="Deadline")

@api.depends("create_date", "validity")
def _compute_date_deadline(self):
for record in self:
base_date = record.create_date.date() if record.create_date else fields.Date.today()
record.date_deadline = add(base_date, days=record.validity)

def _inverse_date_deadline(self):
for record in self:
base_date = record.create_date.date() if record.create_date else fields.Date.today()
if record.date_deadline and base_date:
record.validity = (record.date_deadline - base_date).days

def accept_offer(self):
for record in self:

if record.status == "accepted":
continue

accepted_offer = record.property_id.offer_ids.filtered(lambda offer: offer.status == "accepted")
if accepted_offer:
raise UserError("Only one offer can be accepted for a giver property !")
else:
record.status = "accepted"
record.property_id.buyer = record.partner_id
record.property_id.selling_price = record.price
return True

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


class EstatePropertyTag(models.Model):
_name = "estate.property.tag"
_description = "Estate property tag model"

name = fields.Char(required=True)
8 changes: 8 additions & 0 deletions estate/models/estate_property_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Estate property type model"

name = fields.Char(required=True)
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,estate_property,model_estate_property,base.group_user,1,1,1,1
access_estate_property_type,estate_property_type,model_estate_property_type,base.group_user,1,1,1,1
access_estate_property_tag,estate_property_tag,model_estate_property_tag,base.group_user,1,1,1,1
access_estate_property_offer,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_advertisements_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_settings_menu" name="Settings">
<menuitem id="estate_property_settings_menu_type_action" action="estate_property_type_action"/>
<menuitem id="estate_property_settings_menu_tag_action" action="estate_property_tag_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_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 string="Property">
<header>
<button name="accept_offer" type="object" string="Accept"/>
<button name="refuse_offer" type="object" string="Refuse"/>
</header>
<sheet>
<h1>
<field name="property_id"/>
</h1>
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<field name="status"/>
</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="Properties">
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="accept_offer" type="object" title="Accept" icon="fa-check"/>
<button name="refuse_offer" type="object" title="Refuse" icon="fa-times"/>
<field name="status"/>
</list>
</field>
</record>
</odoo>
22 changes: 22 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<odoo>
<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 string="Property Tag">
<sheet>
<h1>
<field name="name"/>
</h1>
</sheet>
</form>
</field>
</record>

<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>
Loading