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.

38 lines
1.3 KiB

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