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.

112 lines
4.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from openerp import api, fields, models
  5. class BaseKanbanAbstract(models.AbstractModel):
  6. '''Inherit from this class to add support for Kanban stages to your model.
  7. All public properties are preceded with kanban_ in order to isolate from
  8. child models, with the exception of stage_id, which is a required field in
  9. the Kanban widget and must be defined as such.'''
  10. _name = 'base.kanban.abstract'
  11. _order = 'kanban_priority desc, kanban_sequence'
  12. _group_by_full = {
  13. 'stage_id': lambda s, *a, **k: s._read_group_stage_ids(*a, **k),
  14. }
  15. kanban_sequence = fields.Integer(
  16. default=10,
  17. index=True,
  18. help='Order of record in relation to other records in the same Kanban'
  19. ' stage and with the same priority',
  20. )
  21. kanban_priority = fields.Selection(
  22. selection=[('0', 'Normal'), ('5', 'Medium'), ('10', 'High')],
  23. index=True,
  24. default='0',
  25. help='The priority of the record (shown as stars in Kanban views)',
  26. )
  27. stage_id = fields.Many2one(
  28. string='Kanban Stage',
  29. comodel_name='base.kanban.stage',
  30. track_visibility='onchange',
  31. index=True,
  32. copy=False,
  33. help='The Kanban stage that this record is currently in',
  34. default=lambda s: s._default_stage_id(),
  35. domain=lambda s: [('res_model.model', '=', s._name)],
  36. )
  37. kanban_user_id = fields.Many2one(
  38. string='Assigned To',
  39. comodel_name='res.users',
  40. index=True,
  41. track_visibility='onchange',
  42. help='User that the record is currently assigned to',
  43. )
  44. kanban_color = fields.Integer(
  45. string='Color Index',
  46. help='Color index to be used for the record\'s Kanban card',
  47. )
  48. kanban_legend_priority = fields.Text(
  49. string='Priority Explanation',
  50. related='stage_id.legend_priority',
  51. help='Explanation text to help users understand how the priority/star'
  52. ' mechanism applies to this record (depends on current stage)',
  53. )
  54. kanban_legend_blocked = fields.Text(
  55. string='Special Handling Explanation',
  56. related='stage_id.legend_blocked',
  57. help='Explanation text to help users understand how the special'
  58. ' handling status applies to this record (depends on current'
  59. ' stage)',
  60. )
  61. kanban_legend_done = fields.Text(
  62. string='Ready Explanation',
  63. related='stage_id.legend_done',
  64. help='Explanation text to help users understand how the ready'
  65. ' status applies to this record (depends on current stage)',
  66. )
  67. kanban_legend_normal = fields.Text(
  68. string='Normal Handling Explanation',
  69. related='stage_id.legend_normal',
  70. help='Explanation text to help users understand how the normal'
  71. ' handling status applies to this record (depends on current'
  72. ' stage)',
  73. )
  74. kanban_status = fields.Selection(
  75. selection=[
  76. ('normal', 'Normal Handling'),
  77. ('done', 'Ready'),
  78. ('blocked', 'Special Handling'),
  79. ],
  80. string='Kanban Status',
  81. default='normal',
  82. track_visibility='onchange',
  83. required=True,
  84. copy=False,
  85. help='A record can have one of several Kanban statuses, which are used'
  86. ' to indicate whether there are any special situations affecting'
  87. ' it. The exact meaning of each status is allowed to vary based'
  88. ' on the stage the record is in but they are roughly as follow:\n'
  89. '* Normal Handling: Default status, no special situations\n'
  90. '* Ready: Ready to transition to the next stage\n'
  91. '* Special Handling: Blocked in some way (e.g. must be handled by'
  92. ' a specific user)\n'
  93. )
  94. @api.model
  95. def _default_stage_id(self):
  96. return self.env['base.kanban.stage']
  97. @api.multi
  98. def _read_group_stage_ids(
  99. self, domain=None, read_group_order=None, access_rights_uid=None
  100. ):
  101. stage_model = self.env['base.kanban.stage'].sudo(access_rights_uid)
  102. stages = stage_model.search([('res_model.model', '=', self._name)])
  103. names = [(r.id, r.display_name) for r in stages]
  104. fold = {r.id: r.fold for r in stages}
  105. return names, fold