Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aaha - Technical Training #49

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
11 changes: 11 additions & 0 deletions estate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

Choose a reason for hiding this comment

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

Since recently it is not needed to add this line anymore.

Suggested change
# -*- coding: utf-8 -*-

{
'name': 'Real Estate',
'depends': ['base'],
'application': True,
'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
32 changes: 32 additions & 0 deletions estate/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from odoo import models, fields


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

name = fields.Char(required=True, string="Title")
description = fields.Text(string="Description")
postcode = fields.Char(string="Postcode")
date_availability = fields.Date(default=fields.Date.add(fields.Date.today(), days=90), copy=False, string="Available From")

Choose a reason for hiding this comment

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

Not all months consist of 30 days, so to be more precise you can use months option.

Suggested change
date_availability = fields.Date(default=fields.Date.add(fields.Date.today(), days=90), copy=False, string="Available From")
date_availability = fields.Date(default=fields.Date.add(fields.Date.today(), months=3), copy=False, string="Available From")

expected_price = fields.Float(required=True, string="Expected Price")
selling_price = fields.Float(readonly=True, copy=False, string="Selling Price")
bedrooms = fields.Integer(default=2, string="Bedrooms")
living_area = fields.Integer(string="Living Area (sqm)")
facades = fields.Integer(string="Facades")
garage = fields.Boolean(string="Garage")
garden = fields.Boolean(string="Garden")
garden_area = fields.Integer(string="Garden Area (sqm)")
garden_orientation = fields.Selection(
string="Garden Orientation",
selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")],
help="Type to detect orientation of the garden")
active = fields.Boolean(default=True)
state = fields.Selection(
default='new',
selection=[
('new', 'New'),
('offer received', 'Offer Received'),
('offer accepted', 'Offer Accepted'),

Choose a reason for hiding this comment

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

By convention we use pyhon-like style.

Suggested change
('offer received', 'Offer Received'),
('offer accepted', 'Offer Accepted'),
('offer_received', 'Offer Received'),
('offer_accepted', 'Offer Accepted'),

('sold', 'Sold'),
('canceled', 'Canceled')])
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
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
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"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_level_menu" name="Advertisements">
<menuitem id="estate_property_menu_action" name="Properties" action="estate_property_action"/>
</menuitem>
</menuitem>
</odoo>
80 changes: 80 additions & 0 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<odoo>
<record id="estate_property_action" model="ir.actions.act_window">

Choose a reason for hiding this comment

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

usually we put actions after the views declaration

<field name="name">Add Property</field>
<field name="res_model">estate.property</field>
<field name="view_mode">tree,form</field>
</record>

<record id="estate_property_view_tree" model="ir.ui.view">
<field name="name">estate.property.tree</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
<tree string="Channel">
<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"/>
</tree>
</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 string="Property">
<sheet>
<h2>
<field name="name"/>
</h2>
<group>
<group>
<field name="postcode"/>
<field name="date_availability"/>
</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"/>
<field name="facades"/>
<field name="garage" />
<field name="garden"/>
<field name="garden_area"/>
<field name="garden_orientation"/>
</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 string="Search Properties">
<field name="name"/>
<field name="postcode"/>
<field name="expected_price"/>
<field name="bedrooms"/>
<field name="living_area"/>
<field name="facades"/>
<filter name="available" string="Available" domain="['|', ('state', '=', 'new'), ('state', '=', 'offer received')]"/>

Choose a reason for hiding this comment

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

As an alternative way you can write:

Suggested change
<filter name="available" string="Available" domain="['|', ('state', '=', 'new'), ('state', '=', 'offer received')]"/>
<filter name="available" string="Available" domain="[('state', 'in', ('new', 'offer_received'))]"/>

<filter name="groupby_postcode" string="Postcode" context="{'group_by': 'postcode'}"/>
</search>
</field>
</record>

</odoo>