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.

49 lines
1.9 KiB

  1. # Copyright 2019 Eficent Business and IT Consulting Services S.L.
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import UserError
  5. class IrModel(models.Model):
  6. _inherit = 'ir.model'
  7. is_kanban = fields.Boolean(
  8. string="Kanban", default=False,
  9. help="Whether this model support kanban stages.",
  10. )
  11. @api.multi
  12. def write(self, vals):
  13. if self and 'is_kanban' in vals:
  14. if not all(rec.state == 'manual' for rec in self):
  15. raise UserError(_('Only custom models can be modified.'))
  16. if not all(rec.is_kanban <= vals['is_kanban'] for rec in self):
  17. raise UserError(
  18. _('Field "Kanban" cannot be changed to "False".'))
  19. res = super(IrModel, self).write(vals)
  20. # setup models; this reloads custom models in registry
  21. self.pool.setup_models(self._cr)
  22. # update database schema of models
  23. models = self.pool.descendants(self.mapped('model'), '_inherits')
  24. self.pool.init_models(self._cr, models, dict(
  25. self._context, update_custom_fields=True))
  26. else:
  27. res = super(IrModel, self).write(vals)
  28. return res
  29. def _reflect_model_params(self, model):
  30. vals = super(IrModel, self)._reflect_model_params(model)
  31. vals['is_kanban'] = issubclass(
  32. type(model), self.pool['base.kanban.abstract'])
  33. return vals
  34. @api.model
  35. def _instanciate(self, model_data):
  36. model_class = super(IrModel, self)._instanciate(model_data)
  37. if model_data.get('is_kanban') and \
  38. model_class._name != 'base.kanban.abstract':
  39. parents = model_class._inherit or []
  40. parents = [parents] if isinstance(parents, (str,)) else parents
  41. model_class._inherit = parents + ['base.kanban.abstract']
  42. return model_class