1- from odoo import models , fields
2- from odoo .tools import date_utils
1+ #!/usr/bin/env python3
2+ from dateutil .relativedelta import relativedelta
3+
4+ from odoo import api , models , fields
35
46
57class EstateProperty (models .Model ):
@@ -10,8 +12,7 @@ class EstateProperty(models.Model):
1012 description = fields .Text ()
1113 postcode = fields .Char ()
1214 date_avaliability = fields .Date (
13- copy = False ,
14- default = date_utils .add (fields .Date .today (), month = 2 ),
15+ copy = False , default = fields .Date .today () + relativedelta (month = 3 )
1516 )
1617 expected_price = fields .Float (required = True )
1718 selling_price = fields .Float (readonly = True , copy = False )
@@ -48,9 +49,30 @@ class EstateProperty(models.Model):
4849 property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
4950 customer = fields .Many2one ("res.users" , string = "Customer" , copy = False )
5051 salesperson = fields .Many2one (
51- "res.partner" ,
52- string = "Salesperson" ,
53- default = lambda self :self .env .user
52+ "res.partner" , string = "Salesperson" , default = lambda self : self .env .user
5453 )
5554 tag_ids = fields .Many2many ("estate.property.tag" , string = "Property Tags" )
56- offer_ids = fields .One2many ("estate.property.offer" , "property_id" , string = "Offer" )
55+ offer_ids = fields .One2many ("estate.property.offer" , "property_id" , string = "Offer" )
56+ total_area = fields .Integer (compute = "_compute_area" )
57+ best_price = fields .Integer (compute = "_compute_highest" )
58+
59+ @api .depends ("living_area" , "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 ("offer_ids.price" )
65+ def _compute_highest (self ):
66+ for record in self :
67+ if not record .mapped ("offer_ids.price" ):
68+ record .best_price = 0
69+ else :
70+ record .best_price = max (record .mapped ("offer_ids.price" ))
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
0 commit comments