1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from openerp.osv import fields, osv
25 from openerp import tools
26 from openerp.tools.translate import _
28 class project_gtd_context(osv.osv):
29 _name = "project.gtd.context"
30 _description = "Context"
32 'name': fields.char('Context', size=64, required=True, select=1, translate=1),
33 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of contexts."),
38 _order = "sequence, name"
42 class project_gtd_timebox(osv.osv):
43 _name = "project.gtd.timebox"
46 'name': fields.char('Timebox', size=64, required=True, select=1, translate=1),
47 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of timebox."),
48 'icon': fields.selection(tools.icons, 'Icon', size=64),
52 class project_task(osv.osv):
53 _inherit = "project.task"
55 'timebox_id': fields.many2one('project.gtd.timebox', "Timebox",help="Time-laps during which task has to be treated"),
56 'context_id': fields.many2one('project.gtd.context', "Context",help="The context place where user has to treat task"),
59 def copy_data(self, cr, uid, id, default=None, context=None):
64 default['timebox_id'] = False
65 default['context_id'] = False
66 return super(project_task,self).copy_data(cr, uid, id, default, context)
68 def _get_context(self, cr, uid, context=None):
69 ids = self.pool.get('project.gtd.context').search(cr, uid, [], context=context)
70 return ids and ids[0] or False
73 'context_id': _get_context
75 def next_timebox(self, cr, uid, ids, *args):
76 timebox_obj = self.pool.get('project.gtd.timebox')
77 timebox_ids = timebox_obj.search(cr,uid,[])
78 if not timebox_ids: return True
79 for task in self.browse(cr,uid,ids):
80 timebox = task.timebox_id.id
82 self.write(cr, uid, task.id, {'timebox_id': timebox_ids[0]})
83 elif timebox_ids.index(timebox) != len(timebox_ids)-1:
84 index = timebox_ids.index(timebox)
85 self.write(cr, uid, task.id, {'timebox_id': timebox_ids[index+1]})
88 def prev_timebox(self, cr, uid, ids, *args):
89 timebox_obj = self.pool.get('project.gtd.timebox')
90 timebox_ids = timebox_obj.search(cr,uid,[])
91 for task in self.browse(cr,uid,ids):
92 timebox = task.timebox_id.id
94 if timebox_ids.index(timebox):
95 index = timebox_ids.index(timebox)
96 self.write(cr, uid, task.id, {'timebox_id': timebox_ids[index - 1]})
98 self.write(cr, uid, task.id, {'timebox_id': False})
101 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
102 if not context: context = {}
103 res = super(project_task,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
104 search_extended = False
105 timebox_obj = self.pool.get('project.gtd.timebox')
106 if (res['type'] == 'search') and context.get('gtd', False):
107 tt = timebox_obj.browse(cr, uid, timebox_obj.search(cr,uid,[]), context=context)
114 search_extended += '''<filter domain="[('timebox_id','=', ''' + str(time.id) + ''')]" icon="''' + icon + '''" string="''' + time.name + '''" context="{'user_invisible': True}"/>\n'''
115 search_extended +='''<separator orientation="vertical"/>'''
117 res['arch'] = tools.ustr(res['arch']).replace('<separator name="gtdsep"/>', search_extended)
122 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: