1
1
from dateutil .relativedelta import relativedelta
2
-
3
2
from odoo import api , fields , models
4
3
from odoo .exceptions import UserError
5
4
from odoo .exceptions import ValidationError
9
8
class EstateProperty (models .Model ):
10
9
_name = "estate.property"
11
10
_description = "Estate Property"
11
+ _order = "id desc"
12
12
13
13
name = fields .Char (string = "Title" , required = True )
14
14
description = fields .Text (string = "Description" )
15
15
postcode = fields .Char (string = "Postcode" )
16
16
date_availability = fields .Date (
17
17
default = lambda self : fields .Date .today () + relativedelta (months = 3 ),
18
- string = "Available From" , copy = False ,
18
+ string = "Available From" , copy = False
19
19
)
20
20
expected_price = fields .Float (string = "Property Expected Price" , required = True )
21
21
selling_price = fields .Float (string = "Selling Price" , readonly = True , copy = False )
@@ -32,7 +32,7 @@ class EstateProperty(models.Model):
32
32
('south' , "South" ),
33
33
('east' , "East" ),
34
34
('west' , "West" ),
35
- ],
35
+ ]
36
36
)
37
37
state = fields .Selection (
38
38
string = "State" ,
@@ -42,7 +42,7 @@ class EstateProperty(models.Model):
42
42
('accepted' , "Offer Accepted" ),
43
43
('sold' , "Sold" ),
44
44
('cancelled' , "Cancelled" ),
45
- ], required = True , copy = False , default = 'new' ,
45
+ ], required = True , copy = False , default = 'new'
46
46
)
47
47
buyer_id = fields .Many2one ("res.partner" )
48
48
salesman_id = fields .Many2one ("res.users" , default = lambda self : self .env .user )
@@ -51,23 +51,27 @@ class EstateProperty(models.Model):
51
51
offer_ids = fields .One2many ('estate.property.offer' , 'property_id' ,
52
52
string = "Offers" )
53
53
54
- total_area = fields .Float (string = "Total Area" , compute = " _compute_total_area" ,
54
+ total_area = fields .Float (string = "Total Area" , compute = ' _compute_total_area' ,
55
55
store = True )
56
56
57
57
best_price = fields .Float (string = "Best price" ,
58
58
compute = '_compute_best_price' , store = True )
59
+ is_offer_excepted = fields .Boolean (string = "Offer Excepted" ,
60
+ compute = '_compute_is_offer_excepted' )
61
+ is_available = fields .Boolean (string = "Available" , compute = '_compute_is_available' ,
62
+ store = True )
59
63
60
64
_sql_constraints = [
61
65
(
62
- " check_expected_price_positive" ,
63
- " CHECK(expected_price >= 0)" ,
64
- " Expected price must be strictly positive." ,
66
+ ' check_expected_price_positive' ,
67
+ ' CHECK(expected_price >= 0)' ,
68
+ ' Expected price must be strictly positive.' ,
65
69
),
66
70
(
67
- " check_selling_price_positive" ,
68
- " CHECK(selling_price >= 0)" ,
69
- " Selling price must be strictly positive." ,
70
- ),
71
+ ' check_selling_price_positive' ,
72
+ ' CHECK(selling_price >= 0)' ,
73
+ ' Selling price must be strictly positive.' ,
74
+ )
71
75
]
72
76
73
77
@api .depends ('garden_area' , 'living_area' )
@@ -80,15 +84,25 @@ def _compute_best_price(self):
80
84
for val in self :
81
85
val .best_price = max (val .offer_ids .mapped ('price' ), default = 0 )
82
86
87
+ @api .depends ('offer_ids.state' )
88
+ def _compute_is_offer_excepted (self ):
89
+ for val in self :
90
+ val .is_offer_excepted = any (x .state == 'accepted' for x in val .offer_ids )
91
+
92
+ @api .depends ('state' )
93
+ def _compute_is_available (self ):
94
+ for val in self :
95
+ val .is_available = val .state in ('new' , 'received' )
96
+
83
97
def action_sold (self ):
84
98
if self .state == 'cancelled' :
85
- raise UserError (' Cancelled property cannot be sold.' )
99
+ raise UserError (" Cancelled property cannot be sold." )
86
100
self .state = 'sold'
87
101
88
102
def action_cancel (self ):
89
103
for val in self :
90
104
if val .state == 'sold' :
91
- raise UserError (' Sold property cannot be cancelled.' )
105
+ raise UserError (" Sold property cannot be cancelled." )
92
106
val .state = 'cancelled'
93
107
94
108
@api .onchange ('garden' )
@@ -100,7 +114,7 @@ def _onchange_garden(self):
100
114
self .garden_area = False
101
115
self .garden_orientation = False
102
116
103
- @api .constrains (" expected_price" , " selling_price" )
117
+ @api .constrains (' expected_price' , ' selling_price' )
104
118
def _check_selling_price_vs_expected (self ):
105
119
for rec in self :
106
120
if float_is_zero (rec .selling_price or 0.0 , precision_digits = 2 ):
@@ -111,8 +125,3 @@ def _check_selling_price_vs_expected(self):
111
125
raise ValidationError (
112
126
"Here Selling price must be at least 90% of the expected price."
113
127
)
114
- # if rec.selling_price and rec.selling_price <= rec.expected_price * 0.90:
115
- # raise ValidationError(
116
- # "Selling price should not be possible to accept an offer lower "
117
- # "than 90% of the expected price",
118
- # )
0 commit comments