Skip to content

Commit d90aff1

Browse files
committed
[IMP] estate: added sql constraints and python constraints, fixed offer view
1 parent a29276d commit d90aff1

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

estate/models/estate_property.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/env python3
22
from dateutil.relativedelta import relativedelta
3+
from odoo.exceptions import ValidationError
34

45
from odoo import api, models, fields, exceptions
56

67

78
class EstateProperty(models.Model):
89
_name = "estate.property"
910
_description = "Estate Property"
11+
_check_expected_price = models.Constraint(
12+
"CHECK(expected_price > 0)", "A property expected price must be strictly positive."
13+
)
14+
_check_selling_price = models.Constraint(
15+
"CHECK(selling_price >= 0)", "A property selling price must be positive."
16+
)
1017

1118
name = fields.Char(required=True, default="Unknown")
1219
description = fields.Text()
@@ -76,6 +83,7 @@ def _onchange_garden(self):
7683
self.garden_orientation = "north"
7784
else:
7885
self.garden_area = 0
86+
self.garden_orientation = None
7987

8088
def action_sold_property(self):
8189
for record in self:
@@ -92,3 +100,16 @@ def action_cancel_offer(self):
92100
else:
93101
record.state = "cancelled"
94102
return True
103+
104+
@api.constrains("selling_price", "expected_price")
105+
def _check_selling_price_persentage(self):
106+
for record in self:
107+
selling_price_persentage = (
108+
record.selling_price / record.expected_price
109+
) * 100
110+
if selling_price_persentage >= 90 or selling_price_persentage == 0:
111+
pass
112+
else:
113+
raise ValidationError(
114+
"The selling price cannot be lower than 90% of the expected price."
115+
)

estate/models/estate_property_offer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Estate Property Offer"
9-
9+
_check_offer_price = models.Constraint(
10+
"CHECK(price > 0)", "An offer price must be strictly positive"
11+
)
12+
1013
price = fields.Float()
1114
status = fields.Selection(
1215
selection=[("accepted", "Accepted"), ("refused", "Refused")], copy=False

estate/models/estate_property_tag.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
class EstatePropertyTags(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag"
7+
_check_tag_name = models.Constraint(
8+
"UNIQUE(name)", "A property tag name should be unique."
9+
)
710

811
name = fields.Char(required=True)

estate/models/estate_property_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
class EstatePropertyType(models.Model):
66
_name = "estate.property.type"
77
_description = "Estate Property Type"
8+
_check_type_name = models.Constraint(
9+
"UNIQUE(name)", "A property type name should be unique."
10+
)
811

912
name = fields.Char(required=True)

estate/views/estate_property_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
<field name="partner_id"/>
119119
<field name="validity" string="Validity(days)"/>
120120
<field name="date_deadline"/>
121-
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
122-
<button name="action_refuse" string="Refuse" type="object" icon="fa-times"/>
121+
<button name="action_accept" string="Accept" type="object" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
122+
<button name="action_refuse" string="Refuse" type="object" icon="fa-times" invisible="status in ('accepted', 'refused')"/>
123123
<field name="status"/>
124124
</list>
125125
</field>

0 commit comments

Comments
 (0)