Skip to content

Commit 167ed52

Browse files
committed
[IMP] estate: Improve UI, ordering, filters, and constraints
• Introduced inline list view for property types. • Added status bar widget for property state visualization. • Set default and manual ordering for multiple models. • Included sequence field for property types to enable manual ordering. • Prevented property type editing directly from the property form. • Enabled color picker for property tags. • Adjusted button visibility based on property state. • Made garden-related fields invisible when no garden exists. • Restricted offer submissions when property is in specific states. • Made list views for offers and tags editable. • Set availability date as optional and hidden by default. • Applied visual decorations for various property and offer states. • Implemented default filter to display available properties. • Enhanced search filter for living area. • Added stat button to property types to monitor associated offers. • Filtered stat button results to display only relevant offers.
1 parent e06b60d commit 167ed52

11 files changed

+103
-33
lines changed

estate/__init__.py

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

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"data": [
77
"security/ir.model.access.csv",
88
"views/estate_property_views.xml",
9+
"views/estate_property_offer_views.xml",
910
"views/estate_property_type_views.xml",
1011
"views/estate_property_tag_views.xml",
11-
"views/estate_property_offer_views.xml",
1212
"views/estate_menus.xml",
1313
],
1414
"license": "LGPL-3",

estate/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from . import estate_property
22
from . import estate_property_type
33
from . import estate_property_tag
4-
from . import estate_property_offer
4+
from . import estate_property_offer

estate/models/estate_property.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
from datetime import timedelta
12
from odoo import models, fields, api
23
from odoo.exceptions import ValidationError
34
from odoo.exceptions import UserError
45
from odoo.tools import float_is_zero, float_compare
5-
from datetime import timedelta
66

77

88
class EstateProperty(models.Model):
99
_name = "estate.property"
1010
_description = "Estate Property"
11+
_order = "id desc"
1112

1213
name = fields.Char(string="Name", required=True)
1314
description = fields.Text(string="Description")
@@ -56,6 +57,8 @@ class EstateProperty(models.Model):
5657
("sold", "Sold"),
5758
("cancelled", "Cancelled"),
5859
],
60+
compute="_compute_state",
61+
store=True,
5962
)
6063
salesman_id = fields.Many2one(
6164
"res.users", string="Salesman", default=lambda self: self.env.user
@@ -92,6 +95,14 @@ def _compute_best_price(self):
9295
for property in self:
9396
property.best_price = max(property.offer_ids.mapped("price"), default=0.0)
9497

98+
@api.depends("offer_ids")
99+
def _compute_state(self):
100+
for record in self:
101+
if record.offer_ids and record.selling_price == 0.0:
102+
record.state = "offer received"
103+
else:
104+
record.state = "new"
105+
95106
@api.onchange("garden")
96107
def _onchange_garden(self):
97108
for property in self:

estate/models/estate_property_offer.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from datetime import timedelta
12
from odoo import models, fields, api
23
from odoo.exceptions import UserError
3-
from datetime import timedelta
44

55

66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Estate Property Offer"
9+
_order = "price desc"
910

1011
price = fields.Float(string="Price")
1112
status = fields.Selection(
@@ -16,7 +17,7 @@ class EstatePropertyOffer(models.Model):
1617
],
1718
)
1819
validity = fields.Integer(
19-
string="Validity (days)",
20+
string="Validity(days)",
2021
default=7,
2122
help="Validity of the offer in days, after that it will be refused automatically.",
2223
)
@@ -28,6 +29,12 @@ class EstatePropertyOffer(models.Model):
2829
)
2930
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
3031
property_id = fields.Many2one("estate.property", string="Property", required=True)
32+
property_type_id = fields.Many2one(
33+
"estate.property.type",
34+
string="Property Type",
35+
related="property_id.property_type_id",
36+
store=True,
37+
)
3138

3239
@api.depends("validity")
3340
def _compute_date_deadline(self):
@@ -76,7 +83,9 @@ def action_set_accepted(self):
7683

7784
def action_set_refused(self):
7885
for offer in self:
79-
if offer.status == "accepted":
86+
if offer.status is False:
87+
offer.status = "refused"
88+
elif offer.status == "accepted":
8089
offer.status = "refused"
8190
offer.property_id.state = "offer received"
8291
offer.property_id.buyer_id = False

estate/models/estate_property_tag.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag"
7-
8-
name = fields.Char(string="Tag Name", required=True)
9-
description = fields.Text(string="Description")
10-
117
_sql_constraints = [
128
("unique_name", "UNIQUE(name)", "A tag with same name is already exists."),
139
]
10+
_order = "name asc"
11+
12+
name = fields.Char(string="Tag Name", required=True)
13+
description = fields.Text(string="Description")
14+
color = fields.Integer(string="Color")

estate/models/estate_property_type.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
22

33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Estate Property Type"
7-
8-
name = fields.Char(required=True)
9-
107
_sql_constraints = [
118
("unique_name", "UNIQUE(name)", "A type with same name is already exists."),
129
]
10+
_order = "sequence,name"
11+
12+
name = fields.Char(required=True)
13+
property_ids = fields.One2many(
14+
comodel_name="estate.property",
15+
inverse_name="property_type_id",
16+
string="Properties",
17+
)
18+
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
19+
sequence = fields.Integer(
20+
"Sequence", default=1, help="Used to order types. Lower is better."
21+
)
22+
23+
offer_count = fields.Integer("Offers", compute="_compute_offer_count")
24+
25+
@api.depends("offer_ids")
26+
def _compute_offer_count(self):
27+
for record in self:
28+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<odoo>
4+
<record id="estate_property_offer_action" model="ir.actions.act_window">
5+
<field name="name">Property Offer</field>
6+
<field name="res_model">estate.property.offer</field>
7+
<field name="view_mode">list,form</field>
8+
<field name="domain">[('property_type_id', '=', active_id)]</field>
9+
</record>
10+
411
<record id="estate_property_offer_view" model="ir.ui.view">
512
<field name="name">estate.property.offer.list</field>
613
<field name="model">estate.property.offer</field>
714
<field name="arch" type="xml">
8-
<list>
15+
<list editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
916
<field name="price"/>
1017
<field name="status"/>
1118
<field name="partner_id"/>
1219
<field name="validity"/>
13-
<button name="action_set_accepted" string="Accepted" type="object" icon="fa-check"/>
14-
<button name="action_set_refused" string="Refused" type="object" icon="fa-times"/>
20+
<button name="action_set_accepted" string="Accepted" type="object" icon="fa-check"
21+
invisible="status != False"/>
22+
<button name="action_set_refused" string="Refused" type="object" icon="fa-times"
23+
invisible="status != False"/>
1524
<field name="date_deadline"/>
1625
</list>
1726
</field>

estate/views/estate_property_tag_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<field name="name">estate.property.tag.list</field>
1818
<field name="model">estate.property.tag</field>
1919
<field name="arch" type="xml">
20-
<list string="Property Types">
20+
<list string="Property Types" editable="bottom">
2121
<field name="name"/>
2222
<field name="description"/>
2323
</list>

estate/views/estate_property_type_views.xml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<field name="model">estate.property.type</field>
1919
<field name="arch" type="xml">
2020
<list string="Property Types">
21+
<field name="sequence" widget="handle"/>
2122
<field name="name"/>
2223
</list>
2324
</field>
@@ -30,9 +31,28 @@
3031
<field name="arch" type="xml">
3132
<form string="Property Type">
3233
<sheet>
33-
<group>
34+
<div class="oe_button_box" name='button_box'>
35+
<button class="oe_stat_button" type='action'
36+
name='estate.estate_property_offer_action'
37+
icon="fa-th-list"
38+
invisible="offer_count == 0">
39+
<field name='offer_count' string='Offers' widget='statinfo'/>
40+
</button>
41+
</div>
42+
<h1>
3443
<field name="name"/>
35-
</group>
44+
</h1>
45+
<notebook>
46+
<page string="Properties">
47+
<field name="property_ids">
48+
<list>
49+
<field name="name"/>
50+
<field name="expected_price"/>
51+
<field name="state"/>
52+
</list>
53+
</field>
54+
</page>
55+
</notebook>
3656
</sheet>
3757
</form>
3858
</field>

0 commit comments

Comments
 (0)