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.

114 lines
4.4 KiB

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