11from dateutil .relativedelta import relativedelta
22from odoo import fields , models ,api ,exceptions
3+ from odoo .tools .float_utils import float_compare , float_is_zero ;
4+ from odoo .exceptions import ValidationError ;
35
46
57class EstateProperty (models .Model ):
68 _name = "estate.property"
79 _description = "Property"
810 _positif_expected_price = models .Constraint ("CHECK (expected_price > 0)" ,"A price can't be negatif" );
911 _positif_selling_price = models .Constraint ("CHECK (selling_price > 0)" ,"A price can't be negatif" );
10- _postif_best_price = models .Constraint ("CHECK (best_price > 0)" , "A price can't be negatif" );
1112
1213 state = fields .Selection (selection = [("New" ,"New" ), ("Offer_Received" ,"Offer Received" ) ,("Offer_Accepted" ,"Offer Accepted" ), ("Sold" ,"Sold" ), ("Cancelled" ,"Cancelled" )])
1314 active = fields .Boolean ('Active' ,default = True )
@@ -70,4 +71,12 @@ def _get_best_price(self):
7071 @api .onchange ("garden" )
7172 def _garden_pre_fill (self ):
7273 self .garden_area = 10 if self .garden else 0
73- self .garden_orientation = 'North' if self .garden else ''
74+ self .garden_orientation = 'North' if self .garden else ''
75+
76+ @api .constrains ('selling_price' ,'expected_price' )
77+ def _check_prices (self ):
78+ for record in self :
79+ if float_is_zero (record .selling_price ,2 ):
80+ return ;
81+ if (float_compare (record .selling_price ,record .expected_price * .8 ,2 ) == - 1 ):
82+ raise ValidationError (f"Selling price is too low { record .selling_price } " );
0 commit comments