11# Part of Odoo. See LICENSE file for full copyright and licensing details.
22
3- from odoo import fields , models , api
4- from datetime import timedelta
3+ from odoo import fields , models , api , exceptions
54
65
76class EstateProperty (models .Model ):
@@ -12,7 +11,7 @@ class EstateProperty(models.Model):
1211 active = fields .Boolean ('Active' , default = True )
1312 description = fields .Text ('Description' )
1413 postcode = fields .Char ('Postcode' )
15- date_availability = fields .Date ('Available From' , copy = False , default = fields .Datetime . now () + timedelta ( days = 90 ))
14+ date_availability = fields .Date ('Available From' , copy = False , default = fields .Date . add ( fields . Date . today (), months = 3 ))
1615 expected_price = fields .Float ('Expected Price' , required = True )
1716 selling_price = fields .Float ('Selling Price' , readonly = True , copy = False )
1817 bedrooms = fields .Integer ('Bedrooms' , default = 2 )
@@ -44,6 +43,16 @@ class EstateProperty(models.Model):
4443 total_area = fields .Integer ('Total Area (sqm)' , compute = '_compute_total_area' )
4544 best_offer = fields .Float ('Best Offer' , compute = '_compute_best_offer' )
4645
46+ _check_expected_price = models .Constraint (
47+ 'CHECK(expected_price > 0)' ,
48+ 'The expected price must be strictly positive' ,
49+ )
50+
51+ _check_selling_price = models .Constraint (
52+ 'CHECK(selling_price >= 0)' ,
53+ 'The selling price must be positive' ,
54+ )
55+
4756 @api .depends ('garden_area' , 'living_area' )
4857 def _compute_total_area (self ):
4958 for record in self :
@@ -65,3 +74,19 @@ def _onchange_garden(self):
6574 else :
6675 self .garden_area = 0
6776 self .garden_orientation = ''
77+
78+ def property_sold (self ):
79+ for record in self :
80+ if record .state != 'cancelled' :
81+ record .state = 'sold'
82+ else :
83+ raise exceptions .UserError ("Sold properties cannot be cancelled." )
84+ return True
85+
86+ def property_cancelled (self ):
87+ for record in self :
88+ if record .state != 'sold' :
89+ record .state = 'cancelled'
90+ else :
91+ raise exceptions .UserError ("Cancelled properties cannot be sold." )
92+ return True
0 commit comments