1
-
2
-
3
-
4
-
5
- # offers model that will offer us the offers
6
-
1
+ # offers model that will offer us the offers
7
2
8
3
9
4
from odoo import fields , models , api
14
9
15
10
16
11
class EstatePropertyOffer (models .Model ):
17
- _name = ' estate.property.offer'
18
- _description = ' Offer model for the properties of real estate'
12
+ _name = " estate.property.offer"
13
+ _description = " Offer model for the properties of real estate"
19
14
price = fields .Float ()
20
15
status = fields .Selection (
21
- selection = [(' accepted' , ' Accepted' ), (' refused' , ' Refused ' )],
22
- string = ' Status' ,
23
- copy = False
16
+ selection = [(" accepted" , " Accepted" ), (" refused" , " Refused " )],
17
+ string = " Status" ,
18
+ copy = False ,
24
19
)
25
20
26
- partner_id = fields .Many2one ('res.partner' , string = 'Partner' )
21
+ partner_id = fields .Many2one ("res.partner" , string = "Partner" )
22
+
23
+ property_id = fields .Many2one ("estate.property" , string = "Property" )
27
24
28
- property_id = fields .Many2one ('estate.property' , string = 'Property' )
25
+ property_type_id = fields .Many2one (
26
+ "estate.property.type" ,
27
+ related = "property_id.property_type_id" ,
28
+ store = True ,
29
+ readonly = False ,
30
+ )
29
31
30
- property_type_id = fields .Many2one ("estate.property.type" , related = "property_id.property_type_id" ,store = True ,readonly = False )
31
-
32
- validity = fields .Integer (default = 7 )
32
+ validity = fields .Integer (default = 7 )
33
33
34
- date_deadline = fields .Date (compute = '_compute_offer_deadline' , inverse = '_deadline_update' )
34
+ date_deadline = fields .Date (
35
+ compute = "_compute_offer_deadline" , inverse = "_deadline_update"
36
+ )
35
37
36
-
37
38
# constrains of sql
38
39
39
- _sql_constraints = [('check_price' , 'CHECK(price > 0)' , 'Offered price must be strictly positive' )
40
+ _sql_constraints = [
41
+ ("check_price" , "CHECK(price > 0)" , "Offered price must be strictly positive" )
40
42
]
41
-
42
- # order in which data is fetched
43
-
44
- _order = "price desc"
45
43
44
+ # order in which data is fetched
46
45
46
+ _order = "price desc"
47
47
48
48
# deadline will be computed based upon the validity date
49
- @api .depends (' validity' )
49
+ @api .depends (" validity" )
50
50
def _compute_offer_deadline (self ):
51
51
for offer in self :
52
52
if not offer .create_date :
53
- offer .date_deadline = datetime .now () + relativedelta (days = (offer .validity or 0 ))
53
+ offer .date_deadline = datetime .now () + relativedelta (
54
+ days = (offer .validity or 0 )
55
+ )
54
56
return
55
57
56
- offer .date_deadline = offer .create_date + relativedelta (days = (offer .validity or 0 ))
57
-
58
+ offer .date_deadline = offer .create_date + relativedelta (
59
+ days = (offer .validity or 0 )
60
+ )
58
61
59
62
# deadline date can also be changed and once this is saved validity will be updated
60
63
def _deadline_update (self ):
61
64
for offer in self :
62
- offer .validity = (offer .date_deadline - (offer .create_date or datetime .now ()).date ()).days
63
-
65
+ offer .validity = (
66
+ offer .date_deadline - (offer .create_date or datetime .now ()).date ()
67
+ ).days
64
68
65
- # action for the accepting the offer
69
+ # action for the accepting the offer
66
70
def action_offer_confirm (self ):
67
71
for record in self :
68
- # since saling price is only updated when offer is accepted therefore it validates if offer
72
+ # since saling price is only updated when offer is accepted therefore it validates if offer
69
73
# is already accepted than warning
70
74
71
- if record .property_id .selling_price > 0 :
72
- raise UserError (' Offer price already accepted for the property' )
75
+ if record .property_id .selling_price > 0 :
76
+ raise UserError (" Offer price already accepted for the property" )
73
77
74
- record .status = ' accepted'
78
+ record .status = " accepted"
75
79
record .property_id .selling_price = self .price
76
80
record .property_id .partner_id = record .partner_id
77
- record .property_id .state = ' offer_accepted'
81
+ record .property_id .state = " offer_accepted"
78
82
79
83
# action for the refusal of the status
80
84
def action_offer_refuse (self ):
81
-
82
85
for record in self :
83
- if ( record .status == ' accepted' ):
86
+ if record .status == " accepted" :
84
87
record .property_id .selling_price = 0
85
- record .property_id .partner_id = ''
86
- record .status = ' refused'
88
+ record .property_id .partner_id = ""
89
+ record .status = " refused"
87
90
88
-
89
-
90
91
# now in case of offer creation CRUD
91
- # self will be a proxy object ,
92
- # property_id feilds is available in vals
92
+ # self will be a proxy object ,
93
+ # property_id feilds is available in vals
93
94
@api .model_create_multi
94
95
def create (self , vals ):
95
-
96
96
# will check the offer value and does property has other offers which are max thw\an this one
97
- for value in vals :
98
- property_details = self .env ['estate.property' ].browse (value .get ('property_id' ))
97
+ for value in vals :
98
+ property_details = self .env ["estate.property" ].browse (
99
+ value .get ("property_id" )
100
+ )
99
101
for property_data in property_details :
100
102
offers_list = property_data .mapped ("offer_ids.price" )
101
103
max_offer = max (offers_list , default = 0 )
102
- comparison_result = float_compare (value .get ('price' ),max_offer , precision_digits = 2 )
103
-
104
- if comparison_result == - 1 :
105
- raise UserError ('Offer with a lower amount than an existing offer' )
104
+ comparison_result = float_compare (
105
+ value .get ("price" ), max_offer , precision_digits = 2
106
+ )
107
+
108
+ if comparison_result == - 1 :
109
+ raise UserError ("Offer with a lower amount than an existing offer" )
110
+
111
+ if property_data .state == "new" :
112
+ property_data .state = "offer_received"
106
113
107
114
return super ().create (vals )
108
-
0 commit comments