1
- from odoo import fields , models
1
+ from odoo import api , fields , models
2
2
3
3
4
4
class EstateProperty (models .Model ):
@@ -8,8 +8,8 @@ class EstateProperty(models.Model):
8
8
name = fields .Char (required = True )
9
9
description = fields .Text ()
10
10
postcode = fields .Char ()
11
- date_availability = fields .Date ("Available from" , default = lambda _ : fields . Date (). add ( fields . Date (). today (), months = 3 ),
12
- copy = False )
11
+ date_availability = fields .Date ("Available from" ,
12
+ default = lambda _ : fields . Date (). add ( fields . Date (). today (), months = 3 ), copy = False )
13
13
expected_price = fields .Float (required = True )
14
14
selling_price = fields .Float (readonly = True , copy = False )
15
15
bedrooms = fields .Integer (default = 2 )
@@ -19,8 +19,8 @@ class EstateProperty(models.Model):
19
19
garden = fields .Boolean ()
20
20
garden_area = fields .Integer ("Garden Area (sqm)" )
21
21
garden_orientation = fields .Selection (string = "Garden Orientation" ,
22
- selection = [("north" , "North" ), ("south" , "South" ), ( "east" , "East" ),
23
- ("west" , "West" )])
22
+ selection = [("north" , "North" ), ("south" , "South" ),
23
+ ("east" , "East" ), ( " west" , "West" )])
24
24
active = fields .Boolean ("Active" , default = True )
25
25
state = fields .Selection (string = "State" , default = "new" , copy = False , required = True ,
26
26
selection = [("new" , "New" ), ("offer received" , "Offer Received" ),
@@ -31,3 +31,24 @@ class EstateProperty(models.Model):
31
31
salesperson_id = fields .Many2one ("res.users" , string = "Salesperson" , index = True , default = lambda self : self .env .user )
32
32
property_tag_ids = fields .Many2many ("estate.property.tag" , string = "Tag" )
33
33
offer_ids = fields .One2many ("estate.property.offer" , "property_id" , string = "Offer" )
34
+ total_area = fields .Integer ("Total Area (sqm)" , compute = "_compute_total_area" )
35
+ best_price = fields .Float (compute = "_compute_best_price" )
36
+
37
+ @api .depends ("living_area" , "garden_area" )
38
+ def _compute_total_area (self ):
39
+ for estate in self :
40
+ estate .total_area = estate .living_area + estate .garden_area
41
+
42
+ @api .depends ("offer_ids" )
43
+ def _compute_best_price (self ):
44
+ for estate in self :
45
+ estate .best_price = max (estate .offer_ids .mapped ("price" )) if estate .offer_ids else 0
46
+
47
+ @api .onchange ("garden" )
48
+ def _onchange_garden (self ):
49
+ if self .garden :
50
+ self .garden_area = 10
51
+ self .garden_orientation = "north"
52
+ else :
53
+ self .garden_area = 0
54
+ self .garden_orientation = ""
0 commit comments