File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11from odoo import api , fields , models
2- from odoo .exceptions import UserError
2+ from odoo .exceptions import UserError , ValidationError
3+ from odoo .tools .float_utils import float_compare , float_is_zero
34
45
56class Estate (models .Model ):
@@ -74,3 +75,20 @@ def action_mark_cancel(self):
7475 if record .status == 'sold' :
7576 raise UserError ("Sold properties cannot be canceled." )
7677 record .status = 'canceled'
78+
79+ _check_expected_price = models .Constraint (
80+ 'CHECK(expected_price > 0)' ,
81+ 'The expected price must be strictly positive'
82+ )
83+
84+ _check_selling_price = models .Constraint (
85+ 'CHECK(selling_price >= 0)' ,
86+ 'The selling price must be positive'
87+ )
88+
89+ @api .constrains ('selling_price' )
90+ def _check_selling_price (self ):
91+ for record in self :
92+ if not float_is_zero (record .selling_price , precision_digits = 2 ):
93+ if float_compare (record .selling_price , record .expected_price * 0.9 , precision_digits = 2 ) < 0 :
94+ raise ValidationError ('The selling price must be atleast 90% of the expected price! You must reduce the expected price to accept the offer' )
Original file line number Diff line number Diff line change @@ -45,3 +45,7 @@ def action_reject_offer(self):
4545 record .property_id .buyer_id = False
4646 record .property_id .status = 'offer_received'
4747
48+ _check_price = models .Constraint (
49+ 'CHECK(price > 0)' ,
50+ 'The offer price must be strictly positive'
51+ )
Original file line number Diff line number Diff line change @@ -6,3 +6,8 @@ class PropertyTag(models.Model):
66 _description = 'Estate Property Tag'
77
88 name = fields .Char ("Tag Name" , required = True )
9+
10+ _unique_name = models .Constraint (
11+ 'UNIQUE(name)' ,
12+ 'The property tag name must be unique'
13+ )
Original file line number Diff line number Diff line change @@ -6,3 +6,8 @@ class PropertyType(models.Model):
66 _description = 'Estate Property Type'
77
88 name = fields .Char ("Property Type" , required = True )
9+
10+ _unique_name = models .Constraint (
11+ 'UNIQUE(name)' ,
12+ 'The property type name must be unique'
13+ )
You can’t perform that action at this time.
0 commit comments