Skip to content

Commit a7acb9e

Browse files
committed
[IMP] estate: align views and models with coding guidelines
- Renamed XML ids and view names to follow naming conventions - Reordered model field attributes according to the defined guidelines
1 parent 668311e commit a7acb9e

8 files changed

+73
-77
lines changed

estate/models/estate_property.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
class EstateProperty(models.Model):
88
_name = "estate.property"
99
_description = "Estate Property"
10+
_sql_constraints = [
11+
(
12+
"check_expected_price",
13+
"CHECK(expected_price > 0)",
14+
"The expected price must be greater than 0.",
15+
),
16+
]
1017
_order = "id desc"
1118

1219
name = fields.Char(string="Name", required=True)
@@ -77,22 +84,6 @@ class EstateProperty(models.Model):
7784
compute="_compute_best_price",
7885
)
7986

80-
_sql_constraints = [
81-
(
82-
"check_expected_price",
83-
"CHECK(expected_price > 0)",
84-
"The expected price must be greater than 0.",
85-
),
86-
]
87-
88-
@api.ondelete(at_uninstall=False)
89-
def _unlink_check(self):
90-
for property in self:
91-
if property.state not in ["new", "cancelled"]:
92-
raise UserError(
93-
"You cannot delete a property that is not new or cancelled."
94-
)
95-
9687
@api.depends("living_area", "garden_area", "garden")
9788
def _compute_total_area(self):
9889
for property in self:
@@ -105,6 +96,24 @@ def _compute_best_price(self):
10596
for property in self:
10697
property.best_price = max(property.offer_ids.mapped("price"), default=0.0)
10798

99+
@api.constrains("selling_price", "expected_price")
100+
def _check_selling_price(self):
101+
for property in self:
102+
if float_is_zero(property.selling_price, precision_rounding=2):
103+
continue
104+
105+
if (
106+
float_compare(
107+
property.selling_price,
108+
property.expected_price * 0.9,
109+
precision_rounding=2,
110+
)
111+
< 0
112+
):
113+
raise ValidationError(
114+
"The selling price cannot be lower than 90'%' of the expected price!"
115+
)
116+
108117
@api.onchange("garden")
109118
def _onchange_garden(self):
110119
for property in self:
@@ -115,6 +124,14 @@ def _onchange_garden(self):
115124
property.garden_area = 0
116125
property.garden_orientation = False
117126

127+
@api.ondelete(at_uninstall=False)
128+
def _unlink_check(self):
129+
for property in self:
130+
if property.state not in ["new", "cancelled"]:
131+
raise UserError(
132+
"You cannot delete a property that is not new or cancelled."
133+
)
134+
118135
def action_set_sold(self):
119136
for property in self:
120137
if property.selling_price > 0.0 and property.state != "cancelled":
@@ -136,21 +153,3 @@ def action_set_cancelled(self):
136153
raise UserError("This property is already cancelled.")
137154
elif property.state == "sold":
138155
raise UserError("A sold property cannot be cancelled.")
139-
140-
@api.constrains("selling_price", "expected_price")
141-
def _check_selling_price(self):
142-
for property in self:
143-
if float_is_zero(property.selling_price, precision_rounding=2):
144-
continue
145-
146-
if (
147-
float_compare(
148-
property.selling_price,
149-
property.expected_price * 0.9,
150-
precision_rounding=2,
151-
)
152-
< 0
153-
):
154-
raise ValidationError(
155-
"The selling price cannot be lower than 90'%' of the expected price!"
156-
)

estate/models/estate_property_offer.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Estate Property Offer"
9+
_sql_constraints = [
10+
("check_price", "CHECK(price > 0)", "The price must be greater than 0."),
11+
]
912
_order = "price desc"
1013

1114
price = fields.Float(string="Price")
@@ -36,23 +39,6 @@ class EstatePropertyOffer(models.Model):
3639
store=True,
3740
)
3841

39-
_sql_constraints = [
40-
("check_price", "CHECK(price > 0)", "The price must be greater than 0."),
41-
]
42-
43-
@api.model_create_multi
44-
def create(self, vals_list):
45-
for record in vals_list:
46-
property = self.env["estate.property"].browse(record["property_id"])
47-
48-
if record.get("price") < property.best_price:
49-
raise UserError(
50-
"You cannot create an offer lower than an existing one."
51-
)
52-
53-
property.state = "offer received"
54-
return super().create(vals_list)
55-
5642
@api.depends("validity")
5743
def _compute_date_deadline(self):
5844
for offer in self:
@@ -75,6 +61,19 @@ def _inverse_date_deadline(self):
7561
else:
7662
offer.validity = 0
7763

64+
@api.model_create_multi
65+
def create(self, vals_list):
66+
for record in vals_list:
67+
property = self.env["estate.property"].browse(record["property_id"])
68+
69+
if record.get("price") < property.best_price:
70+
raise UserError(
71+
"You cannot create an offer lower than an existing one."
72+
)
73+
74+
property.state = "offer received"
75+
return super().create(vals_list)
76+
7877
def action_set_accepted(self):
7978
for offer in self:
8079
if offer.property_id.selling_price == 0.0:

estate/models/estate_property_tag.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag"
7+
_sql_constraints = [
8+
("unique_name", "UNIQUE(name)", "A tag with same name is already exists."),
9+
]
710
_order = "name asc"
811

912
name = fields.Char(string="Tag Name", required=True)
1013
description = fields.Text(string="Description")
1114
color = fields.Integer(string="Color")
12-
13-
_sql_constraints = [
14-
("unique_name", "UNIQUE(name)", "A tag with same name is already exists."),
15-
]

estate/models/estate_property_type.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Estate Property Type"
7+
_sql_constraints = [
8+
("unique_name", "UNIQUE(name)", "A type with same name is already exists."),
9+
]
710
_order = "sequence,name"
811

912
name = fields.Char(required=True)
@@ -16,13 +19,8 @@ class EstatePropertyType(models.Model):
1619
sequence = fields.Integer(
1720
"Sequence", default=1, help="Used to order types. Lower is better."
1821
)
19-
2022
offer_count = fields.Integer("Offers", compute="_compute_offer_count")
2123

22-
_sql_constraints = [
23-
("unique_name", "UNIQUE(name)", "A type with same name is already exists."),
24-
]
25-
2624
@api.depends("offer_ids")
2725
def _compute_offer_count(self):
2826
for record in self:

estate/views/estate_property_offer_views.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
<field name="domain">[('property_type_id', '=', active_id)]</field>
99
</record>
1010

11-
<record id="estate_property_offer_view" model="ir.ui.view">
12-
<field name="name">estate.property.offer.list</field>
11+
<!-- list view -->
12+
<record id="estate_property_offer_view_list" model="ir.ui.view">
13+
<field name="name">estate.property.offer.view.list</field>
1314
<field name="model">estate.property.offer</field>
1415
<field name="arch" type="xml">
1516
<list editable="bottom" decoration-success="status == 'accepted'" decoration-danger="status == 'refused'">
@@ -26,8 +27,9 @@
2627
</field>
2728
</record>
2829

29-
<record id="estate_property_offer_form" model="ir.ui.view">
30-
<field name="name">estate.property.offer.form</field>
30+
<!-- form view -->
31+
<record id="estate_property_offer_view_form" model="ir.ui.view">
32+
<field name="name">estate.property.offer.view.form</field>
3133
<field name="model">estate.property.offer</field>
3234
<field name="arch" type="xml">
3335
<form>

estate/views/estate_property_tag_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<!-- list view -->
1616
<record id="estate_property_tag_view_list" model="ir.ui.view">
17-
<field name="name">estate.property.tag.list</field>
17+
<field name="name">estate.property.tag.view.list</field>
1818
<field name="model">estate.property.tag</field>
1919
<field name="arch" type="xml">
2020
<list string="Property Types" editable="bottom">
@@ -26,7 +26,7 @@
2626

2727
<!-- form view -->
2828
<record id="estate_property_tag_view_form" model="ir.ui.view">
29-
<field name="name">estate.property.tag.form</field>
29+
<field name="name">estate.property.tag.view.form</field>
3030
<field name="model">estate.property.tag</field>
3131
<field name="arch" type="xml">
3232
<form string="Property Tag">

estate/views/estate_property_type_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<!-- list view -->
1616
<record id="estate_property_type_view_list" model="ir.ui.view">
17-
<field name="name">estate.property.type.list</field>
17+
<field name="name">estate.property.type.view.list</field>
1818
<field name="model">estate.property.type</field>
1919
<field name="arch" type="xml">
2020
<list string="Property Types">
@@ -26,7 +26,7 @@
2626

2727
<!-- form view -->
2828
<record id="estate_property_type_view_form" model="ir.ui.view">
29-
<field name="name">estate.property.type.form</field>
29+
<field name="name">estate.property.type.view.form</field>
3030
<field name="model">estate.property.type</field>
3131
<field name="arch" type="xml">
3232
<form string="Property Type">

estate/views/estate_property_views.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</record>
1515

1616
<!-- list view -->
17-
<record id="estate_property_view" model="ir.ui.view">
18-
<field name="name">estate.property.list</field>
17+
<record id="estate_property_view_list" model="ir.ui.view">
18+
<field name="name">estate.property.view.list</field>
1919
<field name="model">estate.property</field>
2020
<field name="arch" type="xml">
2121
<list string="estate_property_view" decoration-success="state in ['offer received','offer accepted']"
@@ -34,8 +34,8 @@
3434
</record>
3535

3636
<!-- form view -->
37-
<record id="estate_property_form" model="ir.ui.view">
38-
<field name="name">estate.property.form</field>
37+
<record id="estate_property_view_form" model="ir.ui.view">
38+
<field name="name">estate.property.view.form</field>
3939
<field name="model">estate.property</field>
4040
<field name="arch" type="xml">
4141
<form string="estate_property_form">
@@ -96,8 +96,8 @@
9696
</record>
9797

9898
<!-- search view-->
99-
<record id="estate_property_search" model="ir.ui.view">
100-
<field name="name">estate.property.search</field>
99+
<record id="estate_property_view_search" model="ir.ui.view">
100+
<field name="name">estate.property.view.search</field>
101101
<field name="model">estate.property</field>
102102
<field name="arch" type="xml">
103103
<search string="estate_property_search">
@@ -119,8 +119,8 @@
119119
</record>
120120

121121
<!-- kanban view -->
122-
<record id="estate_property_kanban_view" model="ir.ui.view">
123-
<field name="name">estate.property.kanban</field>
122+
<record id="estate_property_view_kanban" model="ir.ui.view">
123+
<field name="name">estate.property.view.kanban</field>
124124
<field name="model">estate.property</field>
125125
<field name="arch" type="xml">
126126
<kanban default_group_by="property_type_id" records_draggable="False" group_create="False">
@@ -157,4 +157,3 @@
157157
</field>
158158
</record>
159159
</odoo>
160-

0 commit comments

Comments
 (0)