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.

111 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 odoo 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, and user_id, which is a
  10. special field that has special treatment in some places (such as the
  11. mail module).
  12. """
  13. _name = 'base.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. kanban_sequence = fields.Integer(
  19. default=10,
  20. index=True,
  21. help='Order of record in relation to other records in the same Kanban'
  22. ' stage and with the same priority',
  23. )
  24. kanban_priority = fields.Selection(
  25. selection=[('0', 'Normal'), ('1', 'Medium'), ('2', 'High')],
  26. index=True,
  27. default='0',
  28. help='The priority of the record (shown as stars in Kanban views)',
  29. )
  30. stage_id = fields.Many2one(
  31. string='Kanban Stage',
  32. comodel_name='base.kanban.stage',
  33. track_visibility='onchange',
  34. index=True,
  35. copy=False,
  36. help='The Kanban stage that this record is currently in',
  37. default=lambda s: s._default_stage_id(),
  38. domain=lambda s: [('res_model_id.model', '=', s._name)],
  39. group_expand='_read_group_stage_ids',
  40. )
  41. user_id = fields.Many2one(
  42. string='Assigned To',
  43. comodel_name='res.users',
  44. index=True,
  45. track_visibility='onchange',
  46. help='User that the record is currently assigned to',
  47. )
  48. kanban_color = fields.Integer(
  49. string='Color Index',
  50. help='Color index to be used for the record\'s Kanban card',
  51. )
  52. kanban_legend_priority = fields.Text(
  53. string='Priority Explanation',
  54. related='stage_id.legend_priority',
  55. help='Explanation text to help users understand how the priority/star'
  56. ' mechanism applies to this record (depends on current stage)',
  57. )
  58. kanban_legend_blocked = fields.Text(
  59. string='Special Handling Explanation',
  60. related='stage_id.legend_blocked',
  61. help='Explanation text to help users understand how the special'
  62. ' handling status applies to this record (depends on current'
  63. ' stage)',
  64. )
  65. kanban_legend_done = fields.Text(
  66. string='Ready Explanation',
  67. related='stage_id.legend_done',
  68. help='Explanation text to help users understand how the ready'
  69. ' status applies to this record (depends on current stage)',
  70. )
  71. kanban_legend_normal = fields.Text(
  72. string='Normal Handling Explanation',
  73. related='stage_id.legend_normal',
  74. help='Explanation text to help users understand how the normal'
  75. ' handling status applies to this record (depends on current'
  76. ' stage)',
  77. )
  78. kanban_status = fields.Selection(
  79. selection=[
  80. ('normal', 'Normal Handling'),
  81. ('done', 'Ready'),
  82. ('blocked', 'Special Handling'),
  83. ],
  84. string='Kanban Status',
  85. default='normal',
  86. track_visibility='onchange',
  87. required=True,
  88. copy=False,
  89. help='A record can have one of several Kanban statuses, which are used'
  90. ' to indicate whether there are any special situations affecting'
  91. ' it. The exact meaning of each status is allowed to vary based'
  92. ' on the stage the record is in but they are roughly as follow:\n'
  93. '* Normal Handling: Default status, no special situations\n'
  94. '* Ready: Ready to transition to the next stage\n'
  95. '* Special Handling: Blocked in some way (e.g. must be handled by'
  96. ' a specific user)\n'
  97. )
  98. @api.model
  99. def _default_stage_id(self):
  100. return self.env['base.kanban.stage']
  101. @api.multi
  102. def _read_group_stage_ids(self, stages, domain, order):
  103. search_domain = [('res_model_id.model', '=', self._name)]
  104. return stages.search(search_domain, order=order)