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.

86 lines
3.4 KiB

11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2013 Daniel Reis
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp.osv import fields, orm
  21. class SLADefinition(orm.Model):
  22. """
  23. SLA Definition
  24. """
  25. _name = 'project.sla'
  26. _description = 'SLA Definition'
  27. _columns = {
  28. 'name': fields.char('Title', size=64, required=True, translate=True),
  29. 'active': fields.boolean('Active'),
  30. 'control_model': fields.char('For documents', size=128, required=True),
  31. 'control_field_id': fields.many2one(
  32. 'ir.model.fields', 'Control Date', required=True,
  33. domain="[('model_id.model', '=', control_model),"
  34. " ('ttype', 'in', ['date', 'datetime'])]",
  35. help="Date field used to check if the SLA was achieved."),
  36. 'sla_line_ids': fields.one2many(
  37. 'project.sla.line', 'sla_id', 'Definitions'),
  38. 'analytic_ids': fields.many2many(
  39. 'account.analytic.account', string='Contracts'),
  40. }
  41. _defaults = {
  42. 'active': True,
  43. }
  44. def _reapply_slas(self, cr, uid, ids, recalc_closed=False, context=None):
  45. """
  46. Force SLA recalculation on all _open_ Contracts for the selected SLAs.
  47. To use upon SLA Definition modifications.
  48. """
  49. contract_obj = self.pool.get('account.analytic.account')
  50. for sla in self.browse(cr, uid, ids, context=context):
  51. contr_ids = [x.id for x in sla.analytic_ids if x.state == 'open']
  52. contract_obj._reapply_sla(
  53. cr, uid, contr_ids, recalc_closed=recalc_closed,
  54. context=context)
  55. return True
  56. def reapply_slas(self, cr, uid, ids, context=None):
  57. """ Reapply SLAs button action """
  58. return self._reapply_slas(cr, uid, ids, context=context)
  59. class SLARules(orm.Model):
  60. """
  61. SLA Definition Rule Lines
  62. """
  63. _name = 'project.sla.line'
  64. _definition = 'SLA Definition Rule Lines'
  65. _order = 'sla_id,sequence'
  66. _columns = {
  67. 'sla_id': fields.many2one('project.sla', 'SLA Definition'),
  68. 'sequence': fields.integer('Sequence'),
  69. 'name': fields.char('Title', size=64, required=True, translate=True),
  70. 'condition': fields.char(
  71. 'Condition', size=256, help="Apply only if this expression is "
  72. "evaluated to True. The document fields can be accessed using "
  73. "either o, obj or object. Example: obj.priority <= '2'"),
  74. 'limit_qty': fields.integer('Hours to Limit'),
  75. 'warn_qty': fields.integer('Hours to Warn'),
  76. }
  77. _defaults = {
  78. 'sequence': 10,
  79. }