1- from odoo import fields , models
1+ from odoo import api , fields , models
22from dateutil .relativedelta import relativedelta
33from datetime import date
44
55
66class EstatePropertyModel (models .Model ):
7- _name = " estate.property"
7+ _name = ' estate.property'
88 _description = "Real Estate property database"
99 name = fields .Char (required = True )
1010 description = fields .Text ()
@@ -21,32 +21,59 @@ class EstatePropertyModel(models.Model):
2121 garden_area = fields .Integer ()
2222 garden_orientation = fields .Selection (
2323 selection = [
24- ('north' , ' North' ),
25- ('east' , ' East' ),
26- ('south' , ' South' ),
27- ('west' , ' West' ),
24+ ('north' , " North" ),
25+ ('east' , " East" ),
26+ ('south' , " South" ),
27+ ('west' , " West" ),
2828 ],
29- string = ' Garden Orientation' ,
29+ string = " Garden Orientation" ,
3030 default = 'south' ,
3131 )
3232 state = fields .Selection (
3333 selection = [
34- ('new' , ' New' ),
35- ('offer_received' , ' Offer Received' ),
36- ('offer_accepted' , ' Offer Accepted' ),
37- ('sold' , ' Sold' ),
38- ('cancel' , ' Cancelled' ),
34+ ('new' , " New" ),
35+ ('offer_received' , " Offer Received" ),
36+ ('offer_accepted' , " Offer Accepted" ),
37+ ('sold' , " Sold" ),
38+ ('cancel' , " Cancelled" ),
3939 ],
4040 required = True ,
4141 copy = False ,
4242 default = 'new' ,
4343 )
44- property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
45- buyer_id = fields .Many2one ("res.partner" , string = "Buyer" , copy = False )
44+
45+ property_type_id = fields .Many2one ('estate.property.type' , string = "Property Type" )
46+ buyer_id = fields .Many2one ('res.partner' , string = "Buyer" , copy = False )
4647 salesperson_id = fields .Many2one (
47- " res.users" ,
48- string = "Salesperson" ,
48+ ' res.users' ,
49+ string = "Salesperson" ,
4950 default = lambda self : self .env .user
5051 )
51- tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
52- offer_ids = fields .One2many ("estate.property.offer" , "property_id" , string = "Offers" )
52+ tag_ids = fields .Many2many ('estate.property.tag' , string = "Tags" )
53+ offer_ids = fields .One2many ('estate.property.offer' , 'property_id' , string = "Offers" )
54+
55+ total_area = fields .Integer (compute = '_compute_total_area' , string = "Total Area (sqm)" )
56+ best_price = fields .Float (compute = '_compute_best_price' , string = "Best Offer" )
57+
58+ @api .depends ('living_area' , 'garden_area' )
59+ def _compute_total_area (self ):
60+ for record in self :
61+ record .total_area = record .living_area + record .garden_area
62+
63+ @api .depends ('offer_ids.price' )
64+ def _compute_best_price (self ):
65+ for record in self :
66+ offers = record .offer_ids .mapped ('price' )
67+ if offers :
68+ record .best_price = max (offers )
69+ else :
70+ record .best_price = 0.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 = False
0 commit comments