forked from OCA/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_gtd.py
167 lines (150 loc) · 6.24 KB
/
project_gtd.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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, osv
from openerp import tools
class project_gtd_context(osv.Model):
_name = "project.gtd.context"
_description = "Context"
_columns = {
'name': fields.char(
'Context', size=64, required=True, translate=True),
'sequence': fields.integer(
'Sequence',
help=("Gives the sequence order when displaying "
"a list of contexts.")),
}
_defaults = {
'sequence': 1
}
_order = "sequence, name"
class project_gtd_timebox(osv.Model):
_name = "project.gtd.timebox"
_order = "sequence"
_columns = {
'name': fields.char(
'Timebox', size=64, required=True, select=1, translate=1),
'sequence': fields.integer(
'Sequence',
help="Gives the sequence order when displaying "
"a list of timebox."),
}
class project_task(osv.Model):
_inherit = "project.task"
_columns = {
'timebox_id': fields.many2one(
'project.gtd.timebox',
"Timebox",
help="Time-laps during which task has to be treated"),
'context_id': fields.many2one(
'project.gtd.context',
"Context",
help="The context place where user has to treat task"),
}
def _get_context(self, cr, uid, context=None):
ids = self.pool.get('project.gtd.context').search(
cr, uid, [], context=context)
return ids and ids[0] or False
def _read_group_timebox_ids(
self, cr, uid, ids, domain,
read_group_order=None, access_rights_uid=None, context=None):
"""Used to display all timeboxes on the view."""
timebox_obj = self.pool.get('project.gtd.timebox')
order = timebox_obj._order
access_rights_uid = access_rights_uid or uid
timebox_ids = timebox_obj._search(
cr, uid, [],
order=order, access_rights_uid=access_rights_uid, context=context)
result = timebox_obj.name_get(
cr, access_rights_uid, timebox_ids, context=context)
# Restore order of the search
result.sort(
lambda x, y: cmp(timebox_ids.index(x[0]), timebox_ids.index(y[0])))
fold = dict.fromkeys(timebox_ids, False)
return result, fold
_defaults = {
'context_id': _get_context
}
_group_by_full = {
'timebox_id': _read_group_timebox_ids,
}
def copy_data(self, cr, uid, id, default=None, context=None):
if context is None:
context = {}
if not default:
default = {}
if not default.get('timebox_id'):
default['timebox_id'] = False
if not default.get('context_id'):
default['context_id'] = False
return super(project_task, self).copy_data(
cr, uid, id, default, context)
def next_timebox(self, cr, uid, ids, *args):
timebox_obj = self.pool.get('project.gtd.timebox')
timebox_ids = timebox_obj.search(cr, uid, [])
if not timebox_ids:
return True
for task in self.browse(cr, uid, ids):
timebox = task.timebox_id
if not timebox:
self.write(cr, uid, task.id, {'timebox_id': timebox_ids[0]})
elif timebox_ids.index(timebox) != len(timebox_ids)-1:
index = timebox_ids.index(timebox)
self.write(
cr, uid, task.id, {'timebox_id': timebox_ids[index+1]})
return True
def prev_timebox(self, cr, uid, ids, *args):
timebox_obj = self.pool.get('project.gtd.timebox')
timebox_ids = timebox_obj.search(cr, uid, [])
for task in self.browse(cr, uid, ids):
timebox = task.timebox_id
if timebox:
if timebox_ids.index(timebox):
index = timebox_ids.index(timebox)
self.write(
cr, uid, task.id,
{'timebox_id': timebox_ids[index - 1]})
else:
self.write(cr, uid, task.id, {'timebox_id': False})
return True
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
if not context:
context = {}
res = super(project_task, self).fields_view_get(
cr, uid, view_id, view_type, context,
toolbar=toolbar, submenu=submenu)
search_extended = False
timebox_obj = self.pool.get('project.gtd.timebox')
if (res['type'] == 'search') and context.get('gtd', False):
timeboxes = timebox_obj.browse(
cr, uid, timebox_obj.search(cr, uid, []), context=context)
search_extended = ''
for timebox in timeboxes:
filter_ = u"""
<filter domain="[('timebox_id', '=', {timebox_id})]"
string="{string}"/>\n
""".format(timebox_id=timebox.id, string=timebox.name)
search_extended += filter_
search_extended += '<separator orientation="vertical"/>'
res['arch'] = tools.ustr(res['arch']).replace(
'<separator name="gtdsep"/>', search_extended)
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: