11from dateutil .relativedelta import relativedelta
2- from odoo import fields , models ,api ,exceptions
3- from odoo .tools .float_utils import float_compare , float_is_zero ;
4- from odoo .exceptions import ValidationError ;
2+ from odoo import fields , models , api , exceptions
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"
10- _positif_expected_price = models .Constraint ("CHECK (expected_price > 0)" ,"A price can't be negatif" );
11- _positif_selling_price = models .Constraint ("CHECK (selling_price > 0)" ,"A price can't be negatif" );
10+ _order = "id desc"
1211
13- state = fields .Selection (selection = [("New" ,"New" ), ("Offer_Received" ,"Offer Received" ) ,("Offer_Accepted" ,"Offer Accepted" ), ("Sold" ,"Sold" ), ("Cancelled" ,"Cancelled" )])
14- active = fields .Boolean ('Active' ,default = True )
15- name = fields .Char (required = True ,default = "Unkown" )
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" )
14+
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" )
1618 description = fields .Text ()
1719 postcode = fields .Char ()
18- date_availability = fields .Date ("Available From" ,copy = False ,default = fields .Datetime .today () + relativedelta (months = 3 ))
19- 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 )
2022 expected_price = fields .Float (required = True )
21- selling_price = fields .Float (readonly = True ,copy = False )
22- 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" )
2325 bedrooms = fields .Integer (default = 2 )
2426 living_area = fields .Integer ()
2527 facades = fields .Integer ()
2628 garage = fields .Boolean ()
2729 garden = fields .Boolean ()
2830 garden_area = fields .Integer ()
29- garden_orientation = fields .Selection (selection = [('North' ,'North' ),('South' ,'South' ),('East' ,'East' ),('West' ,'West' )])
30- total_area = fields .Float (compute = "_get_total_area" ,string = "Total Area" );
31- property_type_id = fields .Many2one ("estate.property.type" ,string = "Type" )
32- buyer_id = fields .Many2one ("res.partner" ,string = "Buyer" )
33- seller_id = fields .Many2one ("res.users" ,default = lambda self : self .env .user ,string = "Seller" )
34- tag_ids = fields .Many2many ("estate.property.tag" ,string = "Tags" )
35- 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" )
3638
3739 def sell_property (self ):
3840 for record in self :
39- if (record .state == "Cancelled" ):
41+ if (record .state == "Cancelled" ):
4042 raise exceptions .UserError ("Can't sell cancelled property." )
4143 record .state = "Sold"
4244 return True
43-
45+
4446 def cancel_property (self ):
4547 for record in self :
46- if (record .state == "Sold" ):
48+ if (record .state == "Sold" ):
4749 raise exceptions .UserError ("Can't cancel sold property." )
4850 record .state = "Cancelled"
4951 return True
5052
51- @api .depends ('living_area' ,'garden_area' )
53+ @api .depends ('living_area' , 'garden_area' )
5254 def _get_total_area (self ):
5355 for record in self :
54- record .total_area = record .garden_area + record .living_area ;
55-
56+ record .total_area = record .garden_area + record .living_area
5657
5758 @api .depends ('offer_ids' )
5859 def _get_best_price (self ):
5960 for record in self :
60- max :int = 0
61-
62- if (len (record .offer_ids )== 0 ):
61+ max : int = 0
62+ if (len (record .offer_ids ) == 0 ):
6363 record .best_price = 0
6464 continue
65-
65+
6666 for offer in record .offer_ids :
67- if (offer .price >= max ):
67+ if (offer .price >= max ):
6868 max = offer .price
6969 record .best_price = max
7070
@@ -73,10 +73,10 @@ def _garden_pre_fill(self):
7373 self .garden_area = 10 if self .garden else 0
7474 self .garden_orientation = 'North' if self .garden else ''
7575
76- @api .constrains ('selling_price' ,'expected_price' )
76+ @api .constrains ('selling_price' , 'expected_price' )
7777 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 } " );
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 } " )
0 commit comments