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