1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
26 from mx import DateTime
27 from mx.DateTime import now
31 from osv import fields, osv
35 class one2many_mod(fields.one2many):
36 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
41 for obj in obj.browse(cr, user, ids, context=context):
43 v = getattr(obj,'context'+num+'_id').id
45 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'=',obj.id),('context_id','=',v)], limit=self._limit)
46 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
47 res[r[self._fields_id]].append( r['id'] )
50 class project_gtd_context(osv.osv):
51 _name = "project.gtd.context"
53 'name': fields.char('Context', size=64, required=True, select=1),
54 'sequence': fields.integer('Sequence'),
55 'project_default_id': fields.many2one('project.project', 'Default Project', required=True),
58 'sequence': lambda *args: 1
60 _order = "sequence, name"
64 class project_gtd_timebox(osv.osv):
65 _name = "project.gtd.timebox"
67 'name': fields.char('Timebox', size=64, required=True, select=1),
68 'user_id': fields.many2one('res.users', 'User', required=True, select=1),
69 'child_ids': fields.one2many('project.gtd.timebox', 'parent_id', 'Child Timeboxes'),
70 'parent_id': fields.many2one('project.gtd.timebox', 'Parent Timebox'),
71 'task_ids': fields.one2many('project.task', 'timebox_id', 'Tasks'),
72 'type': fields.selection([('daily','Daily'),('weekly','Weekly'),('monthly','Monthly'),('other','Other')], 'Type', required=True),
73 'task1_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
74 'task2_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
75 'task3_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
76 'task4_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
77 'task5_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
78 'task6_ids': one2many_mod('project.task', 'timebox_id', 'Tasks'),
79 'context1_id': fields.many2one('project.gtd.context', 'Context 1', required=True),
80 'context2_id': fields.many2one('project.gtd.context', 'Context 2'),
81 'context3_id': fields.many2one('project.gtd.context', 'Context 3'),
82 'context4_id': fields.many2one('project.gtd.context', 'Context 4'),
83 'context5_id': fields.many2one('project.gtd.context', 'Context 5'),
84 'context6_id': fields.many2one('project.gtd.context', 'Context 6'),
85 'col_project': fields.boolean('Project'),
86 'col_date_start': fields.boolean('Date Start'),
87 'col_priority': fields.boolean('Priority'),
88 'col_deadline': fields.boolean('Deadline'),
89 'col_planned_hours': fields.boolean('Planned Hours'),
90 'col_effective_hours': fields.boolean('Effective Hours'),
92 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False):
93 res = super(project_gtd_timebox,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar)
94 if (res['type']=='form') and ('record_id' in context):
95 if context['record_id']:
96 rec = self.browse(cr, uid, int(context['record_id']), context)
98 iids = self.search(cr,uid, [('user_id','=',uid),('parent_id','=',False)], context=context)
100 rec = self.browse(cr, uid, int(iids[0]), context=context)
104 <form string="Daily Timebox">
105 <field name="name" readonly="1"/>
106 <notebook position="top">
109 if not getattr(rec, 'context%d_id'%i):
113 <field name="%s" colspan="4" nolabel="1">
114 <tree editable="bottom" colors="grey:state in ('done','pending');red:state=='cancelled'" string="Tasks">
116 """ % (getattr(rec, 'context%d_id'%(i,)).name.encode('utf-8'), 'task%d_ids'%(i,))
118 res['arch'] += '<field name="project_id" required="1"/>\n'
119 if rec.col_date_start:
120 res['arch'] += '<field name="date_start"/>\n'
122 res['arch'] += '<field name="priority"/>\n'
124 res['arch'] += '<field name="date_deadline"/>\n'
125 if rec.col_planned_hours:
126 res['arch'] += '<field name="planned_hours" widget="float_time" sum="Est. Hours"/>\n'
127 if rec.col_effective_hours:
128 res['arch'] += '<field name="effective_hours" widget="float_time" sum="Eff. Hours"/>\n'
130 <field name="state" readonly="1"/>
140 doc = dom.minidom.parseString(res['arch'])
141 xarch, xfields = self._view_look_dom_arch(cr, uid, doc, view_id, context=context)
143 res['fields'] = xfields
146 'type': lambda *args: 'daily',
147 'col_project': lambda *args: True,
148 'col_date_start': lambda *args: True,
149 'col_priority': lambda *args: True,
150 'col_deadline': lambda *args: False,
151 'col_planned_hours': lambda *args: True,
152 'col_effective_hours': lambda *args: False
154 project_gtd_timebox()
156 class project_task(osv.osv):
157 _inherit = "project.task"
159 'timebox_id': fields.many2one('project.gtd.timebox', "Timebox"),
160 'context_id': fields.many2one('project.gtd.context', "Context"),
162 def copy_data(self, cr, uid, id, default=None, context=None):
165 default['timebox_id']=False
166 default['context_id']=False
167 return super(project_task,self).copy_data(cr, uid, id, default, context)
168 def _get_context(self,cr, uid, ctx):
169 ids = self.pool.get('project.gtd.context').search(cr, uid, [], context=ctx)
170 return ids and ids[0] or False
172 'context_id': _get_context
174 # Override read for using this method if context set !!!
175 #_order = "((55-ascii(coalesce(priority,'2')))*2 + coalesce((date_start::date-current_date)/2,8))"
178 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: