1
- from odoo import fields , models
1
+ from odoo import api , fields , models
2
2
from dateutil .relativedelta import relativedelta
3
3
4
4
@@ -7,7 +7,7 @@ class EstateProperty(models.Model):
7
7
_description = "Estate Property discription"
8
8
9
9
name = fields .Char ('name' , required = True )
10
- description = fields .Text ('description' )
10
+ description = fields .Text ('description' , compute = "_compute_description" )
11
11
postcode = fields .Char ('postcode' )
12
12
availability_date = fields .Date (
13
13
'availabilty date' , copy = False , default = fields .Date .today () + relativedelta (months = 3 ))
@@ -17,11 +17,12 @@ class EstateProperty(models.Model):
17
17
living_area = fields .Integer ('living area' )
18
18
facades = fields .Integer ('facades' )
19
19
garage = fields .Boolean ('garage' )
20
+ garden = fields .Boolean ('garden' )
20
21
garden_area = fields .Integer ('garden area' )
21
22
garden_orientation = fields .Selection (
22
23
string = 'Garden Orientation' ,
23
- selection = [('North ' , 'North' ), ('South ' , 'South' ),
24
- ('East ' , 'East' ), ('West ' , 'West' )]
24
+ selection = [('north ' , 'North' ), ('south ' , 'South' ),
25
+ ('east ' , 'East' ), ('west ' , 'West' )]
25
26
)
26
27
active = fields .Boolean ('active' , default = True )
27
28
state = fields .Selection (
@@ -39,3 +40,35 @@ class EstateProperty(models.Model):
39
40
tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
40
41
offer_ids = fields .One2many (
41
42
"estate.property.offer" , "property_id" , string = "Offers" )
43
+ total_area = fields .Integer (compute = '_compute_total_area' )
44
+ best_offer = fields .Float (compute = "_compute_best_offer" )
45
+
46
+ @api .depends ("living_area" , "garden_area" )
47
+ def _compute_total_area (self ):
48
+ for record in self :
49
+ record .total_area = record .living_area + record .garden_area
50
+
51
+ @api .depends ("buyer_id" )
52
+ def _compute_description (self ):
53
+ for record in self :
54
+ record .description = "Description for buyer %s" % record .buyer_id .name
55
+
56
+ @api .depends ("offer_ids" )
57
+ def _compute_best_offer (self ):
58
+ try :
59
+ for record in self :
60
+ if len (record .offer_ids ) > 0 :
61
+ record .best_offer = max (record .offer_ids .mapped ("price" ))
62
+ else :
63
+ record .best_offer = 0.0
64
+ except Exception as e :
65
+ print (e )
66
+
67
+ @api .onchange ("garden" )
68
+ def _onchange_garden (self ):
69
+ if self .garden :
70
+ self .garden_area = 10
71
+ self .garden_orientation = "north"
72
+ else :
73
+ self .garden_area = 0
74
+ self .garden_orientation = None
0 commit comments