1
- from odoo import api , models , fields
2
- from odoo .exceptions import UserError , ValidationError
3
1
from dateutil .relativedelta import relativedelta
4
2
3
+ from odoo import _ , api , models , fields
4
+ from odoo .exceptions import UserError , ValidationError
5
5
from odoo .tools .float_utils import float_compare , float_is_zero
6
6
7
7
@@ -22,7 +22,7 @@ class EstateProperty(models.Model):
22
22
postcode = fields .Char ()
23
23
date_availability = fields .Date (
24
24
copy = False ,
25
- default = _default_date_availability ()
25
+ default = _default_date_availability
26
26
)
27
27
state = fields .Selection (
28
28
string = 'Status' ,
@@ -70,46 +70,46 @@ def group_by_empty(self, types, domain):
70
70
return types .search ([]) # this is equivalent to return self.env['estate.property.type'].search([])
71
71
72
72
def action_set_sold (self ):
73
- for record in self :
74
- if record .state == 'cancelled' :
75
- raise UserError ("Canceled properties cannot be set as sold." )
76
- record .state = 'sold'
73
+ for property in self :
74
+ if property .state == 'cancelled' :
75
+ raise UserError (_ ( "Canceled properties cannot be set as sold." ) )
76
+ property .state = 'sold'
77
77
return True
78
78
79
79
def action_cancel (self ):
80
- for record in self :
81
- if record .state == 'sold' :
82
- raise UserError ("Sold properties cannot be canceled." )
83
- record .state = 'cancelled'
80
+ for property in self :
81
+ if property .state == 'sold' :
82
+ raise UserError (_ ( "Sold properties cannot be canceled." ) )
83
+ property .state = 'cancelled'
84
84
return True
85
85
86
86
@api .ondelete (at_uninstall = False )
87
87
def _check_unlink_state (self ):
88
- for record in self :
89
- if record .state not in ('new' , 'cancelled' ):
90
- raise UserError ("You cannot delete a property that is not in 'New' or 'Cancelled' state." )
88
+ for property in self :
89
+ if property .state not in ('new' , 'cancelled' ):
90
+ raise UserError (_ ( "You cannot delete a property that is not in 'New' or 'Cancelled' state." ) )
91
91
92
92
@api .constrains ('expected_price' , 'selling_price' )
93
93
def _check_selling_price (self ):
94
- for record in self :
95
- if not float_is_zero (record .expected_price , precision_digits = 2 ):
96
- accepted_offers = record .offers_ids .filtered (lambda o : o .status == 'accepted' )
94
+ for property in self :
95
+ if not float_is_zero (property .expected_price , precision_digits = 2 ):
96
+ accepted_offers = property .offers_ids .filtered (lambda o : o .status == 'accepted' )
97
97
if accepted_offers :
98
- if float_compare (record .selling_price , record .expected_price * 0.90 , precision_digits = 2 ) == - 1 :
98
+ if float_compare (property .selling_price , property .expected_price * 0.90 , precision_digits = 2 ) == - 1 :
99
99
raise ValidationError ("Selling price cannot be lower than 90 percent of expected price" )
100
100
101
101
@api .depends ('living_area' , 'garden_area' )
102
102
def _compute_total_area (self ):
103
- for record in self :
104
- record .total_area = record .living_area + record .garden_area
103
+ for property in self :
104
+ property .total_area = property .living_area + property .garden_area
105
105
106
106
@api .depends ('offers_ids.price' )
107
107
def _compute_best_price (self ):
108
- for record in self :
109
- if record .offers_ids :
110
- record .best_price = max (record .offers_ids .mapped ('price' ))
108
+ for property in self :
109
+ if property .offers_ids :
110
+ property .best_price = max (property .offers_ids .mapped ('price' ))
111
111
else :
112
- record .best_price = 0.0
112
+ property .best_price = 0.0
113
113
114
114
@api .onchange ('garden' )
115
115
def _onchange_garden (self ):
0 commit comments