3
0
Fork 0

FIX remove api.one

16.0
Nicolas Mac Rouillon 2016-12-13 16:02:54 -03:00 committed by Sylvain LE GAL
parent 31e2d00110
commit 18676f3dbf
1 changed files with 70 additions and 66 deletions

View File

@ -142,71 +142,74 @@ class TileTile(models.Model):
string='Error Details', string='Error Details',
compute='_compute_data') compute='_compute_data')
@api.one @api.multi
def _compute_data(self): def _compute_data(self):
if not self.active: for rec in self:
return if not rec.active:
model = self.env[self.model_id.model] return
eval_context = self._get_eval_context() model = self.env[rec.model_id.model]
domain = self.domain or '[]' eval_context = self._get_eval_context()
try: domain = rec.domain or '[]'
count = model.search_count(eval(domain, eval_context)) try:
except Exception as e: count = model.search_count(eval(domain, eval_context))
self.primary_value = self.secondary_value = 'ERR!' except Exception as e:
self.error = str(e) rec.primary_value = rec.secondary_value = 'ERR!'
return rec.error = str(e)
if any([ return
self.primary_function and if any([
self.primary_function != 'count', rec.primary_function and
self.secondary_function and rec.primary_function != 'count',
self.secondary_function != 'count' rec.secondary_function and
]): rec.secondary_function != 'count'
records = model.search(eval(domain, eval_context)) ]):
for f in ['primary_', 'secondary_']: records = model.search(eval(domain, eval_context))
f_function = f + 'function' for f in ['primary_', 'secondary_']:
f_field_id = f + 'field_id' f_function = f + 'function'
f_format = f + 'format' f_field_id = f + 'field_id'
f_value = f + 'value' f_format = f + 'format'
value = 0 f_value = f + 'value'
if self[f_function] == 'count': value = 0
value = count if rec[f_function] == 'count':
elif self[f_function]: value = count
func = FIELD_FUNCTIONS[self[f_function]]['func'] elif rec[f_function]:
if func and self[f_field_id] and count: func = FIELD_FUNCTIONS[rec[f_function]]['func']
vals = [x[self[f_field_id].name] for x in records] if func and rec[f_field_id] and count:
value = func(vals) vals = [x[rec[f_field_id].name] for x in records]
if self[f_function]: value = func(vals)
try: if rec[f_function]:
self[f_value] = (self[f_format] or '{:,}').format(value) try:
except ValueError as e: rec[f_value] = (rec[f_format] or '{:,}').format(value)
self[f_value] = 'F_ERR!' except ValueError as e:
self.error = str(e) rec[f_value] = 'F_ERR!'
return rec.error = str(e)
else: return
self[f_value] = False else:
rec[f_value] = False
@api.one @api.multi
@api.onchange('primary_function', 'primary_field_id', @api.onchange('primary_function', 'primary_field_id',
'secondary_function', 'secondary_field_id') 'secondary_function', 'secondary_field_id')
def _compute_helper(self): def _compute_helper(self):
for f in ['primary_', 'secondary_']: for rec in self:
f_function = f + 'function' for f in ['primary_', 'secondary_']:
f_field_id = f + 'field_id' f_function = f + 'function'
f_helper = f + 'helper' f_field_id = f + 'field_id'
self[f_helper] = '' f_helper = f + 'helper'
field_func = FIELD_FUNCTIONS.get(self[f_function], {}) rec[f_helper] = ''
help = field_func.get('help', False) field_func = FIELD_FUNCTIONS.get(rec[f_function], {})
if help: help = field_func.get('help', False)
if self[f_function] != 'count' and self[f_field_id]: if help:
desc = self[f_field_id].field_description if rec[f_function] != 'count' and rec[f_field_id]:
self[f_helper] = help % desc desc = rec[f_field_id].field_description
else: rec[f_helper] = help % desc
self[f_helper] = help else:
rec[f_helper] = help
@api.one @api.multi
def _compute_active(self): def _compute_active(self):
ima = self.env['ir.model.access'] ima = self.env['ir.model.access']
self.active = ima.check(self.model_id.model, 'read', False) for rec in self:
rec.active = ima.check(rec.model_id.model, 'read', False)
def _search_active(self, operator, value): def _search_active(self, operator, value):
cr = self.env.cr cr = self.env.cr
@ -226,17 +229,18 @@ class TileTile(models.Model):
return [('id', 'in', ids)] return [('id', 'in', ids)]
# Constraints and onchanges # Constraints and onchanges
@api.one @api.multi
@api.constrains('model_id', 'primary_field_id', 'secondary_field_id') @api.constrains('model_id', 'primary_field_id', 'secondary_field_id')
def _check_model_id_field_id(self): def _check_model_id_field_id(self):
if any([ for rec in self:
self.primary_field_id and if any([
self.primary_field_id.model_id.id != self.model_id.id, rec.primary_field_id and
self.secondary_field_id and rec.primary_field_id.model_id.id != rec.model_id.id,
self.secondary_field_id.model_id.id != self.model_id.id rec.secondary_field_id and
]): rec.secondary_field_id.model_id.id != rec.model_id.id
raise ValidationError( ]):
_("Please select a field from the selected model.")) raise ValidationError(
_("Please select a field from the selected model."))
@api.onchange('model_id') @api.onchange('model_id')
def _onchange_model_id(self): def _onchange_model_id(self):