1- from odoo import fields , models
1+ from odoo import api , fields , models
22
33
44class EstateProperty (models .Model ):
@@ -10,7 +10,7 @@ class EstateProperty(models.Model):
1010 postcode = fields .Char ()
1111 date_availability = fields .Date (default = fields .Date .add (fields .Date .today (), months = 3 ), copy = False )
1212 expected_price = fields .Float (required = True )
13- selling_price = fields .Float (readonly = True ,copy = False )
13+ selling_price = fields .Float (readonly = True , copy = False )
1414 bedrooms = fields .Integer (default = 2 )
1515 living_area = fields .Integer ()
1616 facades = fields .Integer ()
@@ -19,7 +19,7 @@ class EstateProperty(models.Model):
1919 garden_area = fields .Integer ()
2020 garden_orientation = fields .Selection (
2121 string = 'Garden orientation' ,
22- selection = [('North' , 'N' ), ('South' , 'S' ),('East' , 'E' ),('West' , 'W' )],
22+ selection = [('North' , 'N' ), ('South' , 'S' ), ('East' , 'E' ), ('West' , 'W' )],
2323 help = "Specify the orientation of the garden to know when you're gonna enjoy the sun" )
2424 state = fields .Selection (
2525 selection = [('New' , 'New' ), ('Offer Received' , 'Offer Received' ), ('Offer Accepted' , 'Offer Accepted' ), ('Sold' , 'Sold' ), ('Cancelled' , 'Cancelled' )],
@@ -28,5 +28,24 @@ class EstateProperty(models.Model):
2828 active = fields .Boolean (default = True )
2929 salesman = fields .Many2one ("res.users" )
3030 buyer = fields .Many2one ("res.partner" , copy = False )
31- tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
32- offer_ids = fields .One2many ("estate.property.offer" ,"property_id" )
31+ tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
32+ offer_ids = fields .One2many ("estate.property.offer" , "property_id" )
33+ total_area = fields .Float (compute = "_compute_total" )
34+ best_price = fields .Float (compute = "_compute_highest_price" )
35+
36+ @api .depends ("living_area" , "garden_area" )
37+ def _compute_total (self ):
38+ for record in self :
39+ record .total_area = record .living_area + record .garden_area
40+
41+ @api .depends ("offer_ids" )
42+ def _compute_highest_price (self ):
43+ for record in self :
44+ record .best_price = max (record .offer_ids .mapped ("price" )) if record .offer_ids else 0
45+
46+ @api .onchange ("garden" )
47+ def _onchange_garden (self ):
48+ self .garden_area = 10 if self .garden else 0
49+ self .garden_orientation = "North" if self .garden else None
50+
51+
0 commit comments