Skip to content
Draft
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': 'Estate',
'version': '1.1',
'category': 'Tutorials',
'summary': 'The Real Estate Advertisement module',
'description': 'Try installing the App',
'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 is depends used for?

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.

if the app is dependent on functions/features of other odoo modules, they must be defined in the depends field. it will load that modules before installing our app

'application': True,
'installable': True,
'author': 'times',
'website': 'https://www.odoo.com/app/estate',
'license': 'LGPL-3',
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_menus.xml',
],
}
1 change: 1 addition & 0 deletions estate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import estate_property
44 changes: 44 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from odoo import fields, models


class EstateProperty(models.Model):
_name = 'estate.property'
_description = "estate property used to buy and sell houses"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Where is this description displayed?

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.

Its the model’s informal name. You can see that displayed in Setting > Technical > Database Structure > Models > Description(column)

_log_access = False
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 is _log_access used for?

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.

_log_access(bool) is used to decide whether create the automatic(access log fields: create_uid, create_date, write_uid, write_date) fields or not.


name = fields.Char(required=True)
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(
default=lambda self: fields.Date.add(fields.Date.context_today(self), months=3),
copy=False
)
expected_price = fields.Float(required=True)
selling_price = fields.Float(readonly=True, copy=False)
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 does copy=False do?

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.

it prevents the field value to be copied over to the new record while duplicated

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(
selection=[
('north', "North"),
('south', "South"),
('east', "East"),
('west', "West"),
],
)
active = fields.Boolean(default=True)
state = fields.Selection(
selection=[
('new', "New"),
('offer_received', "Offer Received"),
('offer_accepted', "Offer Accepted"),
('sold', "Sold"),
('cancelled', "Cancelled"),
],
default='new',
copy=False,
required=True,
)
2 changes: 2 additions & 0 deletions estate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
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 you explain me what happens when you write this line?

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.

it creates a row in the ir_model_access table . what it does : it gives internal users( base.group_user ) access to estate property model with read, write, create and delete permissions

Binary file added estate/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<menuitem id="estate_root_menu" name="Real Estate" web_icon="estate,static/description/icon.png">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this web icon show in the UI?

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, it replaces the default icon of the app and shows this icon.

Image

<menuitem id="estate_first_level_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" name="Properties" action="estate_property_action"/>
</menuitem>
</menuitem>
</odoo>
84 changes: 84 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<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>
<field name='name' string="Title"/>
<field name='postcode'/>
<field name='bedrooms' width="200px"/>
<field name='living_area' string="Living Area (sqm)" width="200px"/>
<field name='expected_price' width="200px"/>
<field name='selling_price' width="200px"/>
<field name='date_availability' string="Available From" width="200px"/>
</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 mb16">
<h1>
<label for="name" string="Property Name"/>
<field name='name' placeholder="Flat no 1"/>
</h1>
</div>
<group col='2'>
<group>
<field name='postcode'/>
<field name='date_availability' string='Available From'/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When do we use view level string and field level string?

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.

We use the field-level string in model python file(estate_property.py) to set the global default label for the field. We use the view-level string in xml views (as seen on line 34 for date_availability) when we need to override that default for a specific view to provide better context to the user without changing the model's core definition.

</group>
<group>
<field name='expected_price'/>
<field name='selling_price'/>
</group>
</group>
<notebook>
<page string='Description'>
<group>
<field name='description'/>
<field name='bedrooms'/>
<field name='living_area' string="Living Area (sqm)"/>
<field name='facades'/>
<field name='garage'/>
<field name='garden'/>
<field name='garden_area' string="Garden Area (sqm)"/>
<field name='garden_orientation'/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id='estate_property_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' string="Title"/>
<field name='postcode'/>
<field name='expected_price'/>
<field name='bedrooms'/>
<field name='living_area' string="Living Area (sqm)" filter_domain="[('living_area', '>=', self)]"/>
<field name='facades'/>
<filter name='active' string='Archived' domain='[("active", "=", False)]'/>
<separator/>
<filter name='state' string='Available' domain='["|", ("state", "=", "new"), ("state", "=", "offer_received")]'/>
<filter name='postcode' string="Postcode" context="{'group_by':'postcode'}"/>
</search>
</field>
</record>

<record id="estate_property_action" model="ir.actions.act_window">
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 is a window action?

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.

A window action is used to create a link between our model and its views by specifying the res_model and view_mode

<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">list,form</field>
</record>
</odoo>