Skip to content

Commit cf9976a

Browse files
author
kukor-odoo
committed
[ADD] estate: enhance views and UI behavior
- Improve estate views following the Sprinkles tutorial. - Add list decorations, inline editing, and statusbar widgets. - Apply deterministic ordering and sequence handling. - Enhance overall UI clarity and usability.
1 parent 7dde16c commit cf9976a

7 files changed

Lines changed: 69 additions & 30 deletions

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
'depends': ['base', 'web'],
77
'data': [
88
'security/ir.model.access.csv',
9+
'views/estate_property_offers.xml',
910
'views/estate_property_views.xml',
1011
'views/estate_type_views.xml',
1112
'views/estate_property_tags.xml',
12-
'views/estate_property_offers.xml',
1313
'views/estate_menus.xml',
1414
],
1515
}

estate/models/estate_property_offer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class EstatePropertyOffer(models.Model):
88
_name = 'estate.property.offer'
99
_description = "Estate Property Offer"
10-
1110
_order = "price desc"
11+
1212
price = fields.Float()
1313
status = fields.Selection(
1414
selection=[('accepted', "Accepted"), ('refused', "Refused")], copy=False
@@ -22,7 +22,8 @@ class EstatePropertyOffer(models.Model):
2222
_offer_price_check = models.Constraint(
2323
'CHECK(price >= 0)', "Offer price should be strictly positive"
2424
)
25-
25+
property_type_id = fields.Many2one(
26+
related='property_id.property_type_id', store=True)
2627
check_button = fields.Char(store=False)
2728

2829
# DEPENDS DECORATOR
@@ -56,7 +57,6 @@ def _compute_offer(self):
5657
])
5758

5859
# BUTTON ACTION - OFFER
59-
6060
def action_accept(self):
6161
for offer in self:
6262
if offer.property_id.buyer_id:
@@ -75,6 +75,7 @@ def action_refuse(self):
7575
record.property_id.selling_price = None
7676
record.property_id.state = 'offer_received'
7777

78+
# OFFER ADDED - STATE CHANGE TO OFFER_RECEIVED
7879
def create(self, vals):
7980
offer = super().create(vals)
8081
if offer.property_id and offer.property_id.state == 'new':

estate/models/estate_property_tags.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class EstatePropertyTags(models.Model):
99

1010
_order = "name"
1111
name = fields.Char("Property Tags", required=True)
12-
color = fields.Integer('Color Index', default=lambda self: random.randint(1, 11))
12+
color = fields.Integer(
13+
'Color Index', default=lambda self: random.randint(1, 11)
14+
)
1315

1416
# SQL CONSTRAINT
1517
_property_tag_uniq = models.Constraint(
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
from odoo import fields, models
1+
from itertools import count
2+
from odoo import api, fields, models
23

34

45
class EstatePropertyType(models.Model):
56
_name = 'estate.property.type'
67
_description = "Estate Property Type"
78
_order = "name"
89

9-
sequence = fields.Integer('Sequence', default=1, help="Used to order Property Type")
10+
sequence = fields.Integer('Sequence', default=1,
11+
help="Used to order Property Type")
1012
name = fields.Char("Property Type", required=True)
11-
property_ids = fields.One2many('estate.property', "property_type_id", required=True)
13+
ofr_ids = fields.One2many('estate.property.offer', 'property_type_id')
14+
offer_count = fields.Integer(compute='_compute_offer')
15+
property_ids = fields.One2many(
16+
'estate.property', "property_type_id", required=True
17+
)
18+
1219
# SQL CONSTRAINT
1320
_property_type_uniq = models.Constraint(
1421
'UNIQUE(name)', "Property Type already exist in database"
1522
)
23+
24+
# DEPEND DECORATOR
25+
@api.depends('ofr_ids')
26+
def _compute_offer(self):
27+
for record in self:
28+
record.offer_count = len(record.ofr_ids)

estate/views/estate_property_offers.xml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
<odoo>
2-
1+
<odoo>
2+
<record id="estate_property_offers_action" model="ir.actions.act_window">
3+
<field name="name">Offers</field>
4+
<field name="res_model">estate.property.offer</field>
5+
<field name="domain">[('property_type_id', '=', active_id)]</field>
6+
</record>
7+
38
<!-- listview -->
49
<record id="estate_property_offer_view_list" model="ir.ui.view">
510
<field name="name">estate.property.offer.view.list</field>
611
<field name="model">estate.property.offer</field>
712
<field name="arch" type="xml">
8-
<list string="Channel" editable="bottom">
13+
<list string="Channel" editable="bottom" decoration-success="status == 'accepted'"
14+
decoration-danger="status == 'refused'">
915
<field name="price"/>
1016
<field name="partner_id"/>
1117
<field name="validity"/>
1218
<field name="date_deadline"/>
13-
<button name="action_accept" type="object" icon="fa-check" title="Accept" invisible="check_button"/>
14-
<button name="action_refuse" type="object" icon="fa-close" title="Refuse" invisible="check_button"/>
19+
<button name="action_accept" type="object" icon="fa-check" title="Accept"
20+
invisible="status in ['accepted','refused']"/>
21+
<button name="action_refuse" type="object" icon="fa-close" title="Refuse"
22+
invisible="status in ['accepted','refused']"/>
1523
<field name="status"/>
1624
</list>
1725
</field>
18-
</record>
19-
20-
<!-- formview -->
26+
</record>
27+
28+
<!-- formview -->
2129
<record id="estate_property_offer_view_form" model="ir.ui.view">
2230
<field name="name">estate.property.offer.view.form</field>
2331
<field name="model">estate.property.offer</field>
@@ -30,7 +38,6 @@
3038
<field name="partner_id"/>
3139
<field name="validity"/>
3240
<field name="date_deadline"/>
33-
<field name="status"/>
3441
</group>
3542
</group>
3643
</sheet>

estate/views/estate_property_views.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
<record id="estate_property_action" model="ir.actions.act_window">
33
<field name="name">Properties</field>
44
<field name="res_model">estate.property</field>
5+
<field name="context">{'search_default_active': 1}</field>
56
</record>
67

78
<!-- listview -->
89
<record id="estate_property_view_list" model="ir.ui.view">
910
<field name="name">estate.property.view.list</field>
1011
<field name="model">estate.property</field>
1112
<field name="arch" type="xml">
12-
<list string="Channel">
13+
<list string="Channel" expand="1" decoration-success="state in ('offer_received', 'offer_accepted')"
14+
decoration-bf="state == 'offer_accepted'" decoration-muted="state == 'sold'">
1315
<field name="name"/>
1416
<field name="property_type_id"/>
1517
<field name="postcode"/>
16-
<field name="date_availability"/>
18+
<field name="date_availability" optional="{'hide':'true'}"/>
1719
<field name="best_price"/>
1820
<field name="living_area"/>
1921
<field name="expected_price"/>
@@ -39,7 +41,8 @@
3941
<field name="name"/>
4042
</h1>
4143
<group>
42-
<field name="property_tag_ids" widget="many2many_tags" string="Property Tag" options="{'color_field' : 'color'}"/>
44+
<field name="property_tag_ids" widget="many2many_tags" string="Property Tag"
45+
options="{'color_field' : 'color'}"/>
4346
</group>
4447
<separator/>
4548
<group>
@@ -75,7 +78,7 @@
7578
</page>
7679
<page string="Offers">
7780
<group>
78-
<field name="offers_id" nolabel="1"/>
81+
<field name="offers_id" nolabel="1" readonly="state in ['sold','cancelled','offer_accepted']"/>
7982
</group>
8083
</page>
8184
<page string="More Info">
@@ -103,8 +106,9 @@
103106
<field name="last_seen"/>
104107
<field name="garden"/>
105108
<field name="garage"/>
106-
<filter string="Garage" name="garage" domain="[('garage', '=', True)]"/>
107-
<filter string="Archived" name="active" domain="[('active', '=', False)]"/>
109+
<field name="living_area" string="Living Area" filter_domain="[('living_area', '>=', self)]"/>
110+
<filter string="Archived" name="unactive" domain="[('active', '=', False)]"/>
111+
<filter string="Active" name="active" domain="[('active', '=', True)]"/>
108112
<filter string="Best Price" name="hei" domain="[('best_price', '>' , 1000)]"/>
109113
<group>
110114
<filter string="Postcode" name="postcode" context="{'group_by': 'postcode'}"/>

estate/views/estate_type_views.xml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,39 @@
1010
<field name="model">estate.property.type</field>
1111
<field name="arch" type="xml">
1212
<list string="Channel" editable="bottom">
13-
<field name="sequence" widget="handle"/>
13+
<field name="sequence" widget="handle"/>
1414
<field name="name"/>
1515
</list>
1616
</field>
1717
</record>
1818

19+
<!-- form view -->
1920
<record id="estate_property_type_view_form" model="ir.ui.view">
2021
<field name="name">estate.property.view.form</field>
2122
<field name="model">estate.property.type</field>
2223
<field name="arch" type="xml">
2324
<form string="">
25+
<header>
26+
</header>
2427
<sheet>
28+
<div class="oe_button_box" name="button_box">
29+
<button type="action" name="%(estate_property_offers_action)d" icon="fa-money">
30+
<div class="o_form_field o_stat_info">
31+
<span class="o_stat_value">
32+
<field name="offer_count" string="Offers" widget="statinfo"/>
33+
</span>
34+
</div>
35+
</button>
36+
</div>
2537
<notebook>
2638
<page name="property" string="Properties">
2739
<field name="property_ids">
28-
<list>
29-
<field name="name" string="Title"/>
30-
<field name="expected_price"/>
31-
<field name="state"/>
32-
</list>
33-
</field>
40+
<list>
41+
<field name="name" string="Title"/>
42+
<field name="expected_price"/>
43+
<field name="state"/>
44+
</list>
45+
</field>
3446
</page>
3547
</notebook>
3648
</sheet>

0 commit comments

Comments
 (0)