1
- from odoo import fields , models
1
+ from odoo import fields , models , api
2
2
from odoo .tools import date_utils as du
3
3
from datetime import date
4
4
5
5
6
6
class EstateProperty (models .Model ):
7
7
_name = "estate.property"
8
8
_description = "A property module that adds the property as a listing"
9
+
9
10
name = fields .Char (required = True )
10
11
description = fields .Text ()
11
12
postcode = fields .Char ()
@@ -27,6 +28,7 @@ class EstateProperty(models.Model):
27
28
("west" , "West" ),
28
29
],
29
30
)
31
+ total_area = fields .Float (compute = "_compute_area" )
30
32
active = fields .Boolean (default = True )
31
33
state = fields .Selection (
32
34
string = "State" ,
@@ -50,3 +52,28 @@ class EstateProperty(models.Model):
50
52
offers_ids = fields .One2many (
51
53
"estate.property.offer" , "property_id" , string = "Offers"
52
54
)
55
+ best_price = fields .Float (
56
+ compute = "_compute_best_price" , readonly = True , string = "Best Offer"
57
+ )
58
+
59
+ @api .depends ("living_area" , "garden" , "garden_area" )
60
+ def _compute_area (self ):
61
+ for record in self :
62
+ record .total_area = record .living_area + record .garden_area
63
+
64
+ @api .depends ("offers_ids.price" )
65
+ def _compute_best_price (self ):
66
+ for record in self :
67
+ if record .offers_ids :
68
+ record .best_price = max (record .offers_ids .mapped ("price" ))
69
+ else :
70
+ record .best_price = 0
71
+
72
+ @api .onchange ("garden" )
73
+ def _onchange_garden (self ):
74
+ if self .garden :
75
+ self .garden_area = 10
76
+ self .garden_orientation = "north"
77
+ else :
78
+ self .garden_area = 0
79
+ self .garden_orientation = None
0 commit comments