1- from odoo import models , fields , api
21from datetime import timedelta
2+
3+ from odoo import models , fields , api
34from odoo .exceptions import ValidationError
45
56
67class EstateProperty (models .Model ):
78 _name = "estate.property"
89 _description = "Real Estate Property"
910 _order = "id desc"
10-
1111 name = fields .Char (required = True )
1212 description = fields .Text ()
1313 postcode = fields .Char ()
@@ -20,22 +20,9 @@ class EstateProperty(models.Model):
2020 garage = fields .Boolean ()
2121 garden = fields .Boolean ()
2222 garden_area = fields .Integer ()
23- garden_orientation = fields .Selection ([
24- ("north" , "North" ),
25- ("south" , "South" ),
26- ("east" , "East" ),
27- ("west" , "West" ),
28- ])
23+ garden_orientation = fields .Selection ([("north" , "North" ),("south" , "South" ),("east" , "East" ),("west" , "West" ),])
2924 active = fields .Boolean (default = True )
30-
31- state = fields .Selection ([
32- ("new" , "New" ),
33- ("offer_received" , "Offer Received" ),
34- ("offer_accepted" , "Offer Accepted" ),
35- ("sold" , "Sold" ),
36- ("canceled" , "Canceled" ),
37- ], string = "Status" , required = True , copy = False , default = "new" )
38-
25+ state = fields .Selection ([("new" , "New" ),("offer_received" , "Offer Received" ),("offer_accepted" , "Offer Accepted" ),("sold" , "Sold" ),("canceled" , "Canceled" )], required = True , copy = False , )
3926 property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
4027 buyer_id = fields .Many2one ("res.partner" , string = "Buyer" )
4128 salesperson_id = fields .Many2one ("res.users" , string = "Salesperson" )
@@ -44,11 +31,9 @@ class EstateProperty(models.Model):
4431 total_area = fields .Float (compute = "_compute_total_area" , string = "Total Area" , store = True )
4532 best_price = fields .Float (compute = "_compute_best_price" , string = "Best Offer" , store = True )
4633 validity_days = fields .Integer (default = 7 )
47- date_deadline = fields .Date (
48- compute = "_compute_date_deadline" ,
49- inverse = "_inverse_date_deadline" ,
50- store = True ,
51- )
34+ date_deadline = fields .Date (compute = "_compute_date_deadline" ,inverse = "_inverse_date_deadline" ,store = True ,)
35+ property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
36+
5237
5338 @api .depends ("living_area" , "garden_area" )
5439 def _compute_total_area (self ):
@@ -110,21 +95,16 @@ def action_back_to_new(self):
11095 @api .constrains ("selling_price" , "expected_price" )
11196 def _check_selling_price_ratio (self ):
11297 for record in self :
113- if record .selling_price <= 0 :
114- raise ValidationError ("Selling price must be greater than or equal to 0" )
11598 if record .selling_price < 0.9 * record .expected_price :
11699 raise ValidationError ("Selling price must be at least 90% of the expected price" )
117- if record .expected_price < 0 :
118- raise ValidationError ("Expected price must be greater than 0" )
119100
120- _check_expected_price = models .Constraint (
121- 'CHECK(expected_price < 0)' ,
101+ def _unlink (self ):
102+ for record in self :
103+ if record .state in ["new" ]:
104+ raise ValidationError ("You cannot delete a new or canceled property." )
105+ return super ().unlink ()
106+
107+ _check_price = models .Constraint (
108+ 'CHECK(expected_price > 0 AND selling_price >= 0)' ,
122109 'The expected price of a property must be strictly positive.'
123- )
124-
125- _check_selling_price = models .Constraint (
126- 'CHECK(selling_price < 0)' ,
127- 'The selling price of a property must be positive.'
128- )
129-
130- property_type_id = fields .Many2one ("estate.property.type" , string = "Property Type" )
110+ )
0 commit comments