44
55
66class Estate (models .Model ):
7- _name = 'estate.property'
8- _description = 'Estate Property'
7+ _name = "estate.property"
8+ _description = "Estate Property"
9+ _order = "id desc"
910
1011 name = fields .Char ("Property Name" , required = True )
1112 description = fields .Text ("Description" )
@@ -21,11 +22,22 @@ class Estate(models.Model):
2122 garden_area = fields .Integer ("Garden Area (sqm)" )
2223 garden_orientation = fields .Selection (
2324 string = "Garden Orientation" ,
24- selection = [('north' , "North" ), ('south' , "South" ), ('east' , "East" ), ('west' , "West" )],
25+ selection = [
26+ ('north' , "North" ),
27+ ('south' , "South" ),
28+ ('east' , "East" ),
29+ ('west' , "West" )
30+ ],
2531 required = True )
2632 status = fields .Selection (
2733 string = "Status" ,
28- selection = [('new' , "New" ), ('offer_received' , "Offer Received" ), ('offer_accepted' , "Offer Accepted" ), ('sold' , "Sold" ), ('canceled' , "Canceled" )],
34+ selection = [
35+ ('new' , "New" ),
36+ ('offer_received' , "Offer Received" ),
37+ ('offer_accepted' , "Offer Accepted" ),
38+ ('sold' , "Sold" ),
39+ ('canceled' , "Canceled" )
40+ ],
2941 default = 'new' ,
3042 required = True )
3143 active = fields .Boolean ("Active" , default = True )
@@ -34,9 +46,19 @@ class Estate(models.Model):
3446 salesperson_id = fields .Many2one ('res.users' , string = "Salesperson" , default = lambda self : self .env .user )
3547 tag_ids = fields .Many2many ('estate.property.tag' , string = "Tags" )
3648 offer_ids = fields .One2many ('estate.property.offer' , 'property_id' , string = "Offers" )
37- total_area = fields .Integer (' Total Area (sqm)' , compute = '_compute_total_area' )
49+ total_area = fields .Integer (" Total Area (sqm)" , compute = '_compute_total_area' )
3850 best_price = fields .Float ("Best Offer" , compute = '_compute_best_price' )
3951
52+ _check_expected_price = models .Constraint (
53+ "CHECK(expected_price > 0)" ,
54+ "The expected price must be strictly positive"
55+ )
56+
57+ _check_selling_price = models .Constraint (
58+ "CHECK(selling_price >= 0)" ,
59+ "The selling price must be positive"
60+ )
61+
4062 @api .depends ('living_area' , 'garden_area' )
4163 def _compute_total_area (self ):
4264 for record in self :
@@ -52,10 +74,8 @@ def _onchange_property_status(self):
5274 for record in self :
5375 if record .status == 'new' and len (record .offer_ids ) > 0 :
5476 record .status = 'offer_received'
55- else :
56- record .status = record .status
5777
58- @api .onchange (" garden" )
78+ @api .onchange (' garden' )
5979 def _onchange_garden (self ):
6080 if self .garden :
6181 self .garden_area = 10
@@ -66,29 +86,18 @@ def _onchange_garden(self):
6686
6787 def action_mark_sold (self ):
6888 for record in self :
69- if record .status == ' canceled' :
70- raise UserError ("Canceled properties cannot be sold." )
71- record .status = ' sold'
89+ if record .status == " canceled" :
90+ raise UserError (self . env . _ ( "Canceled properties cannot be sold." ) )
91+ record .status = " sold"
7292
7393 def action_mark_cancel (self ):
7494 for record in self :
75- if record .status == 'sold' :
76- raise UserError ("Sold properties cannot be canceled." )
77- record .status = 'canceled'
78-
79- _check_expected_price = models .Constraint (
80- 'CHECK(expected_price > 0)' ,
81- 'The expected price must be strictly positive'
82- )
83-
84- _check_selling_price = models .Constraint (
85- 'CHECK(selling_price >= 0)' ,
86- 'The selling price must be positive'
87- )
95+ if record .status == "sold" :
96+ raise UserError (self .env ._ ("Sold properties cannot be canceled." ))
97+ record .status = "canceled"
8898
8999 @api .constrains ('selling_price' )
90100 def _check_selling_price (self ):
91101 for record in self :
92- if not float_is_zero (record .selling_price , precision_digits = 2 ):
93- if float_compare (record .selling_price , record .expected_price * 0.9 , precision_digits = 2 ) < 0 :
94- raise ValidationError ('The selling price must be atleast 90% of the expected price! You must reduce the expected price to accept the offer' )
102+ if not float_is_zero (record .selling_price , precision_digits = 2 ) and float_compare (record .selling_price , record .expected_price * 0.9 , precision_digits = 2 ) < 0 :
103+ raise ValidationError (self .env ._ ("The selling price must be atleast 90% of the expected price! You must reduce the expected price to accept the offer" ))
0 commit comments