1- from odoo import fields , models
1+ from odoo import fields , models , api
22from odoo .tools import date_utils as du
33from datetime import date
44
55
66class EstateProperty (models .Model ):
77 _name = "estate.property"
88 _description = "A property module that adds the property as a listing"
9+
910 name = fields .Char (required = True )
1011 description = fields .Text ()
1112 postcode = fields .Char ()
@@ -27,6 +28,7 @@ class EstateProperty(models.Model):
2728 ("west" , "West" ),
2829 ],
2930 )
31+ total_area = fields .Float (compute = "_compute_area" )
3032 active = fields .Boolean (default = True )
3133 state = fields .Selection (
3234 string = "State" ,
@@ -50,3 +52,28 @@ class EstateProperty(models.Model):
5052 offers_ids = fields .One2many (
5153 "estate.property.offer" , "property_id" , string = "Offers"
5254 )
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