Skip to content

Commit 4ea76b3

Browse files
committed
[IMP] estate : ch10 UI improvements with more filters, conditions and views
1 parent c17a576 commit 4ea76b3

8 files changed

+83
-17
lines changed

estate/models/estate_property.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstateProperty(models.Model):
77
_name = "estate.property"
88
_description = "Estate property model"
9+
_order = "id desc"
910

1011
_check_expected_price = models.Constraint(
1112
'CHECK(expected_price > 0)',
@@ -95,13 +96,15 @@ def action_mark_as_sold(self):
9596
if record.state == "cancelled":
9697
raise UserError(_("Canceled properties cannot be sold."))
9798
record.state = "sold"
99+
record.active = False
98100
return True
99101

100102
def action_mark_as_cancelled(self):
101103
for record in self:
102104
if record.state == "sold":
103105
raise UserError(_("Sold properties cannot be cancelled."))
104106
record.state = "cancelled"
107+
record.active = False
105108
return True
106109

107110
@api.constrains('expected_price')

estate/models/estate_property_offer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Estate property offer"
9+
_order = "price desc"
910

1011
_check_offer_price = models.Constraint(
1112
'CHECK(price > 0)', 'Offer price must be strictly positive.'
@@ -37,7 +38,10 @@ def create(self, vals_list):
3738
required=True,
3839
)
3940
property_id = fields.Many2one(
40-
'estate.property', string='Property', ondelete='restrict', required=True
41+
'estate.property', string='Property', ondelete='restrict', required=True,
42+
)
43+
property_type_id = fields.Many2one(
44+
related='property_id.property_type_id', string='Property Type', store=True,
4145
)
4246

4347
@api.depends("validity", "offer_creation_date")

estate/models/estate_property_tag.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate property tag"
7+
_order = "name"
78
_name_unique = models.Constraint(
89
'unique (name)',
910
'A property tag of that name already exists',
1011
)
1112

1213
name = fields.Char('Property Tag', required=True)
14+
color = fields.Integer('Color Index', default=0)
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

44
class EstatePropertyType(models.Model):
5-
_name = "estate.property.type"
6-
_description = "Estate property type"
5+
_name = 'estate.property.type'
6+
_description = 'Estate property type'
7+
_order = 'name'
78
_name_unique = models.Constraint(
89
'unique (name)',
910
'A property type of that name already exists',
1011
)
1112

1213
name = fields.Char('Property Type', required=True)
14+
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
15+
sequence = fields.Integer('Sequence', default=1)
16+
offer_count = fields.Integer('Number of offers', default=0, compute="_compute_offers_count")
17+
18+
@api.depends("property_ids")
19+
def _compute_offers_count(self):
20+
for record in self:
21+
record.offer_count = sum([len(property.offer_ids) for property in record.property_ids])

estate/views/estate_property_offer_view.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@
2525
<field name="name">estate.property.offer.list</field>
2626
<field name="model">estate.property.offer</field>
2727
<field name="arch" type="xml">
28-
<list string="Channel">
28+
<list string="Channel" editable="bottom" decoration-danger="status == 'no'" decoration-success="status == 'yes'">
2929
<field name="price"/>
3030
<field name="partner_id"/>
3131
<field name="validity"/>
3232
<field name="deadline"/>
33-
<field name="status"/>
34-
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check"/>
35-
<button name="action_reject_offer" string="Reject" type="object" icon="fa-remove"/>
33+
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check" invisible="status in ('yes', 'no')"/>
34+
<button name="action_reject_offer" string="Reject" type="object" icon="fa-remove" invisible="status in ('yes', 'no')"/>
3635
</list>
3736
</field>
3837
</record>
3938

39+
<record id="estate_property_offers_action" model="ir.actions.act_window">
40+
<field name="name">Property Offers</field>
41+
<field name="res_model">estate.property.offer</field>
42+
<field name="view_mode">list</field>
43+
<field name="domain">[('property_type_id', '=', active_id)]</field>
44+
</record>
45+
46+
4047
</odoo>

estate/views/estate_property_tag_view.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@
55
<field name="res_model">estate.property.tag</field>
66
<field name="view_mode">list</field>
77
</record>
8+
9+
<record id="estate_property_tag_view_tree" model="ir.ui.view">
10+
<field name="name">estate.property.tag.list</field>
11+
<field name="model">estate.property.tag</field>
12+
<field name="arch" type="xml">
13+
<list string="Channel" editable="bottom">
14+
<field name="name"/>
15+
</list>
16+
</field>
17+
</record>
818
</odoo>

estate/views/estate_property_type_view.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
<record id="estate_property_types_action" model="ir.actions.act_window">
44
<field name="name">Property Types</field>
55
<field name="res_model">estate.property.type</field>
6-
<field name="view_mode">list</field>
6+
<field name="view_mode">list,form</field>
7+
</record>
8+
9+
<record id="estate_property_types_view_form" model="ir.ui.view">
10+
<field name="name">estate.property.type.form</field>
11+
<field name="model">estate.property.type</field>
12+
<field name="arch" type="xml">
13+
<form string="Property Type Form">
14+
<field name="name"/>
15+
<button name="%(estate.estate_property_offers_action)d"
16+
class="oe_stat_button"
17+
icon="fa-bars"
18+
string="Offers"
19+
type="action">
20+
</button>
21+
</form>
22+
</field>
23+
</record>
24+
25+
<record id="estate_property_type_view_tree" model="ir.ui.view">
26+
<field name="name">estate.property.type.list</field>
27+
<field name="model">estate.property.type</field>
28+
<field name="arch" type="xml">
29+
<list string="Channel">
30+
<field name="name"/>
31+
<field name="offer_count"/>
32+
<field name="sequence" widget="handle"/>
33+
</list>
34+
</field>
735
</record>
836
</odoo>

estate/views/estate_property_view.xml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<record id="estate_property_action" model="ir.actions.act_window">
55
<field name="name">Real Estate Properties</field>
66
<field name="res_model">estate.property</field>
7+
<field name="context">{'search_default_property_state': True}</field>
78
<field name="view_mode">list,form</field>
89
<field name="help" type="html">
910
<p class="o_view_nocontent_smiling_face">
@@ -18,9 +19,10 @@
1819
<field name="arch" type="xml">
1920
<form string="Estate Property Form">
2021
<header>
21-
<button name="action_mark_as_sold" type="object" string="SOLD"/>
22-
<button name="action_mark_as_cancelled" type="object" string="CANCEL"/>
22+
<button name="action_mark_as_sold" type="object" string="SOLD" invisible="not active"/>
23+
<button name="action_mark_as_cancelled" type="object" string="CANCEL" invisible="not active"/>
2324
<field name="state" widget="statusbar"/>
25+
<field name="active" invisible="True"/>
2426
</header>
2527
<sheet>
2628
<div>
@@ -29,7 +31,7 @@
2931
</h1>
3032
<group>
3133
<group>
32-
<field name="property_tags_ids" widget="many2many_tags"/>
34+
<field name="property_tags_ids" widget="many2many_tags" options="{'no_create': True, 'color_field': 'color'}"/>
3335
<field name="property_type_id"/>
3436
<field name="postcode"/>
3537
<field name="date_availability"/>
@@ -50,14 +52,14 @@
5052
<field name="facades"/>
5153
<field name="garage"/>
5254
<field name="garden"/>
53-
<field name="garden_area"/>
54-
<field name="garden_orientation"/>
55+
<field name="garden_area" invisible="not garden"/>
56+
<field name="garden_orientation" invisible="not garden"/>
5557
<field name="total_area"/>
5658
</group>
5759
</page>
5860
<page string="Offers">
5961
<group>
60-
<field name="offer_ids"/>
62+
<field name="offer_ids" readonly="state in ('cancelled', 'sold', 'offer_accepted')"/>
6163
</group>
6264
</page>
6365
<page string="Other Info">
@@ -76,14 +78,14 @@
7678
<field name="name">estate.property.list</field>
7779
<field name="model">estate.property</field>
7880
<field name="arch" type="xml">
79-
<list string="Channel">
81+
<list string="Channel" decoration-success="state in ('offer_received', 'offer_accepted')" decoration-bf="state == 'offer_accepted'" decoration-muted="state == 'sold'">
8082
<field name="name"/>
8183
<field name="postcode"/>
8284
<field name="bedrooms"/>
8385
<field name="living_area"/>
8486
<field name="expected_price"/>
8587
<field name="selling_price"/>
86-
<field name="date_availability"/>
88+
<field name="date_availability" optional="True"/>
8789
</list>
8890
</field>
8991
</record>
@@ -94,6 +96,7 @@
9496
<field name="arch" type="xml">
9597
<search string="Search properties">
9698
<field name="name" string="Property Name" />
99+
<field name="living_area" string="Living Area (sqm)" filter_domain="[('living_area', '>=', self)]"/>
97100
<field name="bedrooms" string="Number Of Bedrooms"/>
98101
<separator/>
99102
<group>

0 commit comments

Comments
 (0)