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,24 +142,25 @@ 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:
if not rec.active:
return return
model = self.env[self.model_id.model] model = self.env[rec.model_id.model]
eval_context = self._get_eval_context() eval_context = self._get_eval_context()
domain = self.domain or '[]' domain = rec.domain or '[]'
try: try:
count = model.search_count(eval(domain, eval_context)) count = model.search_count(eval(domain, eval_context))
except Exception as e: except Exception as e:
self.primary_value = self.secondary_value = 'ERR!' rec.primary_value = rec.secondary_value = 'ERR!'
self.error = str(e) rec.error = str(e)
return return
if any([ if any([
self.primary_function and rec.primary_function and
self.primary_function != 'count', rec.primary_function != 'count',
self.secondary_function and rec.secondary_function and
self.secondary_function != 'count' rec.secondary_function != 'count'
]): ]):
records = model.search(eval(domain, eval_context)) records = model.search(eval(domain, eval_context))
for f in ['primary_', 'secondary_']: for f in ['primary_', 'secondary_']:
@ -168,45 +169,47 @@ class TileTile(models.Model):
f_format = f + 'format' f_format = f + 'format'
f_value = f + 'value' f_value = f + 'value'
value = 0 value = 0
if self[f_function] == 'count': if rec[f_function] == 'count':
value = count value = count
elif self[f_function]: elif rec[f_function]:
func = FIELD_FUNCTIONS[self[f_function]]['func'] func = FIELD_FUNCTIONS[rec[f_function]]['func']
if func and self[f_field_id] and count: if func and rec[f_field_id] and count:
vals = [x[self[f_field_id].name] for x in records] vals = [x[rec[f_field_id].name] for x in records]
value = func(vals) value = func(vals)
if self[f_function]: if rec[f_function]:
try: try:
self[f_value] = (self[f_format] or '{:,}').format(value) rec[f_value] = (rec[f_format] or '{:,}').format(value)
except ValueError as e: except ValueError as e:
self[f_value] = 'F_ERR!' rec[f_value] = 'F_ERR!'
self.error = str(e) rec.error = str(e)
return return
else: else:
self[f_value] = False 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 rec in self:
for f in ['primary_', 'secondary_']: for f in ['primary_', 'secondary_']:
f_function = f + 'function' f_function = f + 'function'
f_field_id = f + 'field_id' f_field_id = f + 'field_id'
f_helper = f + 'helper' f_helper = f + 'helper'
self[f_helper] = '' rec[f_helper] = ''
field_func = FIELD_FUNCTIONS.get(self[f_function], {}) field_func = FIELD_FUNCTIONS.get(rec[f_function], {})
help = field_func.get('help', False) help = field_func.get('help', False)
if help: if help:
if self[f_function] != 'count' and self[f_field_id]: if rec[f_function] != 'count' and rec[f_field_id]:
desc = self[f_field_id].field_description desc = rec[f_field_id].field_description
self[f_helper] = help % desc rec[f_helper] = help % desc
else: else:
self[f_helper] = help 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,14 +229,15 @@ 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):
for rec in self:
if any([ if any([
self.primary_field_id and rec.primary_field_id and
self.primary_field_id.model_id.id != self.model_id.id, rec.primary_field_id.model_id.id != rec.model_id.id,
self.secondary_field_id and rec.secondary_field_id and
self.secondary_field_id.model_id.id != self.model_id.id rec.secondary_field_id.model_id.id != rec.model_id.id
]): ]):
raise ValidationError( raise ValidationError(
_("Please select a field from the selected model.")) _("Please select a field from the selected model."))