Skip to content

Commit 84e43df

Browse files
committed
[IMP] estate: add constraints for property offers, tags, and types to ensure data integrity
1 parent b0836be commit 84e43df

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

estate/models/estate_property.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class EstateProperty(models.Model):
5858
total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area')
5959
best_price = fields.Float('Best Offer', compute='_compute_best_price')
6060

61+
_check_expected_price = models.Constraint(
62+
'CHECK(expected_price > 0)', 'The expected price must be strictly positive.'
63+
)
64+
_check_selling_price = models.Constraint(
65+
'CHECK(selling_price >= 0)', 'The selling price must be positive.'
66+
)
67+
6168
@api.depends('garden_area', 'living_area')
6269
def _compute_total_area(self):
6370
for property in self:

estate/models/estate_property_offer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ class EstatePropertyOffer(models.Model):
1717
copy=False,
1818
)
1919
partner_id = fields.Many2one('res.partner', string='Partner', required=True)
20-
property_id = fields.Many2one('estate.property', string='Property', required=True)
20+
property_id = fields.Many2one(
21+
'estate.property', string='Property', required=True, ondelete='cascade'
22+
)
2123
validity = fields.Integer('Validity (days)', default=7)
2224
date_deadline = fields.Date(
2325
'Deadline', compute='_compute_date_deadline', inverse='_inverse_date_deadline'
2426
)
2527

28+
_check_price = models.Constraint(
29+
'CHECK(price > 0)', 'The price must be strictly positive.'
30+
)
31+
2632
@api.depends('validity')
2733
def _compute_date_deadline(self):
2834
for offer in self:

estate/models/estate_property_tag.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ class EstatePropertyTag(models.Model):
66
_description = "Property Tag"
77

88
name = fields.Char('Tag', required=True)
9+
10+
_name_uniq = models.Constraint(
11+
'unique(name)', 'A tag with the same name already exists.'
12+
)

estate/models/estate_property_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ class EstatePropertyType(models.Model):
66
_description = "Property Type"
77

88
name = fields.Char('Type', required=True)
9+
10+
_name_uniq = models.Constraint(
11+
'unique(name)', 'A type with the same name already exists.'
12+
)

0 commit comments

Comments
 (0)