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 ;
3+ from odoo .tools .float_utils import float_compare , float_is_zero
4+ from odoo .exceptions import ValidationError
55
66
77class EstateProperty (models .Model ):
88 _name = "estate.property"
99 _description = "Property"
1010 _order = "id desc"
1111
12- _positif_expected_price = models .Constraint ("CHECK (expected_price > 0)" ,"A price can't be negatif" );
13- _positif_selling_price = models .Constraint ("CHECK (selling_price > 0)" ,"A price can't be negatif" );
12+ _positif_expected_price = models .Constraint ("CHECK (expected_price > 0)" , "A price can't be negatif" )
13+ _positif_selling_price = models .Constraint ("CHECK (selling_price > 0)" , "A price can't be negatif" )
1414
15- state = fields .Selection (selection = [("New" ,"New" ), ("Offer_Received" ,"Offer Received" ) , ("Offer_Accepted" ,"Offer Accepted" ), ("Sold" ,"Sold" ), ("Cancelled" ,"Cancelled" )])
16- active = fields .Boolean ('Active' ,default = True )
17- name = fields .Char (required = True ,default = "Unkown" )
15+ state = fields .Selection (selection = [("New" , "New" ), ("Offer_Received" , "Offer Received" ), ("Offer_Accepted" , "Offer Accepted" ), ("Sold" , "Sold" ), ("Cancelled" , "Cancelled" )])
16+ active = fields .Boolean ('Active' , default = True )
17+ name = fields .Char (required = True , default = "Unkown" )
1818 description = fields .Text ()
1919 postcode = fields .Char ()
20- date_availability = fields .Date ("Available From" ,copy = False ,default = fields .Datetime .today () + relativedelta (months = 3 ))
21- last_seen = fields .Date ("Last Seen" , default = fields .Datetime .now )
20+ date_availability = fields .Date ("Available From" , copy = False , default = fields .Datetime .today () + relativedelta (months = 3 ))
21+ last_seen = fields .Date ("Last Seen" , default = fields .Datetime .now )
2222 expected_price = fields .Float (required = True )
23- selling_price = fields .Float (readonly = True ,copy = False )
24- best_price = fields .Float (string = "Best Price" ,compute = "_get_best_price" )
23+ selling_price = fields .Float (readonly = True , copy = False )
24+ best_price = fields .Float (string = "Best Price" , compute = "_get_best_price" )
2525 bedrooms = fields .Integer (default = 2 )
2626 living_area = fields .Integer ()
2727 facades = fields .Integer ()
2828 garage = fields .Boolean ()
2929 garden = fields .Boolean ()
3030 garden_area = fields .Integer ()
31- garden_orientation = fields .Selection (selection = [('North' ,'North' ),('South' ,'South' ),('East' ,'East' ),('West' ,'West' )])
32- total_area = fields .Float (compute = "_get_total_area" ,string = "Total Area" );
33- property_type_id = fields .Many2one ("estate.property.type" ,string = "Type" )
34- buyer_id = fields .Many2one ("res.partner" ,string = "Buyer" )
35- seller_id = fields .Many2one ("res.users" ,default = lambda self : self .env .user ,string = "Seller" )
36- tag_ids = fields .Many2many ("estate.property.tag" ,string = "Tags" )
37- offer_ids = fields .One2many ("estate.property.offer" ,"property_id" ,string = "Offers" )
31+ garden_orientation = fields .Selection (selection = [('North' , 'North' ), ('South' , 'South' ), ('East' , 'East' ), ('West' , 'West' )])
32+ total_area = fields .Float (compute = "_get_total_area" , string = "Total Area" )
33+ property_type_id = fields .Many2one ("estate.property.type" , string = "Type" )
34+ buyer_id = fields .Many2one ("res.partner" , string = "Buyer" )
35+ seller_id = fields .Many2one ("res.users" , default = lambda self : self .env .user ,string = "Seller" )
36+ tag_ids = fields .Many2many ("estate.property.tag" , string = "Tags" )
37+ offer_ids = fields .One2many ("estate.property.offer" , "property_id" ,string = "Offers" )
3838
3939 def sell_property (self ):
4040 for record in self :
41- if (record .state == "Cancelled" ):
41+ if (record .state == "Cancelled" ):
4242 raise exceptions .UserError ("Can't sell cancelled property." )
4343 record .state = "Sold"
4444 return True
45-
45+
4646 def cancel_property (self ):
4747 for record in self :
48- if (record .state == "Sold" ):
48+ if (record .state == "Sold" ):
4949 raise exceptions .UserError ("Can't cancel sold property." )
5050 record .state = "Cancelled"
5151 return True
5252
53- @api .depends ('living_area' ,'garden_area' )
53+ @api .depends ('living_area' , 'garden_area' )
5454 def _get_total_area (self ):
5555 for record in self :
56- record .total_area = record .garden_area + record .living_area ;
57-
56+ record .total_area = record .garden_area + record .living_area
5857
5958 @api .depends ('offer_ids' )
6059 def _get_best_price (self ):
6160 for record in self :
62- max :int = 0
63-
64- if (len (record .offer_ids )== 0 ):
61+ max : int = 0
62+ if (len (record .offer_ids ) == 0 ):
6563 record .best_price = 0
6664 continue
67-
65+
6866 for offer in record .offer_ids :
69- if (offer .price >= max ):
67+ if (offer .price >= max ):
7068 max = offer .price
7169 record .best_price = max
7270
@@ -75,10 +73,11 @@ def _garden_pre_fill(self):
7573 self .garden_area = 10 if self .garden else 0
7674 self .garden_orientation = 'North' if self .garden else ''
7775
78- @api .constrains ('selling_price' ,'expected_price' )
76+ @api .constrains ('selling_price' , 'expected_price' )
7977 def _check_prices (self ):
80- for record in self :
81- if float_is_zero (record .selling_price ,2 ):
82- continue ;
83- if (float_compare (record .selling_price ,record .expected_price * .8 ,2 ) == - 1 ):
84- raise ValidationError (f"Selling price is too low { record .selling_price } " );
78+ for record in self :
79+ if float_is_zero (record .selling_price , 2 ):
80+ continue
81+ if (float_compare (record .selling_price , record .expected_price * 0.8 , 2 ) == - 1 ):
82+ raise ValidationError (f"Selling price is too low { record .selling_price } " )
83+
0 commit comments