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_is_zero , float_compare
34
45
56class EstateProperty (models .Model ):
@@ -58,6 +59,15 @@ class EstateProperty(models.Model):
5859 tag_ids = fields .Many2many ('estate.property.tag' , string = 'Tags' )
5960 offer_ids = fields .One2many ('estate.property.offer' , 'property_id' , string = 'Offers' )
6061
62+ _check_expected_price = models .Constraint (
63+ 'CHECK(expected_price > 0)' ,
64+ 'The expected price of a property should be strictly positive.' ,
65+ )
66+ _check_selling_price = models .Constraint (
67+ 'CHECK(selling_price >= 0)' ,
68+ 'The selling price of a property should be positive.' ,
69+ )
70+
6171 @api .depends ('living_area' , 'garden_area' )
6272 def _compute_total_area (self ):
6373 for record in self :
@@ -79,6 +89,16 @@ def _onchange_garden(self):
7989 self .garden_area = None
8090 self .garden_orientation = None
8191
92+ @api .constrains ('selling_price' , 'expected_price' )
93+ def _check_selling_price (self ):
94+ for record in self :
95+ if (
96+ not float_is_zero (record .selling_price , 2 )
97+ and float_compare (record .selling_price , record .expected_price * 0.90 , 2 ) < 0
98+ ):
99+ raise ValidationError ("Selling price cannot be lower than 90% of expected price" )
100+
101+
82102 def action_mark_as_sold (self ):
83103 for record in self :
84104 if record .state == 'cancelled' :
0 commit comments