Skip to content

Commit a2976ed

Browse files
committed
[IMP] chapter5-estate: Add actions, menus and first list/form views
1 parent f488e1f commit a2976ed

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

estate/__manifest__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
'author': "Harsh Maniya",
88
'data': [
99
'security/ir.model.access.csv',
10+
'views/estate_property_views.xml',
11+
'views/estate_menus.xml',
1012
],
1113
'category': 'Sales/Real Estate',
1214
'installable': True,

estate/models/estate_property.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from odoo import models, fields
2+
from dateutil.relativedelta import relativedelta
3+
from datetime import date
24

35

46
class EstateProperty(models.Model):
@@ -8,11 +10,19 @@ class EstateProperty(models.Model):
810
name = fields.Char(string="Property Title", required=True)
911
description = fields.Text(string="Description")
1012
postcode = fields.Char(string="Postcode")
11-
date_availability = fields.Date(string="Available From")
13+
date_availability = fields.Date(
14+
string="Available From",
15+
default=lambda sself: date.today() + relativedelta(months=3),
16+
copy=False
17+
)
1218
expected_price = fields.Float(string="Expected Price", required=True)
13-
selling_price = fields.Float(string="Selling Price")
19+
selling_price = fields.Float(
20+
string="Selling Price",
21+
readonly=True,
22+
copy=False
23+
)
1424

15-
bedrooms = fields.Integer(string="Bedrooms")
25+
bedrooms = fields.Integer(string="Bedrooms", default=2)
1626
living_area = fields.Integer(string="Living Area (sqm)")
1727
facades = fields.Integer(string="Number of Facades")
1828
garage = fields.Boolean(string="Has Garage")
@@ -27,3 +37,17 @@ class EstateProperty(models.Model):
2737
],
2838
string="Garden Orientation"
2939
)
40+
active = fields.Boolean(default=True)
41+
state = fields.Selection(
42+
selection=[
43+
('new', 'New'),
44+
('offer_received', 'Offer Received'),
45+
('offer_accepted', 'Offer Accepted'),
46+
('sold', 'Sold'),
47+
('cancelled', 'Cancelled'),
48+
],
49+
string="Status",
50+
required=True,
51+
copy=False,
52+
default='new',
53+
)

estate/views/estate_menus.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- /home/odoo/odoo19/tutorials/estate/views/estate_menus.xml -->
2+
<odoo>
3+
<menuitem id="menu_estate_root" name="Real Estate"/>
4+
<menuitem id="menu_estate_advertisements" name="Advertisements" parent="menu_estate_root"/>
5+
<menuitem id="menu_estate_properties" name="Properties" parent="menu_estate_advertisements" action="action_estate_property"/>
6+
</odoo>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- /home/odoo/odoo19/tutorials/estate/views/estate_property_views.xml -->
2+
<odoo>
3+
<!-- Action for the model -->
4+
<record id="action_estate_property" model="ir.actions.act_window">
5+
<field name="name">Properties</field>
6+
<field name="res_model">estate.property</field>
7+
<field name="view_mode">list,form</field>
8+
</record>
9+
10+
<!-- list view -->
11+
<record id="view_estate_property_list" model="ir.ui.view">
12+
<field name="name">estate.property.list</field>
13+
<field name="model">estate.property</field>
14+
<field name="arch" type="xml">
15+
<list string="Properties">
16+
<field name="name"/>
17+
<field name="postcode"/>
18+
<field name="expected_price"/>
19+
<field name="selling_price"/>
20+
<field name="bedrooms"/>
21+
<field name="living_area"/>
22+
</list>
23+
</field>
24+
</record>
25+
</odoo>

0 commit comments

Comments
 (0)