@@ -9,24 +9,19 @@ class EstateProperty(models.Model):
99 _name = "estate.property"
1010 _description = "Real Estate Property"
1111 _order = "id desc"
12-
1312 name = fields .Char (required = True )
1413 description = fields .Text ()
1514 postcode = fields .Char ()
16-
1715 date_availability = fields .Date (
1816 "Availability Date" ,
1917 default = lambda self : fields .Date .today () + relativedelta (months = 3 ),
2018 )
21-
2219 expected_price = fields .Float ("Expected Price" , required = True )
2320 selling_price = fields .Float ("Selling Price" , readonly = True )
24-
2521 bedrooms = fields .Integer (default = 2 )
2622 living_area = fields .Integer ("Living Area(sqft)" )
2723 facades = fields .Integer ()
2824 garage = fields .Boolean ()
29-
3025 garden = fields .Boolean ()
3126 garden_area = fields .Integer ("Garden Area(sqft)" )
3227 garden_orientation = fields .Selection (
@@ -38,7 +33,6 @@ class EstateProperty(models.Model):
3833 ],
3934 string = "Garden Orientation" ,
4035 )
41-
4236 state = fields .Selection (
4337 [
4438 ("new" , "New" ),
@@ -52,21 +46,16 @@ class EstateProperty(models.Model):
5246 copy = False ,
5347 default = "new" ,
5448 )
55-
5649 active = fields .Boolean (default = True )
57-
5850 property_type_id = fields .Many2one ("estate.property.type" , "Property Type" )
5951 buyer_id = fields .Many2one ("res.partner" , "Buyer" , copy = False )
6052 salesperson_id = fields .Many2one ("res.users" , string = "Salesperson" )
61-
6253 tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
63-
6454 offer_ids = fields .One2many (
6555 "estate.property.offer" ,
6656 "property_id" ,
6757 string = "Offers"
6858 )
69-
7059 total_area = fields .Integer ("Total Area(sqm)" , compute = "_compute_total_area" )
7160 best_price = fields .Float ("Best Offer" , compute = "_compute_best_price" )
7261
@@ -75,17 +64,16 @@ class EstateProperty(models.Model):
7564 'The expected price of a property must be strictly positive.' ,
7665 )
7766
78-
7967 @api .depends ("living_area" , "garden_area" )
8068 def _compute_total_area (self ):
8169 for record in self :
8270 record .total_area = (record .living_area or 0 ) + (record .garden_area or 0 )
83-
71+
8472 @api .depends ("offer_ids.price" )
8573 def _compute_best_price (self ):
8674 for record in self :
8775 record .best_price = max (record .offer_ids .mapped ("price" ), default = 0 )
88-
76+
8977 @api .onchange ("garden" )
9078 def _onchange_garden (self ):
9179 if self .garden :
@@ -94,19 +82,17 @@ def _onchange_garden(self):
9482 else :
9583 self .garden_area = 0
9684 self .garden_orientation = False
97-
9885 def action_cancel (self ):
9986 for record in self :
10087 if record .state == "sold" :
10188 raise UserError ("A sold property cannot be cancelled" )
10289 record .state = "cancelled"
103-
10490 def action_sold (self ):
10591 for record in self :
10692 if record .state == "cancelled" :
10793 raise UserError ("A cancelled property cannot be set as sold" )
10894 record .state = "sold"
109-
95+
11096 @api .constrains ("selling_price" , "expected_price" )
11197 def _check_selling_price (self ):
11298 for record in self :
0 commit comments