Skip to content

Commit 5039c7d

Browse files
committed
[IMP] estate: add interactions between elements
1 parent ff4d2d9 commit 5039c7d

8 files changed

+100
-15
lines changed

estate/models/estate_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class EstateProperty(models.Model):
66
_name = "estate.property"
77
_description = "Real Estate property"
8+
_order = "id desc"
89

910
name = fields.Char(required=True)
1011
description = fields.Text()

estate/models/estate_property_offer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
class EstatePropertyOffer(models.Model):
55
_name = "estate.property.offer"
66
_description = "Property offer"
7+
_order = "price desc"
78

89
price = fields.Float()
910
status = fields.Selection(string="Status", copy=False, selection=[("accepted", "Accepted"), ("refused", "Refused")])
1011
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
1112
property_id = fields.Many2one("estate.property", string="Property", required=True)
1213
validity = fields.Integer(default=7)
14+
property_type_id = fields.Many2one(related="property_id.property_type_id", stored=True)
1315

1416
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
1517
create_date = fields.Date(default=lambda _: fields.Date().today())

estate/models/estate_property_tag.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Property tag"
7+
_order = "name"
78

89
name = fields.Char(required=True)
10+
color = fields.Integer()
911

1012
_sql_constraints = [
1113
("check_tag_name", "UNIQUE(name)", "The tag name must be unique")

estate/models/estate_property_type.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Property type"
7+
_order = "name"
78

89
name = fields.Char(required=True)
10+
property_ids = fields.One2many("estate.property", "property_type_id", "Properties")
11+
sequence = fields.Integer(default=1)
12+
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
13+
offer_count = fields.Integer(compute="_compute_offer_count")
914

1015
_sql_constraints = [
1116
("check_type_name", "UNIQUE(name)", "The type name must be unique")
1217
]
18+
19+
@api.depends("offer_ids")
20+
def _compute_offer_count(self):
21+
for property_type in self:
22+
property_type.offer_count = len(property_type.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0"?>
22
<odoo>
3+
<record id="estate_property_offer_action" model="ir.actions.act_window">
4+
<field name="name">Property Offers</field>
5+
<field name="res_model">estate.property.offer</field>
6+
<field name="view_mode">tree,form</field>
7+
<field name="domain">[('property_type_id', '=', active_id)]</field>
8+
</record>
9+
310
<record id="real_estate_offer_view_form" model="ir.ui.view">
411
<field name="name">estate.offer.form</field>
512
<field name="model">estate.property.offer</field>
@@ -26,12 +33,13 @@
2633
<field name="name">estate.offer.tree</field>
2734
<field name="model">estate.property.offer</field>
2835
<field name="arch" type="xml">
29-
<tree string="offer_ids">
36+
<tree string="offer_ids" editable="bottom" decoration-danger="status == 'refused'"
37+
decoration-success="status == 'accepted'">
3038
<field name="price"/>
3139
<field name="partner_id"/>
32-
<button name="action_offer_accepted" type="object" icon="fa-check"/>
33-
<button name="action_offer_refused" type="object" icon="fa-close"/>
34-
<field name="status"/>
40+
<button name="action_offer_accepted" type="object" icon="fa-check" title="Accept"/>
41+
<button name="action_offer_refused" type="object" icon="fa-close" title="Refuse"/>
42+
<field name="status" optional="1"/>
3543
<field name="validity"/>
3644
<field name="date_deadline"/>
3745
</tree>

estate/views/estate_property_tag_views.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,15 @@
1212
</p>
1313
</field>
1414
</record>
15+
16+
<record id="property_tag_tree" model="ir.ui.view">
17+
<field name="name">property.tag.tree</field>
18+
<field name="model">estate.property.tag</field>
19+
<field name="arch" type="xml">
20+
<tree string="Stages" editable="top">
21+
<field name="name"/>
22+
<field name="color"/>
23+
</tree>
24+
</field>
25+
</record>
1526
</odoo>

estate/views/estate_property_type_views.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,48 @@
1212
</p>
1313
</field>
1414
</record>
15+
16+
<record id="property_type_tree" model="ir.ui.view">
17+
<field name="name">property.type.tree</field>
18+
<field name="model">estate.property.type</field>
19+
<field name="arch" type="xml">
20+
<tree string="Stages" multi_edit="1">
21+
<field name="sequence" widget="handle"/>
22+
<field name="name"/>
23+
<field name="property_ids"/>
24+
</tree>
25+
</field>
26+
</record>
27+
28+
<record id="property_type_view_form" model="ir.ui.view">
29+
<field name="name">estate.property.type.view.form</field>
30+
<field name="model">estate.property.type</field>
31+
<field name="arch" type="xml">
32+
<form string="Event Category">
33+
<sheet>
34+
<div name="button_box" position="inside">
35+
<button class="oe_stat_button" name="%(estate_property_offer_action)d" type="action" icon="fa-clock-o">
36+
<field name="offer_count" string="Associated offers" widget="statinfo"/>
37+
</button>
38+
</div>
39+
<div class="oe_title">
40+
<h1><field nolabel="1" name="name"/></h1>
41+
</div>
42+
<notebook>
43+
<page name="Properties">
44+
<group>
45+
<field name="property_ids">
46+
<tree string="Properties">
47+
<field name="name"/>
48+
<field name="expected_price"/>
49+
<field name="state"/>
50+
</tree>
51+
</field>
52+
</group>
53+
</page>
54+
</notebook>
55+
</sheet>
56+
</form>
57+
</field>
58+
</record>
1559
</odoo>

estate/views/estate_property_views.xml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<field name="postcode"/>
1010
<field name="expected_price"/>
1111
<field name="bedrooms"/>
12-
<field name="living_area"/>
12+
<field name="living_area" filter_domain="[('living_area', '>=', self)]"/>
1313
<field name="facades"/>
1414
<field name="property_type_id"/>
1515

@@ -26,8 +26,12 @@
2626
<field name="arch" type="xml">
2727
<form string="Real Estate">
2828
<header>
29-
<button name="action_property_sold" type="object" string="Sold"/>
30-
<button name="action_property_canceled" type="object" string="Canceled"/>
29+
<button name="action_property_sold" type="object" string="Sold"
30+
invisible="state == 'sold' or state == 'new' or state == 'offer received'"/>
31+
<button name="action_property_canceled" type="object" string="Canceled"
32+
invisible="state == 'sold' or state == 'new' or state == 'offer received'"/>
33+
<field name="state" widget="statusbar" statusbar_visible="new,offer received,offer accepted, sold"
34+
options="{'clickable': '1'}"/>
3135
</header>
3236

3337
<sheet>
@@ -37,8 +41,8 @@
3741

3842
<group>
3943
<group>
40-
<field name="property_tag_ids" widget="many2many_tags"/>
41-
<field name="property_type_id"/>
44+
<field name="property_tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
45+
<field name="property_type_id" options="{'no_create': true, 'no_open': true}"/>
4246
<field name="postcode"/>
4347
<field name="date_availability"/>
4448
</group>
@@ -60,8 +64,8 @@
6064
<field name="facades"/>
6165
<field name="garage"/>
6266
<field name="garden"/>
63-
<field name="garden_area"/>
64-
<field name="garden_orientation"/>
67+
<field name="garden_area" invisible="not garden"/>
68+
<field name="garden_orientation" invisible="not garden"/>
6569
<field name="state"/>
6670
<field name="total_area"/>
6771
</group>
@@ -88,16 +92,18 @@
8892
<field name="name">estate.tree</field>
8993
<field name="model">estate.property</field>
9094
<field name="arch" type="xml">
91-
<tree string="Channel">
95+
<tree string="Channel" decoration-success="state == 'offer received' or state == 'offer accepted'"
96+
decoration-bf="state == 'offer accepted'" decoration-muted="state == 'sold'">
9297
<field name="name"/>
93-
<field name="property_tag_ids" widget="many2many_tags"/>
98+
<field name="property_tag_ids" options="{'color_field': 'color'}" widget="many2many_tags"/>
9499
<field name="offer_ids"/>
95100
<field name="postcode"/>
96101
<field name="bedrooms"/>
97102
<field name="living_area"/>
98103
<field name="expected_price"/>
99104
<field name="selling_price"/>
100-
<field name="date_availability"/>
105+
<field name="state" optional="1"/>
106+
<field name="date_availability" optional="1"/>
101107
</tree>
102108
</field>
103109
</record>
@@ -106,6 +112,7 @@
106112
<field name="name">Properties</field>
107113
<field name="res_model">estate.property</field>
108114
<field name="view_mode">tree,form</field>
115+
<field name="context">{'search_default_state': True, 'search_default_current': True}</field>
109116
<field name="help" type="html">
110117
<p class="o_view_nocontent_smiling_face">
111118
Define a new property

0 commit comments

Comments
 (0)