Skip to content

Commit 19b9db7

Browse files
committed
[IMP] estate: Chapter 10
1 parent 42d5841 commit 19b9db7

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

estate/models/estate_properties.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from odoo import api, fields, models
2-
from odoo.exceptions import UserError
2+
from odoo.exceptions import UserError, ValidationError
3+
from odoo.tools import float_compare
34

45
DEFAULT_GARDEN_AREA = 10
56
DEFAULT_GARDEN_ORIENTATION = "north"
@@ -8,6 +9,14 @@
89
class PropertyModel(models.Model):
910
_name = "estate.property"
1011
_description = "Estate Property model"
12+
_check_positive_expected_price = models.Constraint(
13+
"CHECK(expected_price >= 0)",
14+
"The expected price must be positive."
15+
)
16+
_check_positive_selling_price = models.Constraint(
17+
"CHECK(selling_price >= 0)",
18+
"The selling price must be positive"
19+
)
1120

1221
name = fields.Char(required=True)
1322
description = fields.Text()
@@ -79,3 +88,9 @@ def mark_as_cancelled(self):
7988
raise UserError("A sold property cannot be set as cancelled.")
8089
record.state = "cancelled"
8190
return True
91+
92+
@api.constrains("selling_price", "expected_price")
93+
def _check_selling_price(self):
94+
for record in self:
95+
if record.selling_price and float_compare(record.selling_price, record.expected_price * .9, 0) == -1:
96+
raise ValidationError(r"The selling price cannot be lower than 90% of the expected price.")

estate/models/estate_property_offers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ class PropertyOfferModel(models.Model):
1717
property_id = fields.Many2one("estate.property", required=True)
1818
validity = fields.Integer(default=7)
1919
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_deadline")
20+
_check_price = models.Constraint(
21+
"CHECK(price >= 0)",
22+
"The price of the offer must be positive."
23+
)
2024

2125
@api.depends("validity")
2226
def _compute_deadline(self):
2327
for record in self:
24-
record.date_deadline = fields.Date.add(record.create_date, days=record.validity) if record.create_date else None
28+
record.date_deadline = fields.Date.add((record.create_date or fields.Datetime.now()), days=record.validity)
2529

2630
def _inverse_deadline(self):
2731
for record in self:

estate/models/estate_property_tags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
class PropertyTagModel(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag model"
7+
_check_tag_uniqueness = models.Constraint(
8+
"UNIQUE(name)",
9+
"Each tag should have a unique name."
10+
)
711

812
name = fields.Char(required=True)

estate/models/estate_property_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
class PropertyTypeModel(models.Model):
55
_name = "estate.property.type"
66
_description = "Estate Property Type model"
7+
_check_type_uniqueness = models.Constraint(
8+
"UNIQUE(name)",
9+
"Each type should have a unique name."
10+
)
711

812
name = fields.Char(required=True)

estate/views/estate_property_offer_views.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
<field name="arch" type="xml">
2222
<form string="Property Offer">
2323
<sheet>
24-
<h1>
25-
<field name="property_id"/>
26-
</h1>
2724
<group>
2825
<field name="price"/>
2926
<field name="partner_id"/>

estate/views/estate_property_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<field name="bedrooms"/>
9191
<field name="living_area"/>
9292
<field name="facades"/>
93-
<filter name="State" domain="['|', ('state', '=', 'new'), ('state', '=', 'received')]"/>
93+
<filter name="State" domain="[('state', 'in', ('new', 'received'))]"/>
9494
<filter name="postcode" context="{'group_by': 'postcode'}"/>
9595
</search>
9696
</field>

0 commit comments

Comments
 (0)