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.

60 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Guewen Baconnier
  5. # Copyright 2015 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. from openerp import models, fields, api
  22. class RevisionBehavior(models.Model):
  23. _name = 'revision.behavior'
  24. _description = 'Revision Behavior'
  25. _rec_name = 'field_id'
  26. model_id = fields.Many2one(comodel_name='ir.model',
  27. string='Model',
  28. ondelete='cascade',
  29. default=lambda self: self._default_model_id())
  30. field_id = fields.Many2one(comodel_name='ir.model.fields',
  31. string='Field',
  32. ondelete='cascade')
  33. default_behavior = fields.Selection(
  34. selection='_selection_default_behavior',
  35. string='Default Behavior',
  36. help="Auto: always apply a change.\n"
  37. "Validate: manually applied by an administrator.\n"
  38. "Never: change never applied.",
  39. )
  40. @api.model
  41. def _default_model_id(self):
  42. return self.env.ref('base.model_res_partner').id
  43. @api.model
  44. def _selection_default_behavior(self):
  45. return [('auto', 'Auto'),
  46. ('validate', 'Validate'),
  47. ('never', 'Never'),
  48. ]
  49. # TODO: cache
  50. @api.model
  51. def get_rules(self, model_name):
  52. rules = self.search([('model_id', '=', model_name)])
  53. return {rule.field_id.name: rule for rule in rules}