Skip to content

Commit ab7946f

Browse files
committed
[IMP] estate: added Inline Views, widgets, list order
-Implemented inline views and widgets to enhance the user interface within the Real Estate module. -Introduced list-ordering functionality to improve the organization and sorting of listings. -Added attribute and option configurations to increase customization capabilities and overall flexibility for users.
1 parent 7a6c138 commit ab7946f

9 files changed

+97
-30
lines changed

Estate/models/estate_property.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
class EstateProperty(models.Model):
77
_name = "estate.property"
88
_description = "Real Estate Property"
9-
9+
_order = "id desc"
10+
1011
name = fields.Char(required=True)
1112
description = fields.Text()
1213
postcode = fields.Char()
@@ -106,12 +107,12 @@ def action_back_to_new(self):
106107
for record in self:
107108
record.state = "new"
108109

109-
@api.constrains("selling_price","expected_price")
110+
@api.constrains("selling_price", "expected_price")
110111
def _check_selling_price_ratio(self):
111112
for record in self:
112113
if record.selling_price <= 0:
113114
raise ValidationError("Selling price must be greater than or equal to 0")
114-
if record.selling_price < 0.9 * record.expected_price:
115+
if record.selling_price < 0.9 * record.expected_price:
115116
raise ValidationError("Selling price must be at least 90% of the expected price")
116117
if record.expected_price < 0:
117118
raise ValidationError("Expected price must be greater than 0")
@@ -125,3 +126,5 @@ def _check_selling_price_ratio(self):
125126
'CHECK(selling_price < 0)',
126127
'The selling price of a property must be positive.'
127128
)
129+
130+
property_type_id = fields.Many2one("estate.property.type", string="Property Type")

Estate/models/estate_property_offer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class EstatePropertyOffer(models.Model):
66
_name = "estate.property.offer"
77
_description = "Real Estate Property Offer"
8+
_order = "price desc"
89
price = fields.Float(required=True)
910
status = fields.Selection(
1011
[
@@ -24,13 +25,9 @@ def action_accept_offer(self):
2425
def action_refuse_offer(self):
2526
for record in self:
2627
record.status = 'refused'
28+
2729
@api.constrains("price")
2830
def _check_price_ratio(self):
2931
for record in self:
3032
if record.price <= 0.0:
3133
raise ValidationError("Price must be greater than 0")
32-
33-
_check_price = models.Constraint(
34-
'CHECK(price < 0)',
35-
'The price must be strictly positive.'
36-
)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
2+
from odoo.exceptions import ValidationError
23

34

45
class EstatePropertyTag(models.Model):
56
_name = "estate.property.tag"
67
_description = "Real Estate Property Tag"
8+
_order = "name desc"
9+
color = fields.Integer( string='Color Index', default=3)
710

811
name = fields.Char(required=True)
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
2+
from odoo.exceptions import ValidationError
23

34

45
class EstatePropertyType(models.Model):
56
_name = "estate.property.type"
67
_description = "Real Estate Property Type"
8+
_order="name desc"
79

810
name = fields.Char(required=True)
11+
property_ids = fields.One2many(
12+
"estate.property", "property_type_id", string="Properties")
13+
sequence = fields.Integer('Sequence', default=7)
14+
offer_count = fields.Integer(
15+
string="Number of Offers",
16+
compute="_compute_offer_count"
17+
)
18+
19+
@api.depends('property_ids.offer_ids')
20+
def _compute_offer_count(self):
21+
for property_type in self:
22+
offer_count = 0
23+
for property in property_type.property_ids:
24+
offer_count += len(property.offer_ids)
25+
property_type.offer_count = offer_count
26+
@api.constrains('name')
27+
def _check_type_name_unique(self):
28+
for record in self:
29+
existing_type = self.search([('name', '=', record.name)])
30+
if existing_type:
31+
raise ValidationError(f"The property type name '{record.name}' must be unique.")
32+
33+
_check_type_name_unique_ratio = models.Constraint(
34+
'CHECK(name)',
35+
'The property name must be unique.'
36+
)

Estate/views/estate_menus.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<menuitem id="estate_property_list_menu"
1313
name="List"
1414
parent="estate_property_menu"
15-
action="action_estate_property_list_only"/>
15+
action="action_estate_property"/>
1616

1717
<menuitem id="estate_property_form_menu"
1818
name="Form"

Estate/views/estate_property_offer_views.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<odoo>
2+
23
<record id="estate_property_offer_tree_view" model="ir.ui.view">
34
<field name="name">estate.property.offer.list</field>
45
<field name="model">estate.property.offer</field>
56
<field name="arch" type="xml">
67
<list>
78
<field name="price" />
89
<field name="partner_id" />
9-
<button name="action_accept_offer" string="Accept" type="object" />
10-
<button name="action_refuse_offer" string="Refuse" type="object" />
10+
<button name="action_accept_offer" string="accept" type="object" invisible="status in ['accepted', 'refused']" />
11+
<button name="action_refuse_offer" string="refuse" type="object" invisible="status in ['accepted', 'refused']" />
1112
<field name="status" />
1213
</list>
1314
</field>
@@ -22,9 +23,9 @@
2223
<group>
2324
<field name="price"/>
2425
<field name="partner_id"/>
25-
<button name="action_accept_offer" string="Accept" type="object" />
26-
<button name="action_refuse_offer" string="Refuse" type="object" />
2726
<field name="status"/>
27+
<button name="action_accept_offer" string="accept" type="object" invisible="status in ['accepted', 'refused']" />
28+
<button name="action_refuse_offer" string="refuse" type="object" invisible="status in ['accepted', 'refused']" />
2829
</group>
2930
</sheet>
3031
</form>

Estate/views/estate_property_tags_views.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44
<field name="res_model">estate.property.tag</field>
55
<field name="view_mode">list,form</field>
66
</record>
7-
</odoo>
7+
<record id="view_estate_property_tag_list" model="ir.ui.view">
8+
<field name="name">estate.property.tag.list</field>
9+
<field name="model">estate.property.tag</field>
10+
<field name="arch" type="xml">
11+
<list>
12+
<field name="name"/>
13+
<field name="color" widget="color_picker"/>
14+
</list>
15+
</field>
16+
</record>
17+
</odoo>
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
<odoo>
2-
<record id="estate_property_type_action" model="ir.actions.act_window">
2+
<record id="estate_property_type_action" model="ir.actions.act_window">
33
<field name="name">Property Types</field>
44
<field name="res_model">estate.property.type</field>
55
<field name="view_mode">list,form</field>
66
</record>
7-
</odoo>
7+
<record id="view_estate_property_type_list" model="ir.ui.view">
8+
<field name="name">estate.property.type.list</field>
9+
<field name="model">estate.property.type</field>
10+
<field name="arch" type="xml">
11+
<list>
12+
<field name="name"/>
13+
</list>
14+
</field>
15+
</record>
16+
<record id="view_estate_property_type_form" model="ir.ui.view">
17+
<field name="name">estate.property.type.form</field>
18+
<field name="model">estate.property.type</field>
19+
<field name="arch" type="xml">
20+
<form>
21+
<sheet>
22+
<header>
23+
<field name="offer_count" string="Offers:-" readonly="1"/>
24+
</header>
25+
<group>
26+
<field name="name"/>
27+
<field name="property_ids" widget="one2many_list">
28+
<list>
29+
<field name="name"/>
30+
<field name="expected_price"/>
31+
<field name="selling_price"/>
32+
<field name="state"/>
33+
</list>
34+
</field>
35+
</group>
36+
</sheet>
37+
</form>
38+
</field>
39+
</record>
40+
</odoo>

Estate/views/estate_property_views.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
</field>
2323
</record>
2424

25-
<record id="action_estate_property_list_only" model="ir.actions.act_window">
26-
<field name="name">Properties (List)</field>
27-
<field name="res_model">estate.property</field>
28-
<field name="view_mode">list</field>
29-
<field name="view_id" ref="estate_property_list_view"/>
30-
</record>
31-
32-
3325
<record id="estate_property_form_view" model="ir.ui.view">
3426
<field name="name">estate.property.form</field>
3527
<field name="model">estate.property</field>
@@ -57,8 +49,8 @@
5749
<field name="facades"/>
5850
<field name="garage"/>
5951
<field name="garden"/>
60-
<field name="garden_area"/>
61-
<field name="garden_orientation"/>
52+
<field name="garden_area" invisible="garden == False"/>
53+
<field name="garden_orientation" invisible="garden == False"/>
6254
</group>
6355

6456
<group string="Extra Information">
@@ -85,8 +77,8 @@
8577
<list editable="bottom">
8678
<field name="partner_id"/>
8779
<field name="price"/>
88-
<button name="action_accept_offer" string="Accept" type="object" />
89-
<button name="action_refuse_offer" string="Refuse" type="object" />
80+
<button name="action_accept_offer" string="Accept" type="object"/>
81+
<button name="action_refuse_offer" string="Refuse" type="object"/>
9082
<field name="status"/>
9183
</list>
9284
</field>

0 commit comments

Comments
 (0)