1- from odoo import fields , models , api
2- from odoo .tools import date_utils as du
31from datetime import date
42
3+ from odoo import fields , models , api
4+ from odoo .tools import date_utils
5+ from odoo .exceptions import UserError
6+
57
68class EstateProperty (models .Model ):
79 _name = "estate.property"
@@ -10,7 +12,9 @@ class EstateProperty(models.Model):
1012 name = fields .Char (required = True )
1113 description = fields .Text ()
1214 postcode = fields .Char ()
13- date_availability = fields .Date (copy = False , default = du .add (date .today (), months = 3 ))
15+ date_availability = fields .Date (
16+ copy = False , default = lambda _ : date_utils .add (date .today (), months = 3 )
17+ )
1418 expected_price = fields .Float (required = True )
1519 selling_price = fields .Float (readonly = True , copy = False )
1620 bedrooms = fields .Integer (default = 2 )
@@ -28,7 +32,7 @@ class EstateProperty(models.Model):
2832 ("west" , "West" ),
2933 ],
3034 )
31- total_area = fields .Float (compute = "_compute_area " )
35+ total_area = fields .Float (compute = "_compute_total_area " )
3236 active = fields .Boolean (default = True )
3337 state = fields .Selection (
3438 string = "State" ,
@@ -56,18 +60,22 @@ class EstateProperty(models.Model):
5660 compute = "_compute_best_price" , readonly = True , string = "Best Offer"
5761 )
5862
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+ @api .depends ("living_area" , "garden_area" )
64+ def _compute_total_area (self ):
65+ for single_property in self :
66+ single_property .total_area = (
67+ single_property .living_area + single_property .garden_area
68+ )
6369
6470 @api .depends ("offers_ids.price" )
6571 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" ))
72+ for single_property in self :
73+ if single_property .offers_ids :
74+ single_property .best_price = max (
75+ single_property .offers_ids .mapped ("price" )
76+ )
6977 else :
70- record .best_price = 0
78+ single_property .best_price = 0
7179
7280 @api .onchange ("garden" )
7381 def _onchange_garden (self ):
@@ -77,3 +85,19 @@ def _onchange_garden(self):
7785 else :
7886 self .garden_area = 0
7987 self .garden_orientation = None
88+
89+ def action_property_cancel (self ):
90+ for single_property in self :
91+ if single_property .state == "sold" :
92+ raise UserError ("Sold properties cannot be cancelled!" )
93+ return False
94+ single_property .state = "cancelled"
95+ return True
96+
97+ def action_property_sold (self ):
98+ for single_property in self :
99+ if single_property .state == "cancelled" :
100+ raise UserError ("Cancelled properties cannot be sold!" )
101+ return False
102+ single_property .state = "sold"
103+ return True
0 commit comments