Skip to content

Commit f575f20

Browse files
[ADD] real_estate: Add property type model and buyer/seller fields
- Introduce a new estate_property_type model to categorize and manage different property types. - Add dedicated fields to the property model for storing buyer and seller information. - Created a form view for the creation of new property types. - Update the property form view to allow selection of buyers and sellers. Chapter #7
1 parent d5a2a5f commit f575f20

8 files changed

Lines changed: 79 additions & 12 deletions

File tree

estate/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'data': [
1111
'security/ir.model.access.csv',
1212
'views/estate_property_views.xml',
13+
'views/estate_property_type_views.xml',
1314
'views/estate_menus.xml'
1415
],
1516
'license': 'LGPL-3', # Default License

estate/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import estate_property
1+
from . import estate_property, estate_property_type

estate/models/estate_property.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class EstateProperty(models.Model):
88
_description = "A real estate model with many fields"
99
active = fields.Boolean(string="Active", default="Active")
1010
bedrooms = fields.Integer(string="Bedrooms", default="2")
11+
buyer = fields.Many2one(
12+
'res.partner', string="Buyer", ondelete='restrict',
13+
)
1114
date_availability = fields.Datetime(
1215
string="Available From", copy=False, default=lambda self: fields.Date.add(fields.Date.context_today(self), months=3))
1316
description = fields.Text(string="Description")
@@ -27,8 +30,13 @@ class EstateProperty(models.Model):
2730
)
2831
garage = fields.Boolean(string="Garage")
2932
living_area = fields.Float(string="Living Area (sqm)")
30-
name = fields.Char(string="Title", required=True, default="Unknown")
33+
name = fields.Char(string="Title", required=True,)
3134
postcode = fields.Char(string="Postcode")
35+
property_type_id = fields.Many2one(
36+
'estate.property.type', string="Property Type")
37+
salesman = fields.Many2one(
38+
'res.users', string="Salesman", ondelete='restrict',
39+
)
3240
selling_price = fields.Float(
3341
string="Selling Price", readonly=True, copy=False)
3442
state = fields.Selection([('new', "New"),
@@ -38,6 +46,11 @@ class EstateProperty(models.Model):
3846
('cancelled', "Cancelled")
3947
],
4048
default='new')
49+
tag_ids = fields.Many2many(
50+
'estate.property.tag',
51+
52+
string="Tags"
53+
)
4154

4255
@api.constrains('expected_price')
4356
def _check_price(self):
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from odoo import fields, models
2+
3+
4+
class EstatePropertyType(models.Model):
5+
6+
_name = 'estate.property.type'
7+
_description = "A model where property types are defined"
8+
9+
name = fields.Char(required=True, string="Property Type")
10+
property_ids = fields.One2many(
11+
'estate.property', inverse_name='property_type_id', string="Properties")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
22
estate.access_estate_property,access_estate_property,estate.model_estate_property,base.group_user,1,1,1,1
3+
estate.access_estate_property_type,access_estate_property_type,estate.model_estate_property_type,base.group_user,1,1,1,1

estate/views/estate_menus.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
<menuitem id="real_estate_root" name="Real Estate" web_icon="estate,static/description/Real_Estate_Logo.jpg" />
55

6-
<menuitem id="real_estate_properties_menu" name="Properties" parent="real_estate_root"/>
6+
<menuitem id="real_estate_properties_menu" name="Advertisements" parent="real_estate_root"/>
7+
<menuitem id="real_estate_properties_settings_menu" name="Settings" parent="real_estate_root" />
78

89
<menuitem id="real_estate_menu_action" name="All Properties " parent="real_estate_properties_menu" action="test_property_action"/>
10+
<menuitem id="real_estate_property_type_action" name="Property Types" parent="real_estate_properties_settings_menu" action="test_property_type_action"/>
11+
912
</odoo>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
4+
<record id="test_property_type_action" model="ir.actions.act_window">
5+
<field name="name">Property Types</field>
6+
<field name="res_model">estate.property.type</field>
7+
<field name="view_mode">list,form</field>
8+
</record>
9+
10+
<record id="estate_property_type_view_form" model="ir.ui.view">
11+
<field name="name">estate.property.type.form</field>
12+
<field name="model">estate.property.type</field>
13+
14+
<field name="arch" type="xml">
15+
<form >
16+
<sheet>
17+
<div class="oe_title oe_inline text-center">
18+
<label for="name"/>
19+
<h1>
20+
<field name="name" default_focus="1" class="oe_inline"/>
21+
</h1>
22+
</div>
23+
</sheet>
24+
</form>
25+
</field>
26+
</record>
27+
28+
</odoo>

estate/views/estate_property_views.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<field name="name">estate.property.list</field>
66
<field name="model">estate.property</field>
77
<field name="arch" type="xml">
8-
<list string="Tags" decoration-danger="state and state == 'cancelled'" limit="20"
9-
decoration-success="state and state == 'offer_accepted'">
8+
<list string="Tags" decoration-danger="state and state == 'cancelled'" limit="20" decoration-success="state and state == 'offer_accepted'">
109
<field name="name" string="Property Title"/>
1110
<field name="postcode" width="96px"/>
1211
<field name="bedrooms"/>
@@ -27,18 +26,20 @@
2726
<field name="arch" type="xml">
2827
<form string="Real Estate">
2928
<header>
30-
<field name="state" widget="statusbar" class="oe_inline_end"
31-
statusbar_visible="new,offer_accepted,offer_received,sold,cancelled"
32-
options="{'clickable': True}"/>
29+
<field name="state" widget="statusbar" class="oe_inline_end" statusbar_visible="new,offer_accepted,offer_received,sold,cancelled" options="{'clickable': True}"/>
3330
</header>
3431
<sheet>
3532
<h1>
36-
<field name="name" string="Property Title"/>
33+
<field name="name" placeholder="Property Title"/>
3734
</h1>
35+
<label for="tag_ids"/>
36+
<field name="tag_ids" widget="many2many_tags" options="{'color_field':'color'}"/>
37+
<separator/>
3838
<group>
3939
<group>
40-
<field name="date_availability"/>
40+
<field name="property_type_id"/>
4141
<field name="selling_price"/>
42+
<field name="date_availability"/>
4243
</group>
4344
<group>
4445
<field name="postcode" width="96px" class="oe_inline oe_left"/>
@@ -58,7 +59,17 @@
5859
<field name="garden_orientation" widget="radio"/>
5960
</group>
6061
</page>
62+
<page string="Other Info">
63+
<group>
64+
<field name="salesman" widget="many2one_avatar_user" />
65+
<field name="buyer" widget="many2one_avatar_user"/>
66+
67+
</group>
68+
</page>
6169
</notebook>
70+
71+
72+
6273
</sheet>
6374
</form>
6475
</field>
@@ -76,8 +87,7 @@
7687
<field name="postcode"/>
7788
<separator/>
7889
<filter string="Date Availability" name="Date Availability" date="date_availability"/>
79-
<filter name="available_properties" string="Available"
80-
domain="['|', ('state','=','offer_received'), ('state','=','new')]"/>
90+
<filter name="available_properties" string="Available" domain="['|', ('state','=','offer_received'), ('state','=','new')]"/>
8191
<group>
8292
<filter string="Postcode" name="group_by_postcode" context="{'group_by':'postcode'}"/>
8393
</group>

0 commit comments

Comments
 (0)