@@ -46,24 +46,21 @@ class CustomInfoValue(models.Model):
46
46
readonly = True ,
47
47
)
48
48
property_sequence = fields .Integer (
49
- related = "property_id.sequence" , store = True , index = True , readonly = True ,
49
+ related = "property_id.sequence" , store = True , index = True ,
50
50
)
51
51
category_sequence = fields .Integer (
52
52
string = "Category Sequence" ,
53
53
related = "property_id.category_id.sequence" ,
54
54
store = True ,
55
- readonly = True ,
56
- )
57
- category_id = fields .Many2one (
58
- related = "property_id.category_id" , store = True , readonly = True ,
59
55
)
60
- name = fields .Char (related = "property_id.name" , readonly = True )
61
- field_type = fields .Selection (related = "property_id.field_type" , readonly = True ,)
56
+ category_id = fields .Many2one (related = "property_id.category_id" , store = True )
57
+ name = fields .Char (related = "property_id.name" )
58
+ field_type = fields .Selection (related = "property_id.field_type" )
62
59
field_name = fields .Char (
63
60
compute = "_compute_field_name" ,
64
61
help = "Technical name of the field where the value is stored." ,
65
62
)
66
- required = fields .Boolean (related = "property_id.required" , readonly = True )
63
+ required = fields .Boolean (related = "property_id.required" )
67
64
value = fields .Char (
68
65
compute = "_compute_value" ,
69
66
inverse = "_inverse_value" ,
@@ -81,7 +78,6 @@ class CustomInfoValue(models.Model):
81
78
domain = "[('property_ids', '=', property_id)]" ,
82
79
)
83
80
84
- @api .multi
85
81
def check_access_rule (self , operation ):
86
82
"""You access a value if you access its owner record."""
87
83
if self .env .uid != SUPERUSER_ID :
@@ -113,28 +109,24 @@ def _selection_owner_id(self):
113
109
if m .model in self .env and self .env [m .model ]._auto
114
110
]
115
111
116
- @api .multi
117
112
@api .depends ("property_id.field_type" )
118
113
def _compute_field_name (self ):
119
114
"""Get the technical name where the real typed value is stored."""
120
115
for s in self :
121
116
s .field_name = "value_{!s}" .format (s .property_id .field_type )
122
117
123
- @api .multi
124
118
@api .depends ("res_id" , "model" )
125
119
def _compute_owner_id (self ):
126
120
"""Get the id from the linked record."""
127
121
for record in self :
128
122
record .owner_id = "{},{}" .format (record .model , record .res_id )
129
123
130
- @api .multi
131
124
def _inverse_owner_id (self ):
132
125
"""Store the owner according to the model and ID."""
133
126
for record in self .filtered ("owner_id" ):
134
127
record .model = record .owner_id ._name
135
128
record .res_id = record .owner_id .id
136
129
137
- @api .multi
138
130
@api .depends (
139
131
"property_id.field_type" ,
140
132
"field_name" ,
@@ -154,7 +146,6 @@ def _compute_value(self):
154
146
else :
155
147
s .value = getattr (s , s .field_name , False )
156
148
157
- @api .multi
158
149
def _inverse_value (self ):
159
150
"""Write the value correctly converted in the typed field."""
160
151
for record in self :
@@ -168,48 +159,47 @@ def _inverse_value(self):
168
159
record .value , record .field_type , record .property_id ,
169
160
)
170
161
171
- @api .one
172
162
@api .constrains ("property_id" , "value_str" , "value_int" , "value_float" )
173
163
def _check_min_max_limits (self ):
174
164
"""Ensure value falls inside the property's stablished limits."""
175
- minimum , maximum = self .property_id .minimum , self .property_id .maximum
176
- if minimum <= maximum :
177
- value = self [self .field_name ]
178
- if not value :
179
- # This is a job for :meth:`.~_check_required`
180
- return
181
- if self .field_type == "str" :
182
- number = len (self .value_str )
183
- message = _ (
184
- "Length for %(prop)s is %(val)s, but it should be "
185
- "between %(min)d and %(max)d."
186
- )
187
- elif self .field_type in {"int" , "float" }:
188
- number = value
189
- if self .field_type == "int" :
165
+ for record in self :
166
+ minimum , maximum = record .property_id .minimum , record .property_id .maximum
167
+ if minimum <= maximum :
168
+ value = record [record .field_name ]
169
+ if not value :
170
+ # This is a job for :meth:`.~_check_required`
171
+ continue
172
+ if record .field_type == "str" :
173
+ number = len (self .value_str )
190
174
message = _ (
191
- "Value for %(prop)s is %(val)s, but it should be "
175
+ "Length for %(prop)s is %(val)s, but it should be "
192
176
"between %(min)d and %(max)d."
193
177
)
178
+ elif record .field_type in {"int" , "float" }:
179
+ number = value
180
+ if record .field_type == "int" :
181
+ message = _ (
182
+ "Value for %(prop)s is %(val)s, but it should be "
183
+ "between %(min)d and %(max)d."
184
+ )
185
+ else :
186
+ message = _ (
187
+ "Value for %(prop)s is %(val)s, but it should be "
188
+ "between %(min)f and %(max)f."
189
+ )
194
190
else :
195
- message = _ (
196
- "Value for %(prop)s is %(val)s, but it should be "
197
- "between %(min)f and %(max)f."
191
+ continue
192
+ if not minimum <= number <= maximum :
193
+ raise ValidationError (
194
+ message
195
+ % {
196
+ "prop" : record .property_id .display_name ,
197
+ "val" : number ,
198
+ "min" : minimum ,
199
+ "max" : maximum ,
200
+ }
198
201
)
199
- else :
200
- return
201
- if not minimum <= number <= maximum :
202
- raise ValidationError (
203
- message
204
- % {
205
- "prop" : self .property_id .display_name ,
206
- "val" : number ,
207
- "min" : minimum ,
208
- "max" : maximum ,
209
- }
210
- )
211
202
212
- @api .multi
213
203
@api .onchange ("property_id" )
214
204
def _onchange_property_set_default_value (self ):
215
205
"""Load default value for this property."""
0 commit comments