You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Guewen Baconnier (Camptocamp SA)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, models
  5. class IrModel(models.Model):
  6. _inherit = 'ir.model'
  7. @api.multi
  8. def _compute_has_an_active_field(self):
  9. for model in self:
  10. active_fields = self.env['ir.model.fields'].search(
  11. [('model_id', '=', model.id),
  12. ('name', '=', 'active'),
  13. ],
  14. limit=1)
  15. model.has_an_active_field = bool(active_fields)
  16. @api.model
  17. def _search_has_an_active_field(self, operator, value):
  18. if operator not in ['=', '!=']:
  19. raise AssertionError('operator %s not allowed' % operator)
  20. fields_model = self.env['ir.model.fields']
  21. domain = []
  22. active_fields = fields_model.search(
  23. [('name', '=', 'active')])
  24. models = active_fields.mapped('model_id')
  25. if operator == '=' and value or operator == '!=' and not value:
  26. domain.append(('id', 'in', models.ids))
  27. else:
  28. domain.append(('id', 'not in', models.ids))
  29. return domain
  30. has_an_active_field = fields.Boolean(
  31. compute=_compute_has_an_active_field,
  32. search=_search_has_an_active_field,
  33. string='Has an active field',
  34. )