@@ -5,13 +5,6 @@ class EstateProperty(models.Model):
55 _name = 'estate.property'
66 _description = 'Estate properties'
77 _order = 'id desc'
8- _check_name = models .Constraint ('UNIQUE(name)' , 'Property name must be unique' )
9- _check_expected_price = models .Constraint ('CHECK(expected_price > 0)' , 'Expected price must be positive' )
10- _check_selling_price = models .Constraint ('CHECK(selling_price >= 0)' , 'Selling price cannot be negative' )
11- _check_bedrooms = models .Constraint ('CHECK(bedrooms >= 0)' , 'Bedrooms cannot be negative' )
12- _check_living_area = models .Constraint ('CHECK(living_area >= 0)' , 'Living area cannot be negative' )
13- _check_facades = models .Constraint ('CHECK(facades >= 0)' , 'Facades cannot be negative' )
14- _check_garden_area = models .Constraint ('CHECK(garden_area >= 0)' , 'Garden area cannot be negative' )
158
169 name = fields .Char ('Name' , required = True )
1710 description = fields .Char ('Description' )
@@ -43,11 +36,13 @@ class EstateProperty(models.Model):
4336 total_area = fields .Integer ('Total Area' , compute = '_compute_total_area' )
4437 best_price = fields .Float ('Best Offer' , compute = '_compute_best_price' )
4538
46- @api .constrains ('selling_price' )
47- def _check_selling_price_within_range (self ):
48- for record in self :
49- if not tools .float_utils .float_is_zero (record .selling_price , 2 ) and record .selling_price < 0.9 * record .expected_price :
50- raise exceptions .ValidationError ('Selling price cannot be lower than 90% of the expected price' )
39+ _check_name = models .Constraint ('UNIQUE(name)' , 'Property name must be unique' )
40+ _check_expected_price = models .Constraint ('CHECK(expected_price > 0)' , 'Expected price must be positive' )
41+ _check_selling_price = models .Constraint ('CHECK(selling_price >= 0)' , 'Selling price cannot be negative' )
42+ _check_bedrooms = models .Constraint ('CHECK(bedrooms >= 0)' , 'Bedrooms cannot be negative' )
43+ _check_living_area = models .Constraint ('CHECK(living_area >= 0)' , 'Living area cannot be negative' )
44+ _check_facades = models .Constraint ('CHECK(facades >= 0)' , 'Facades cannot be negative' )
45+ _check_garden_area = models .Constraint ('CHECK(garden_area >= 0)' , 'Garden area cannot be negative' )
5146
5247 @api .depends ('garden_area' , 'living_area' )
5348 def _compute_total_area (self ):
@@ -65,6 +60,12 @@ def _onchange_garden(self):
6560 record .garden_area = (10 if record .garden else 0 )
6661 record .garden_orientation = ('north' if record .garden else None )
6762
63+ @api .constrains ('selling_price' )
64+ def _check_selling_price (self ):
65+ for record in self :
66+ if not tools .float_utils .float_is_zero (record .selling_price , 2 ) and record .selling_price < 0.9 * record .expected_price :
67+ raise exceptions .ValidationError ('Selling price cannot be lower than 90% of the expected price' )
68+
6869 @api .ondelete (at_uninstall = False )
6970 def _property_delete (self ):
7071 if self .state != 'new' and self .state != 'cancelled' :
0 commit comments