Skip to content

Commit c48844b

Browse files
committed
[ADD] real_estate: add security rules, UI menu and basic views for model
This commit covers Chapters 4, 5, and 6 of the server framework tutorial. It includes: - Adding security access rules for the basic model to manage user permissions. - Creating the first user interface by adding a menu item and action to navigate to the model records. - Defining the basic tree (list) view and form view for the model to enable record visualization and editing.
1 parent 8a82939 commit c48844b

File tree

6 files changed

+149
-4
lines changed

6 files changed

+149
-4
lines changed

real_estate/__manifest__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
'name': "RealEstate",
33
'depends': ['base'],
44
'sequence': 1,
5+
'license': 'LGPL-3',
56
'application': True,
67
'category': 'Real Estate',
78
'version': '1.0',
8-
'author': "prbo"
9-
9+
'author': "prbo",
10+
'data': [
11+
'security/ir.model.access.csv',
12+
'views/estate_property_views.xml',
13+
'views/estate_menus.xml'
14+
]
1015
}

real_estate/data/ir.model.access.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
2+
access_estate_property_user,access.estate.property,model_estate_property,base.group_user,1,1,1,1

real_estate/models/estate_property.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import fields, models
2+
from datetime import date, timedelta
23

34
class estate_property(models.Model):
45
_name = "estate.property"
@@ -7,7 +8,11 @@ class estate_property(models.Model):
78
name = fields.Char(required=True)
89
description = fields.Text()
910
postcode = fields.Char()
10-
date_availability = fields.Date(copy=False)
11+
date_availability = fields.Date(
12+
string="Available From",
13+
copy=False,
14+
default=lambda self: date.today() + timedelta(days=90)
15+
)
1116
expected_price = fields.Float(required=True)
1217
selling_price = fields.Float(readonly=True, copy=False)
1318
bedrooms = fields.Integer(default=2)
@@ -21,4 +26,20 @@ class estate_property(models.Model):
2126
selection=[('north', 'North'), ('south', 'South'),
2227
('east', 'East'), ('west', 'West')],
2328
help="Direction of the garden"
24-
)
29+
)
30+
active = fields.Boolean(default=True)
31+
state = fields.Selection(
32+
selection=[
33+
('new', 'New'),
34+
('offer_received', 'Offer Received'),
35+
('offer_accepted', 'Offer Accepted'),
36+
('sold', 'Sold'),
37+
('cancelled', 'Cancelled')
38+
],
39+
required=True,
40+
copy=False,
41+
default='new'
42+
)
43+
44+
45+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_estate_property_user,access.estate.property,model_estate_property,,1,1,1,1

real_estate/views/estate_menus.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<menuitem id="estate_menu_root" name="Estate" sequence="10" />
4+
5+
<menuitem id="estate_menu_property"
6+
name="Properties"
7+
parent="estate_menu_root"
8+
sequence="10" />
9+
10+
<menuitem id="estate_menu_property_action"
11+
parent="estate_menu_property"
12+
action="action_estate_property"
13+
sequence="10" />
14+
15+
</odoo>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="action_estate_property" model="ir.actions.act_window">
4+
<field name="name">Properties</field>
5+
<field name="res_model">estate.property</field>
6+
<field name="view_mode">list,form</field>
7+
8+
</record>
9+
10+
<record id="view_estate_property_tree" model="ir.ui.view">
11+
<field name="name">estate.property.list</field>
12+
<field name="model">estate.property</field>
13+
<field name="arch" type="xml">
14+
<list string="Properties">
15+
<field name="name" />
16+
<field name="postcode" />
17+
<field name="bedrooms" />
18+
<field name="living_area" />
19+
<field name="expected_price" />
20+
<field name="selling_price" />
21+
<field name="date_availability" />
22+
</list>
23+
</field>
24+
</record>
25+
26+
<record id="view_estate_property_form" model="ir.ui.view">
27+
<field name="name">estate.property.form</field>
28+
<field name="model">estate.property</field>
29+
<field name="arch" type="xml">
30+
<form string="Properties">
31+
<sheet>
32+
<h1>
33+
<field name="name" />
34+
</h1>
35+
<group>
36+
37+
<group>
38+
39+
<field name="postcode" />
40+
<field name="date_availability" />
41+
42+
</group>
43+
<group>
44+
<field name="expected_price" />
45+
<field name="selling_price" />
46+
47+
</group>
48+
</group>
49+
<notebook>
50+
<page string="Description">
51+
<group>
52+
53+
<field name="description" />
54+
</group>
55+
<group>
56+
<field name="bedrooms" />
57+
<field name="living_area" />
58+
<field name="facades" />
59+
<field name="garage" />
60+
<field name="garden" />
61+
<field name="garden_area" />
62+
<field name="garden_orientation" />
63+
<field name="state"/>
64+
</group>
65+
</page>
66+
</notebook>
67+
</sheet>
68+
</form>
69+
</field>
70+
</record>
71+
72+
73+
<record id="view_estate_property_search" model="ir.ui.view">
74+
<field name="name">estate.property.search</field>
75+
<field name="model">estate.property</field>
76+
<field name="arch" type="xml">
77+
<search string="Search Properties">
78+
79+
<field name="name" string="Title" />
80+
<field name="postcode" />
81+
<field name="expected_price" />
82+
<field name="bedrooms" />
83+
<field name="living_area" />
84+
<field name="facades" />
85+
86+
87+
<separator />
88+
<filter string="Available" name="available" domain="[('state', 'in', ['new', 'offer_received'])]"/>
89+
90+
91+
<group expand="1" string="Group By">
92+
<filter string="Postcode" name="group_postcode"
93+
context="{'group_by': 'postcode'}" />
94+
</group>
95+
</search>
96+
</field>
97+
</record>
98+
99+
100+
</odoo>

0 commit comments

Comments
 (0)