66
77
88class EstateProperty (models .Model ):
9- _name = " estate.property"
9+ _name = ' estate.property'
1010 _description = "estate property"
1111
1212 name = fields .Char (required = True , string = "Title" )
1313 description = fields .Text ()
1414 postcode = fields .Char ()
15- date_availability = fields .Date (
16- default = lambda self : fields .Date .add (fields .Date .today (), months = 3 ), copy = False
17- )
15+ date_availability = fields .Date (default = lambda self : fields .Date .add (fields .Date .today (), months = 3 ), copy = False )
1816 expected_price = fields .Float (required = True )
1917 selling_price = fields .Float (readonly = True , copy = False )
2018 bedrooms = fields .Integer (default = 2 )
@@ -23,17 +21,15 @@ class EstateProperty(models.Model):
2321 garage = fields .Boolean ()
2422 garden = fields .Boolean ()
2523 garden_area = fields .Integer ()
26- garden_orientation = fields .Selection (
27- [('north' , "North" ), ('south' , "South" ), ('east' , "East" ), ('west' , "West" )]
28- )
24+ garden_orientation = fields .Selection ([('north' , "North" ), ('south' , "South" ), ('east' , "East" ), ('west' , "West" )])
2925 total_area = fields .Integer (compute = '_compute_total_area' )
30- property_type_id = fields .Many2one ('estate.property.type' , string = "House Type" )
31- buyer_id = fields .Many2one ('res.partner' , string = "Buyer" , copy = False )
32- seller_id = fields .Many2one ('res.users' , string = "Seller" , default = lambda self : self .env .user )
33- tag_ids = fields .Many2many ('estate.property.tag' , string = "Tags" )
34- offer_ids = fields .One2many ('estate.property.offer' , 'property_id' , string = "" )
26+ property_type_id = fields .Many2one (comodel_name = 'estate.property.type' , string = "House Type" )
27+ buyer_id = fields .Many2one (comodel_name = 'res.partner' , string = "Buyer" , copy = False )
28+ seller_id = fields .Many2one (comodel_name = 'res.users' , string = "Seller" , default = lambda self : self .env .user )
29+ tag_ids = fields .Many2many (comodel_name = 'estate.property.tag' , string = "Tags" )
30+ offer_ids = fields .One2many (comodel_name = 'estate.property.offer' , inverse_name = 'property_id' , string = "" )
3531 best_offer = fields .Float (compute = '_compute_best_offer' )
36- active = fields .Boolean ("Active" , default = True )
32+ active = fields .Boolean (string = "Active" , default = True )
3733 state = fields .Selection (
3834 string = "Status" ,
3935 selection = [
@@ -48,50 +44,51 @@ class EstateProperty(models.Model):
4844 copy = False ,
4945 )
5046
51- _check_expected_price = models .Constraint (
52- 'CHECK(expected_price > 0)' , "The expected price must be stricly positive"
53- )
47+ _check_expected_price = models .Constraint ('CHECK(expected_price > 0)' , "The expected price must be stricly positive" )
5448
5549 _check_selling_price = models .Constraint ('CHECK(selling_price > 0)' , "The selling price must be stricly positive" )
5650
5751 @api .depends ('living_area' , 'garden_area' )
5852 def _compute_total_area (self ):
59- for record in self :
60- record .total_area = record .living_area + record .garden_area
53+ for record_property in self :
54+ record_property .total_area = record_property .living_area + record_property .garden_area
6155
6256 @api .depends ('offer_ids.price' )
6357 def _compute_best_offer (self ):
64- for record in self :
65- record .best_offer = max (record .offer_ids .mapped ('price' ), default = 0 )
58+ for record_property in self :
59+ record_property .best_offer = max (record_property .offer_ids .mapped ('price' ), default = 0 )
6660
6761 @api .onchange ('garden' )
6862 def _onchange_garden (self ):
69- self .garden_area = 10 if self .garden else 0
70- self .garden_orientation = 'north' if self .garden else ''
63+ if self .garden :
64+ self .garden_area = 10
65+ self .garden_orientation = 'north'
66+ else :
67+ self .garden_area = 0
68+ self .garden_orientation = ''
7169
7270 @api .constrains ('selling_price' , 'expected_price' )
7371 def _check_selling_expected_price (self ):
74- for record in self :
75- if not float_is_zero (record .selling_price , precision_digits = 2 ) and (
76- float_compare ( record .expected_price * 0.9 , record .selling_price , precision_digits = 2 , ) > 0 ):
72+ for record_property in self :
73+ if not float_is_zero (record_property .selling_price , precision_digits = 2 ) and (
74+ float_compare (record_property .expected_price * 0.9 , record_property .selling_price , precision_digits = 2 ) > 0 ):
7775 raise UserError (self .env ._ ("The selling price must be a least 90% of the expected price!" ))
7876
7977 def action_cancel (self ):
80- for record in self :
81- if record .state == 'sold' :
82- raise UserError (self .env ._ ("Sold properties cannot be cancelled" ))
83- record .state = 'cancelled'
78+ for record_property in self :
79+ if record_property .state == 'sold' :
80+ raise UserError (record_property .env ._ ("Sold properties cannot be cancelled" ))
81+ record_property .state = 'cancelled'
8482 return True
8583
8684 def action_sold (self ):
87- for record in self :
88- if record .state == 'cancelled' :
89- raise UserError (self .env_ ("Canceled properties cannot be sold" ))
90- record .state = 'sold'
85+ for record_property in self :
86+ if record_property .state == 'cancelled' :
87+ raise UserError (record_property .env_ ("Canceled properties cannot be sold" ))
88+ record_property .state = 'sold'
9189 return True
9290
9391 @api .ondelete (at_uninstall = False )
9492 def _ondelete (self ):
95- if not any ((property_id .state in ('new' , 'cancelled' )) for property_id in self ):
93+ if any ((property_id .state not in ('new' , 'cancelled' )) for property_id in self ):
9694 raise UserError (self .env ._ ("You can only delete property in the state New or Cancelled" ))
97-
0 commit comments