forked from Techsystech/web
[IMP][8.0][web_dashboard_tile] Refactor (see changes in description) (#476)
Conflicts: web_dashboard_tile/__openerp__.py web_dashboard_tile/models/tile_tile.py9.0
parent
fb3f97df0e
commit
6524ddcbd4
|
@ -142,70 +142,68 @@ class TileTile(models.Model):
|
||||||
string='Error Details',
|
string='Error Details',
|
||||||
compute='_compute_data')
|
compute='_compute_data')
|
||||||
|
|
||||||
@api.multi
|
@api.one
|
||||||
def _compute_data(self):
|
def _compute_data(self):
|
||||||
|
if not self.active:
|
||||||
|
return
|
||||||
|
model = self.env[self.model_id.model]
|
||||||
eval_context = self._get_eval_context()
|
eval_context = self._get_eval_context()
|
||||||
for rec in self:
|
domain = self.domain or '[]'
|
||||||
if not rec.active:
|
try:
|
||||||
return
|
count = model.search_count(eval(domain, eval_context))
|
||||||
domain = rec.domain or '[]'
|
except Exception as e:
|
||||||
model = rec.env[rec.model_id.model]
|
self.primary_value = self.secondary_value = 'ERR!'
|
||||||
try:
|
self.error = str(e)
|
||||||
count = model.search_count(eval(domain, eval_context))
|
return
|
||||||
except Exception as e:
|
if any([
|
||||||
rec.primary_value = rec.secondary_value = 'ERR!'
|
self.primary_function and
|
||||||
rec.error = str(e)
|
self.primary_function != 'count',
|
||||||
return
|
self.secondary_function and
|
||||||
if any([
|
self.secondary_function != 'count'
|
||||||
rec.primary_function and
|
]):
|
||||||
rec.primary_function != 'count',
|
records = model.search(eval(domain, eval_context))
|
||||||
rec.secondary_function and
|
for f in ['primary_', 'secondary_']:
|
||||||
rec.secondary_function != 'count'
|
f_function = f + 'function'
|
||||||
]):
|
f_field_id = f + 'field_id'
|
||||||
records = model.search(eval(domain, eval_context))
|
f_format = f + 'format'
|
||||||
for f in ['primary_', 'secondary_']:
|
f_value = f + 'value'
|
||||||
f_function = f + 'function'
|
value = 0
|
||||||
f_field_id = f + 'field_id'
|
if self[f_function] == 'count':
|
||||||
f_format = f + 'format'
|
value = count
|
||||||
f_value = f + 'value'
|
elif self[f_function]:
|
||||||
value = 0
|
func = FIELD_FUNCTIONS[self[f_function]]['func']
|
||||||
if rec[f_function] == 'count':
|
if func and self[f_field_id] and count:
|
||||||
value = count
|
vals = [x[self[f_field_id].name] for x in records]
|
||||||
elif rec[f_function]:
|
value = func(vals)
|
||||||
func = FIELD_FUNCTIONS[rec[f_function]]['func']
|
if self[f_function]:
|
||||||
if func and rec[f_field_id] and count:
|
try:
|
||||||
vals = [x[rec[f_field_id].name] for x in records]
|
self[f_value] = (self[f_format] or '{:,}').format(value)
|
||||||
value = func(vals)
|
except ValueError as e:
|
||||||
if rec[f_function]:
|
self[f_value] = 'F_ERR!'
|
||||||
try:
|
self.error = str(e)
|
||||||
rec[f_value] = (rec[f_format] or '{:,}').format(value)
|
return
|
||||||
except ValueError as e:
|
else:
|
||||||
rec[f_value] = 'F_ERR!'
|
self[f_value] = False
|
||||||
rec.error = str(e)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
rec[f_value] = False
|
|
||||||
|
|
||||||
@api.multi
|
@api.one
|
||||||
@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.multi
|
@api.one
|
||||||
def _compute_active(self):
|
def _compute_active(self):
|
||||||
ima = self.env['ir.model.access']
|
ima = self.env['ir.model.access']
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
|
|
@ -56,4 +56,4 @@
|
||||||
|
|
||||||
.openerp .oe_searchview_drawer .oe_opened .oe_dashboard_tile_form {
|
.openerp .oe_searchview_drawer .oe_opened .oe_dashboard_tile_form {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue