11# Part of Odoo. See LICENSE file for full copyright and licensing details.
22
33from odoo import fields , models , api , exceptions
4- from datetime import timedelta
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 :
@@ -68,16 +77,16 @@ def _onchange_garden(self):
6877
6978 def property_sold (self ):
7079 for record in self :
71- if self .state != 'cancelled' :
72- self .state = 'sold'
80+ if record .state != 'cancelled' :
81+ record .state = 'sold'
7382 else :
7483 raise exceptions .UserError ("Sold properties cannot be cancelled." )
7584 return True
7685
7786 def property_cancelled (self ):
7887 for record in self :
79- if self .state != 'sold' :
80- self .state = 'cancelled'
88+ if record .state != 'sold' :
89+ record .state = 'cancelled'
8190 else :
8291 raise exceptions .UserError ("Cancelled properties cannot be sold." )
8392 return True
0 commit comments