Browse Source

bring back active field

pull/405/head
Iván Todorovich 8 years ago
parent
commit
5dfe528404
  1. 30
      web_dashboard_tile/models/tile_tile.py

30
web_dashboard_tile/models/tile_tile.py

@ -11,7 +11,7 @@ from dateutil.relativedelta import relativedelta
from openerp import api, fields, models from openerp import api, fields, models
from openerp.tools.safe_eval import safe_eval as eval from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.exceptions import ValidationError
from openerp.exceptions import ValidationError, except_orm
class TileTile(models.Model): class TileTile(models.Model):
@ -67,10 +67,16 @@ class TileTile(models.Model):
" ('ttype', 'in', ['float', 'int'])]") " ('ttype', 'in', ['float', 'int'])]")
helper = fields.Char(compute='_compute_function_helper') helper = fields.Char(compute='_compute_function_helper')
active = fields.Boolean(
compute='_compute_active',
search='_search_active',
readonly=True)
@api.one @api.one
def _compute_data(self): def _compute_data(self):
self.count = 0 self.count = 0
self.computed_value = 0 self.computed_value = 0
if self.active:
# Compute count item # Compute count item
model = self.env[self.model_id.model] model = self.env[self.model_id.model]
eval_context = self._get_eval_context() eval_context = self._get_eval_context()
@ -105,6 +111,28 @@ class TileTile(models.Model):
} }
self.helper = _(helpers.get(self.field_function, '')) % desc self.helper = _(helpers.get(self.field_function, '')) % desc
@api.one
def _compute_active(self):
ima = self.env['ir.model.access']
self.active = ima.check(self.model_id.model, 'read', False)
def _search_active(self, operator, value):
cr = self.env.cr
if operator != '=':
raise except_orm(
_('Unimplemented Feature. Search on Active field disabled.'))
ima = self.env['ir.model.access']
ids = []
cr.execute("""
SELECT tt.id, im.model
FROM tile_tile tt
INNER JOIN ir_model im
ON tt.model_id = im.id""")
for result in cr.fetchall():
if (ima.check(result[1], 'read', False) == value):
ids.append(result[0])
return [('id', 'in', ids)]
# Constraints and onchanges # Constraints and onchanges
@api.one @api.one
@api.constrains('model_id', 'field_id') @api.constrains('model_id', 'field_id')

Loading…
Cancel
Save