@@ -25,10 +25,10 @@ class EstateProperty(models.Model):
2525 garden_orientation = fields .Selection (
2626 string = "Garden Orientation" ,
2727 selection = [
28- ('north' , 'North' ),
29- ('south' , 'South' ),
30- ('east' , 'East' ),
31- ('west' , 'West' )
28+ ('north' , 'North' ),
29+ ('south' , 'South' ),
30+ ('east' , 'East' ),
31+ ('west' , 'West' )
3232 ]
3333 )
3434 active = fields .Boolean (default = True )
@@ -40,7 +40,8 @@ class EstateProperty(models.Model):
4040 ('sold' , 'Sold' ),
4141 ('cancelled' , 'Cancelled' )
4242 ],
43- default = "new"
43+ default = "new" ,
44+ readonly = True
4445 )
4546 property_type_id = fields .Many2one ("estate.property.type" )
4647 buyer_id = fields .Many2one ("res.partner" , copy = False )
@@ -50,6 +51,23 @@ class EstateProperty(models.Model):
5051 total_area = fields .Float (compute = "_compute_total_area" )
5152 best_offer = fields .Float (compute = "_compute_best_offer" )
5253
54+ _check_area = models .Constraint (
55+ 'CHECK(garden_area >= 0 AND living_area>=0)' ,
56+ 'Area must be positive'
57+ )
58+
59+ _check_price = models .Constraint (
60+ 'CHECK(selling_price >= 0 AND expected_price>=0)' ,
61+ 'Price must be positive'
62+ )
63+
64+ @api .constrains ('selling_price' , 'expected_price' )
65+ def _check_selling_price (self ):
66+ for record in self :
67+ if not float_is_zero (record .selling_price , precision_digits = 2 ):
68+ if float_compare (record .selling_price , 0.9 * record .expected_price , precision_digits = 2 ) < 0 :
69+ raise ValidationError ("The selling price cannot be lower than 90% of the expected price." )
70+
5371 @api .depends ('living_area' , 'garden_area' )
5472 def _compute_total_area (self ):
5573 for record in self :
@@ -86,20 +104,8 @@ def sold_property(self):
86104 else :
87105 record .state = 'sold'
88106
89- _check_price = models .Constraint (
90- 'CHECK(selling_price >= 0 AND expected_price>=0)' ,
91- 'selling price and expected_price must be positive'
92- )
93-
94- @api .constrains ('selling_price' , 'expected_price' , 'state' )
95- def _check_selling_price (self ):
96- for record in self :
97- if not float_is_zero (record .selling_price , precision_digits = 2 ):
98- if float_compare (record .selling_price , 0.9 * record .expected_price , precision_digits = 2 ) < 0 :
99- raise ValidationError ("the selling price lower" )
100-
101107 @api .ondelete (at_uninstall = True )
102108 def _unlink_check_state_of_property (self ):
103109 for record in self :
104- if record .state in ('offer_received ' , 'offer_accepted' , 'sold ' ):
105- raise UserError ("You cannot delete a new or cancelled property ! " )
110+ if record .state not in ('new ' , 'cancelled ' ):
111+ raise UserError ("only 'New' or 'Cancelled' property can be deleted. " )
0 commit comments