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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ MANIFEST
*.manifest
*.spec

#editor
.vscode/

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand Down
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
22 changes: 22 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
'name': 'Real Estate',
'description': 'Real Estate !',
'version': '1.0',
'summary': 'Track Real Estate',
'website': 'https://www.odoo.com/app/realestate',
'author': 'Odoo S.A.',
'application': True,
'license': 'LGPL-3',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'license': 'LGPL-3',
'application': True,
'license': 'LGPL-3',

You probably want to have application=True for this module. See the manifest reference.

'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_list.xml',
'views/estate_view_form.xml',
'views/estate_view_search.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
97 changes: 97 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError
from odoo import api, fields, models


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

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

@api.depends('living_area', 'garden_area')
def _compute_total_area(self):
for rec in self:
rec.total_area = (rec.living_area or 0) + (rec.garden_area or 0)
Comment on lines +64 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

This compute is defined twice (see line 76).


@api.depends('offer_ids.price')
def _compute_best_price(self):
for rec in self:
prices = rec.offer_ids.mapped('price')
rec.best_price = max(prices) if prices else 0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

That works, you can also do

Suggested change
rec.best_price = max(prices) if prices else 0.0
rec.best_price = max(prices, default=0.0)


@api.depends("living_area", "garden_area")
def _compute_total_area(self):
for prop in self:
prop.total_area = prop.living_area + prop.garden_area

@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

def action_sold(self):
if "cancelled" in self.mapped("state"):
Copy link
Contributor

Choose a reason for hiding this comment

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

It works but it's not super readable. I'd do:

Suggested change
if "cancelled" in self.mapped("state"):
if any([prop.state == "cancelled" for prop in self]):

raise UserError("Canceled property cannot be sold !")
return self.write({"state": "sold"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return self.write({"state": "sold"})
self.state = 'sold'
return True

write doesn't return anything, and this notation also works, even if the recordset has many records.


def action_cancel(self):
if "sold" in self.mapped("state"):
raise UserError("Sold property cannot be canceled !")
return self.write({"state": "cancelled"})
48 changes: 48 additions & 0 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from odoo import api, fields, models


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

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

@api.depends('validity')
def _compute_date_deadline(self):
for offer in self:
if offer._origin.validity:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if offer._origin.validity:
if offer.validity:

validity will always be set, worst case to 0 so this if...else can be avoided.

offer.date_deadline = fields.Date.add(
offer.create_date.date(), days=offer.validity
)
else:
offer.date_deadline = False

def action_accept(self):
for offer in self:
offer.state = 'accepted'
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id.id
offer.property_id.state = 'offer_accepted'
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id.id
offer.property_id.state = 'offer_accepted'
offer.property_id.write({
'selling_price': offer.price,
'buyer_id': offer.partner_id.id,
'state': 'offer_accepted',
})

It's better to do those three "write" in one :)

other_offers = offer.property_id.offer_ids.filtered(
lambda o: o.id != offer.id and o.state != 'refused'
)
other_offers.state = 'refused'
return True

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


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

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


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

name = fields.Char("Name", required=True)
sequence = fields.Integer("Sequence")
property_ids = fields.One2many(
"estate.property", "property_type_id", string="Properties"
)
offer_count = fields.Integer(string="Offers count", compute="_compute_offer")
5 changes: 5 additions & 0 deletions estate/security/ir.model.access.csv
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in a folder named security by convention, not data.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

EOL missing at the end of the file.

18 changes: 18 additions & 0 deletions estate/views/estate_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<odoo>
<record id="view_property_tree" model="ir.ui.view">
<field name="name">Estate Property Tree</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list string="Estate Properties">
<field name="name"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="post_code"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="date_availability"/>
</list>
</field>
</record>
</odoo>
Copy link
Contributor

Choose a reason for hiding this comment

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

EOL

11 changes: 11 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_menu_advertisements" name="Advertisements">
<menuitem id="estate_property_menu_action" name="Properties" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_menu_settings" name="Settings">
<menuitem id="estate_property_type_menu_action" name="Property Types" action="estate_property_type_action"/>
<menuitem id="estate_property_tag_menu_action" name="Property Tags" action="estate_property_tag_action" />
</menuitem>
</menuitem>
</odoo>
Copy link
Contributor

Choose a reason for hiding this comment

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

EOL

26 changes: 26 additions & 0 deletions estate/views/estate_property_form_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<record id="view_property_offer_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>
<field name="price"/>
<field name="status"/>
</group>
<group>
<field name="partner_id"/>
<field name="property_id"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="estate_property_offer_action" model="ir.actions.act_window">
<field name="name">Property Offers</field>
<field name="res_model">estate.property.offer</field>
<field name="view_mode">tree,form</field>
</record>
</odoo>
Copy link
Contributor

Choose a reason for hiding this comment

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

EOL

33 changes: 33 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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 Offer">
<group>
<field name="price"/>
<field name="partner_id"/>
<field name="state"/>
</group>
</form>
</field>
</record>
<!-- Add the buttons ‘Accept’ and ‘Refuse’ to the estate.property.offer model. -->
<record id="estate_property_offer_view_tree" model="ir.ui.view">
<field name="name">estate.property.offer.tree</field>
<field name="model">estate.property.offer</field>
<field name="arch" type="xml">
<list string="Property Offers">
<field name="price"/>
<field name="partner_id"/>
<field name="state"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="action_accept" type="object" icon="fa-check" title="Accept"
/>
<button name="action_refuse" type="object" icon="fa-times" title="Accept"
/>
</list>
</field>
</record>
</odoo>
18 changes: 18 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<odoo>
<record id="estate_property_tag_view_tree" model="ir.ui.view">
<field name="name">estate.property.tag.tree</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_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>
Copy link
Contributor

Choose a reason for hiding this comment

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

EOL

31 changes: 31 additions & 0 deletions estate/views/estate_property_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<odoo>
<record id="view_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>
<field name="name"/>
</list>
</field>
</record>

<record id="view_property_type_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>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>

<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>
18 changes: 18 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<odoo>
<record id="view_property_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list>
<field name="name"/>
<field name="property_type_id"/>
</list>
</field>
</record>

<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</field>
</record>
</odoo>
Loading