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
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
18 changes: 18 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Real Estate",
"version": "1.0",
"author": "Odoo S.A.",
"depends": ["base"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the purpose of depends?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

depends specifies which modules my module relies on. Odoo uses it to ensure those modules are installed and loaded before installing or upgrading my module. In this case, I added base because my module uses the core Odoo framework, such as models.Model, field types, and models like res.users and res.partner.

"application": True,
"category": "tutorials",
"installable": True,
"license": "LGPL-3",
"data": [
"security/ir.model.access.csv",
"views/estate_property_views.xml",
"views/estate_property_type_view.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
64 changes: 64 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from odoo import api, fields, models


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

active = fields.Boolean(default=True)
bedrooms = fields.Integer(default=2)
best_price = fields.Float(compute='_compute_best_price')
buyer_id = fields.Many2one('res.partner', string="Buyer", copy=False)
date_availability = fields.Date(
copy=False, default=lambda self: fields.Date.add(fields.Date.today(), months=3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can this be done in any other way?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, another approach is to create a separate method, for example _default_date_availability(), which returns the default date, and then pass that method to default.

)
description = fields.Text()
expected_price = fields.Float(required=True)
facades = fields.Integer()
garage = fields.Boolean()
garden = fields.Boolean()
garden_area = fields.Integer()
garden_orientation = fields.Selection(
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
]
Comment on lines +22 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
selection=[
("north", "North"),
("south", "South"),
("east", "East"),
("west", "West"),
]
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
]

)
living_area = fields.Integer()
name = fields.Char(required=True)
offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
postcode = fields.Char()
property_type_id = fields.Many2one('estate.property.type', string="Property Type")
salesperson_id = fields.Many2one(
'res.users', string="Salesperson", default=lambda self: self.env.user
)
selling_price = fields.Float(readonly=True, copy=False)
state = fields.Selection(
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
required=True,
copy=False,
default='new',
)
tag_ids = fields.Many2many('estate.property.tag', string="Property Tags")
total_area = fields.Integer(compute='_compute_total_area')

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


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

price = fields.Float()
status = fields.Selection(
selection=[
("accepted", "Accepted"),
("refused", "Refused"),
],
copy=False,
)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=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 models, fields


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

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 models, fields


class EstatePropertyType(models.Model):
_name = "estate.property.type"
_description = "Property Type"

name = fields.Char(required=True)
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

9 changes: 9 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate"/>
<menuitem id="estate_menu_advertisement" name="Advertisement" parent="estate_menu_root"/>
<menuitem id="estate_menu_settings" name="Settings" parent="estate_menu_root"/>
<menuitem id="estate_menu_property" name="Properties" parent="estate_menu_advertisement" action="estate_property_action"/>
<menuitem id="estate_menu_property_type" name="Property Types" parent="estate_menu_settings" action="estate_property_type_action"/>"
<menuitem id="estate_menu_property_tag" name="Property Tags" parent="estate_menu_settings" action="estate_property_tag_action"/>
</odoo>
30 changes: 30 additions & 0 deletions estate/views/estate_property_offer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<odoo>
<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="Property Offers">
<field name="price"/>
<field name="status"/>
<field name="partner_id"/>
</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 string="Property Offer">
<sheet>
<group>
<field name="price"/>
<field name="status"/>
<field name="partner_id"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>
8 changes: 8 additions & 0 deletions estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<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>
9 changes: 9 additions & 0 deletions estate/views/estate_property_type_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version = "1.0"?>
<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>

113 changes: 113 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0"?>
<odoo>
<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>

<record id="estate_property_view_list" model="ir.ui.view">
<field name="name">estate.property.list</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<list string="Properties">
<field name="name"/>
<field name="postcode"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="expected_price"/>
<field name="selling_price"/>
<field name="date_availability"/>
<field name="property_type_id"/>
<field name="tag_ids" widget="many2many_tags"/>
</list>
</field>
</record>

<record id="estate_property_view_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
</div>
<group>
<field name="tag_ids" widget="many2many_tags"/>
</group>
<group>
<group>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="date_availability"/>
</group>
<group>
<field name="expected_price"/>
<field name="best_price"/>
<field name="selling_price"/>
</group>
</group>
<notebook>
<page string="Description">
<group>
<field name="description"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="facades"/>
<field name="garage"/>
<field name="garden"/>
<field name="garden_area"/>
<field name="garden_orientation"/>
<field name="total_area"/>
</group>
</page>
<page string="Offers">
<field name="offer_ids">
<list>
<field name="price"/>
<field name="status"/>
<field name="partner_id"/>
</list>
</field>
</page>
<page string="Other Information">
<group>
<field name="salesperson_id"/>
<field name="buyer_id"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id="estate_property_view_search" model="ir.ui.view">
<field name="name">estate.property.search</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="property_type_id"/>
<field name="postcode"/>
<field name="expected_price"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="facades"/>

<filter
string="Available"
name="available"
domain="[('state', 'in', ['new', 'offer_received'])]"/>
<filter
string="Postcode"
name="group_postcode"
context="{'group_by': 'postcode'}"/>
</search>
</field>
</record>
</odoo>