@@ -9,14 +9,6 @@ class EstateProperty(models.Model):
99 _description = "Real estate propreties"
1010 _order = "id desc"
1111
12- _check_expected_price = models .Constraint (
13- 'CHECK(expected_price > 0)' ,
14- 'Expected price must be strictly positive.' ,
15- )
16- _check_selling_price = models .Constraint (
17- 'CHECK(selling_price >= 0)' ,
18- 'Selling price must be positive.' ,
19- )
2012 name = fields .Char (required = True )
2113 description = fields .Text ()
2214 postcode = fields .Char ()
@@ -42,6 +34,15 @@ class EstateProperty(models.Model):
4234 total_area = fields .Float (compute = "_compute_total_area" , readonly = True , copy = False )
4335 best_price = fields .Float (compute = "_get_best_price" , readonly = True , copy = False )
4436
37+ _check_expected_price = models .Constraint (
38+ 'CHECK(expected_price > 0)' ,
39+ 'Expected price must be strictly positive.' ,
40+ )
41+ _check_selling_price = models .Constraint (
42+ 'CHECK(selling_price >= 0)' ,
43+ 'Selling price must be positive.' ,
44+ )
45+
4546 @api .depends ('living_area' , 'garden_area' )
4647 def _compute_total_area (self ):
4748 for record in self :
@@ -55,6 +56,12 @@ def _get_best_price(self):
5556 else :
5657 record .best_price = 0
5758
59+ @api .constrains ('selling_price' , 'expected_price' )
60+ def _check_selling_price (self ):
61+ self .ensure_one ()
62+ if self .buyer_id and float_compare (self .expected_price , 0.9 * self .selling_price , 0 ) > 0 :
63+ raise ValidationError ("The selling price cannot be lower than 90% of the expected price." )
64+
5865 @api .onchange ('garden' )
5966 def _onchange_garden (self ):
6067 self .ensure_one ()
@@ -65,6 +72,11 @@ def _onchange_garden(self):
6572 self .garden_area = 0
6673 self .garden_orientation = None
6774
75+ @api .ondelete (at_uninstall = False )
76+ def _unlink_if_not_new_or_cancelled (self ):
77+ if any (record .state in ['new' , 'cancelled' ] for record in self ):
78+ raise UserError ("Can't delete a property which has a state of new or cancelled!" )
79+
6880 def action_set_sold (self ):
6981 self .ensure_one ()
7082 if self .state == 'cancelled' :
@@ -78,14 +90,3 @@ def action_set_cancelled(self):
7890 raise UserError ("Sold property cannot be cancelled" )
7991 self .state = 'cancelled'
8092 return 1
81-
82- @api .constrains ('selling_price' , 'expected_price' )
83- def _check_selling_price (self ):
84- self .ensure_one ()
85- if self .buyer_id and float_compare (self .expected_price , 0.9 * self .selling_price , 0 ) > 0 :
86- raise ValidationError ("The selling price cannot be lower than 90% of the expected price." )
87-
88- @api .ondelete (at_uninstall = False )
89- def _unlink_if_not_new_or_cancelled (self ):
90- if any (record .state in ['new' , 'cancelled' ] for record in self ):
91- raise UserError ("Can't delete a property which has a state of new or cancelled!" )
0 commit comments