1- from odoo import fields , models
1+ from odoo import api , fields , models
22from dateutil .relativedelta import relativedelta
33
44
@@ -15,7 +15,9 @@ class EstateProperty(models.Model):
1515 description = fields .Text ("Description" )
1616 postcode = fields .Char ("Postcode" )
1717 date_availability = fields .Date (
18- "Available From" , default = lambda self : fields .Date .today () + relativedelta (months = 3 ), copy = False
18+ "Available From" ,
19+ default = lambda self : fields .Date .today () + relativedelta (months = 3 ),
20+ copy = False ,
1921 )
2022 expected_price = fields .Float ("Expected Price" , required = True )
2123 selling_price = fields .Float ("Selling Price" , copy = False , readonly = True )
@@ -55,3 +57,30 @@ class EstateProperty(models.Model):
5557 property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
5658 tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
5759 offer_ids = fields .One2many ("estate.property.offer" , "property_id" , string = "Offers" )
60+
61+ # Computed fields
62+ @api .depends ("living_area" , "garden_area" )
63+ def _compute_total_area (self ):
64+ for record in self :
65+ record .total_area = record .living_area + record .garden_area
66+
67+ total_area = fields .Integer ("Total Area (sqm)" , compute = "_compute_total_area" , store = True )
68+
69+ @api .depends ("offer_ids.price" )
70+ def _compute_best_offer (self ):
71+ for record in self :
72+ prices = record .offer_ids .mapped ("price" )
73+ record .best_offer = max (prices ) if prices else 0.0
74+
75+ best_offer = fields .Float ("Best Offer" , compute = "_compute_best_offer" , store = True )
76+
77+ @api .onchange ("garden" )
78+ def _onchange_garden (self ):
79+ if not self .garden :
80+ self .garden_area = 0
81+ self .garden_orientation = False
82+ else :
83+ if not self .garden_area :
84+ self .garden_area = 10
85+ if not self .garden_orientation :
86+ self .garden_orientation = "north"
0 commit comments