Skip to content

Commit 556708c

Browse files
committed
[IMP] estate: Added constraint on estate property and tag and type
1 parent d9e8d79 commit 556708c

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

estate/models/estate_property.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class EstateProperty(models.Model):
4141
tag_ids = fields.Many2many("estate.property.tag", string="tag")
4242
offer_ids = fields.One2many("estate.property.offer", "property_id", string="offer")
4343

44+
_check_expected_price = models.Constraint(
45+
'CHECK(expected_price > 0)',
46+
'The expected_price of any property must be strictly positive.',
47+
)
48+
4449
@api.depends('living_area', 'garden_area')
4550
def _compute_area(self):
4651
for property in self:

estate/models/estate_property_offer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from odoo import api, fields, models
22
from datetime import date
33
from dateutil.relativedelta import relativedelta
4-
from odoo.exceptions import UserError
4+
from odoo.exceptions import UserError, ValidationError
5+
from odoo.tools.float_utils import float_compare, float_is_zero, float_round
56

67

78
class EstatePropertyOffer(models.Model):
@@ -45,3 +46,11 @@ def action_accept(self):
4546
def action_refuse(self):
4647
self.status = 'Refused'
4748
return True
49+
50+
@api.constrains('price')
51+
def _check_price_validity(self):
52+
if (float_is_zero(self.price,0)):
53+
raise ValidationError("Offered price must be at least a euro")
54+
min_amount = self.property_id.expected_price * 0.9
55+
if (float_compare(self.price,min_amount,2) < 0):
56+
raise ValidationError("Offered price must be at least 90% of the expected price")

estate/models/estate_property_tag.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ class EstatePropertyTag(models.Model):
66
_description = "property tags"
77

88
name = fields.Char(required=True)
9+
10+
_unique_name = models.Constraint(
11+
'unique(name)',
12+
'A tag must have a unique name.',
13+
)

estate/models/estate_property_type.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ class EstatePropertyType(models.Model):
66
_description = "property types"
77

88
name = fields.Char(required=True)
9+
10+
_unique_name = models.Constraint(
11+
'unique(name)',
12+
'A property type must have a unique name.',
13+
)

0 commit comments

Comments
 (0)