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
34
45
56class EstateProperty (models .Model ):
67 _name = "estate.property"
78 _description = "Estate Property"
9+ _check_expected_price = models .Constraint ("CHECK(expected_price>0)" , "Le prix doit être strictement positif." )
10+ _check_selling_price = models .Constraint ("CHECK(selling_price>=0)" , "Le prix doit être positif." )
811
912 name = fields .Char (required = True )
1013 description = fields .Text ()
@@ -38,7 +41,7 @@ class EstateProperty(models.Model):
3841 def _compute_total (self ):
3942 for record in self :
4043 record .total_area = record .living_area + record .garden_area
41-
44+
4245 @api .depends ("offer_ids" )
4346 def _compute_highest_price (self ):
4447 for record in self :
@@ -60,3 +63,9 @@ def action_mark_as_cancelled(self):
6063 raise UserError ("Cette maison a déjà été vendue" )
6164 self .state = "Cancelled"
6265 return True
66+
67+ @api .constrains ("selling_price" , "expected_price" )
68+ def _check_selling_price_is_ok (self ):
69+ for record in self :
70+ if float_compare (self .selling_price , 0.9 * self .expected_price , 2 ) == - 1 :
71+ raise ValidationError ("Le prix de vente doit valoir au moins 90 pourcents du prix attendu." )
0 commit comments