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 ##############################################################################
21 from osv import fields, osv
22 from tools.translate import _
26 from datetime import datetime
27 from dateutil.relativedelta import relativedelta
29 class project_scrum_project(osv.osv):
30 _inherit = 'project.project'
32 'product_owner_id': fields.many2one('res.users', 'Product Owner', help="The person who is responsible for the product"),
33 'sprint_size': fields.integer('Sprint Days', help="Number of days allocated for sprint"),
34 'scrum': fields.integer('Is a Scrum Project'),
37 'product_owner_id': lambda self, cr, uid, context={}: uid,
41 project_scrum_project()
43 class project_scrum_sprint(osv.osv):
44 _name = 'project.scrum.sprint'
45 _description = 'Project Scrum Sprint'
46 _order = 'date_start desc'
47 def _compute(self, cr, uid, ids, fields, arg, context=None):
48 res = {}.fromkeys(ids, 0.0)
54 for sprint in self.browse(cr, uid, ids, context=context):
59 for bl in sprint.backlog_ids:
60 tot += bl.expected_hours
61 effective += bl.effective_hours
62 prog += bl.expected_hours * bl.progress / 100.0
64 progress = round(prog/tot*100)
66 'progress' : progress,
67 'expected_hours' : tot,
68 'effective_hours': effective,
72 def button_cancel(self, cr, uid, ids, context=None):
73 self.write(cr, uid, ids, {'state':'cancel'}, context=context)
76 def button_draft(self, cr, uid, ids, context=None):
77 self.write(cr, uid, ids, {'state':'draft'}, context=context)
80 def button_open(self, cr, uid, ids, context=None):
81 self.write(cr, uid, ids, {'state':'open'}, context=context)
82 for (id, name) in self.name_get(cr, uid, ids):
83 message = _("The sprint '%s' has been opened.") % (name,)
84 self.log(cr, uid, id, message)
87 def button_close(self, cr, uid, ids, context=None):
88 self.write(cr, uid, ids, {'state':'done'}, context=context)
89 for (id, name) in self.name_get(cr, uid, ids):
90 message = _("The sprint '%s' has been closed.") % (name,)
91 self.log(cr, uid, id, message)
94 def button_pending(self, cr, uid, ids, context=None):
95 self.write(cr, uid, ids, {'state':'pending'}, context=context)
99 'name' : fields.char('Sprint Name', required=True, size=64),
100 'date_start': fields.date('Starting Date', required=True),
101 'date_stop': fields.date('Ending Date', required=True),
102 'project_id': fields.many2one('project.project', 'Project', required=True, domain=[('scrum','=',1)], help="If you have [?] in the project name, it means there are no analytic account linked to this project."),
103 'product_owner_id': fields.many2one('res.users', 'Product Owner', required=True,help="The person who is responsible for the product"),
104 'scrum_master_id': fields.many2one('res.users', 'Scrum Master', required=True,help="The person who is maintains the processes for the product"),
105 'meeting_ids': fields.one2many('project.scrum.meeting', 'sprint_id', 'Daily Scrum'),
106 'review': fields.text('Sprint Review'),
107 'retrospective': fields.text('Sprint Retrospective'),
108 'backlog_ids': fields.one2many('project.scrum.product.backlog', 'sprint_id', 'Sprint Backlog'),
109 'progress': fields.function(_compute, group_operator="avg", type='float', multi="progress", string='Progress (0-100)', help="Computed as: Time Spent / Total Time."),
110 'effective_hours': fields.function(_compute, multi="effective_hours", string='Effective hours', help="Computed using the sum of the task work done."),
111 'expected_hours': fields.function(_compute, multi="expected_hours", string='Planned Hours', help='Estimated time to do the task.'),
112 'state': fields.selection([('draft','Draft'),('open','Open'),('pending','Pending'),('cancel','Cancelled'),('done','Done')], 'State', required=True),
116 'date_start' : lambda *a: time.strftime('%Y-%m-%d'),
119 def copy(self, cr, uid, id, default=None, context=None):
120 """Overrides orm copy method
121 @param self: The object pointer
122 @param cr: the current row, from the database cursor,
123 @param uid: the current user’s ID for security checks,
124 @param ids: List of case’s IDs
125 @param context: A standard dictionary for contextual values
129 default.update({'backlog_ids': [], 'meeting_ids': []})
130 return super(project_scrum_sprint, self).copy(cr, uid, id, default=default, context=context)
132 def onchange_project_id(self, cr, uid, ids, project_id=False):
135 proj = self.pool.get('project.project').browse(cr, uid, [project_id])[0]
136 v['product_owner_id']= proj.product_owner_id and proj.product_owner_id.id or False
137 v['scrum_master_id']= proj.user_id and proj.user_id.id or False
138 v['date_stop'] = (datetime.now() + relativedelta(days=int(proj.sprint_size or 14))).strftime('%Y-%m-%d')
141 project_scrum_sprint()
143 class project_scrum_product_backlog(osv.osv):
144 _name = 'project.scrum.product.backlog'
145 _description = 'Product Backlog'
147 def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
151 match = re.match('^S\(([0-9]+)\)$', name)
153 ids = self.search(cr, uid, [('sprint_id','=', int(match.group(1)))], limit=limit, context=context)
154 return self.name_get(cr, uid, ids, context=context)
155 return super(project_scrum_product_backlog, self).name_search(cr, uid, name, args, operator,context, limit=limit)
157 def _compute(self, cr, uid, ids, fields, arg, context=None):
158 res = {}.fromkeys(ids, 0.0)
162 for backlog in self.browse(cr, uid, ids, context=context):
168 for task in backlog.tasks_id:
169 task_hours += task.total_hours
170 effective += task.effective_hours
171 tot += task.planned_hours
172 prog += task.planned_hours * task.progress / 100.0
174 progress = round(prog/tot*100)
176 'progress' : progress,
177 'effective_hours': effective,
178 'task_hours' : task_hours
182 def button_cancel(self, cr, uid, ids, context=None):
183 obj_project_task = self.pool.get('project.task')
184 self.write(cr, uid, ids, {'state':'cancel'}, context=context)
185 for backlog in self.browse(cr, uid, ids, context=context):
186 obj_project_task.write(cr, uid, [i.id for i in backlog.tasks_id], {'state': 'cancelled'})
189 def button_draft(self, cr, uid, ids, context=None):
190 self.write(cr, uid, ids, {'state':'draft'}, context=context)
193 def button_open(self, cr, uid, ids, context=None):
194 self.write(cr, uid, ids, {'state':'open'}, context=context)
197 def button_close(self, cr, uid, ids, context=None):
198 obj_project_task = self.pool.get('project.task')
199 self.write(cr, uid, ids, {'state':'done'}, context=context)
200 for backlog in self.browse(cr, uid, ids, context=context):
201 obj_project_task.write(cr, uid, [i.id for i in backlog.tasks_id], {'state': 'done'})
204 def button_pending(self, cr, uid, ids, context=None):
205 self.write(cr, uid, ids, {'state':'pending'}, context=context)
208 def button_postpone(self, cr, uid, ids, context=None):
209 for product in self.browse(cr, uid, ids, context=context):
211 for task in product.tasks_id:
212 if task.state != 'done':
213 tasks_id.append(task.id)
215 clone_id = self.copy(cr, uid, product.id, {
216 'name': 'PARTIAL:'+ product.name ,
218 'tasks_id':[(6, 0, tasks_id)],
220 self.write(cr, uid, ids, {'state':'cancel'}, context=context)
224 'name' : fields.char('Feature', size=64, required=True),
225 'note' : fields.text('Note'),
226 'active' : fields.boolean('Active', help="If Active field is set to true, it will allow you to hide the product backlog without removing it."),
227 'project_id': fields.many2one('project.project', 'Project', required=True, domain=[('scrum','=',1)]),
228 'user_id': fields.many2one('res.users', 'Author'),
229 'sprint_id': fields.many2one('project.scrum.sprint', 'Sprint'),
230 'sequence' : fields.integer('Sequence', help="Gives the sequence order when displaying a list of product backlog."),
231 'tasks_id': fields.one2many('project.task', 'product_backlog_id', 'Tasks Details'),
232 'state': fields.selection([('draft','Draft'),('open','Open'),('pending','Pending'),('done','Done'),('cancel','Cancelled')], 'State', required=True),
233 'progress': fields.function(_compute, multi="progress", group_operator="avg", type='float', string='Progress', help="Computed as: Time Spent / Total Time."),
234 'effective_hours': fields.function(_compute, multi="effective_hours", string='Spent Hours', help="Computed using the sum of the time spent on every related tasks", store=True),
235 'expected_hours': fields.float('Planned Hours', help='Estimated total time to do the Backlog'),
236 'create_date': fields.datetime("Creation Date", readonly=True),
237 'task_hours': fields.function(_compute, multi="task_hours", string='Task Hours', help='Estimated time of the total hours of the tasks')
242 'user_id': lambda self, cr, uid, context: uid,
245 project_scrum_product_backlog()
247 class project_scrum_task(osv.osv):
248 _name = 'project.task'
249 _inherit = 'project.task'
251 def _get_task(self, cr, uid, ids, context=None):
253 for line in self.pool.get('project.scrum.product.backlog').browse(cr, uid, ids, context=context):
254 for task in line.tasks_id:
255 result[task.id] = True
258 'product_backlog_id': fields.many2one('project.scrum.product.backlog', 'Product Backlog',help="Related product backlog that contains this task. Used in SCRUM methodology"),
259 'sprint_id': fields.related('product_backlog_id','sprint_id', type='many2one', relation='project.scrum.sprint', string='Sprint',
261 'project.task': (lambda self, cr, uid, ids, c={}: ids, ['product_backlog_id'], 10),
262 'project.scrum.product.backlog': (_get_task, ['sprint_id'], 10)
266 def onchange_backlog_id(self, cr, uid, backlog_id=False):
269 project_id = self.pool.get('project.scrum.product.backlog').browse(cr, uid, backlog_id).project_id.id
270 return {'value': {'project_id': project_id}}
273 class project_scrum_meeting(osv.osv):
274 _name = 'project.scrum.meeting'
275 _description = 'Scrum Meeting'
278 'name' : fields.char('Meeting Name', size=64),
279 'date': fields.date('Meeting Date', required=True),
280 'sprint_id': fields.many2one('project.scrum.sprint', 'Sprint', required=True),
281 'project_id': fields.many2one('project.project', 'Project'),
282 'question_yesterday': fields.text('Tasks since yesterday'),
283 'question_today': fields.text('Tasks for today'),
284 'question_blocks': fields.text('Blocks encountered'),
285 'question_backlog': fields.text('Backlog Accurate'),
286 'task_ids': fields.many2many('project.task', 'meeting_task_rel', 'metting_id', 'task_id', 'Tasks'),
287 'user_id': fields.related('sprint_id', 'scrum_master_id', type='many2one', relation='res.users', string='Scrum Master', readonly=True),
290 # TODO: Find the right sprint thanks to users and date
293 'date' : lambda *a: time.strftime('%Y-%m-%d'),
296 def button_send_to_master(self, cr, uid, ids, context=None):
297 meeting_id = self.browse(cr, uid, ids, context=context)[0]
298 if meeting_id and meeting_id.sprint_id.scrum_master_id.user_email:
299 res = self.email_send(cr, uid, ids, meeting_id.sprint_id.scrum_master_id.user_email)
301 raise osv.except_osv(_('Error !'), _('Email notification could not be sent to the scrum master %s') % meeting_id.sprint_id.scrum_master_id.name)
303 raise osv.except_osv(_('Error !'), _('Please provide email address for scrum master defined on sprint.'))
306 def button_send_product_owner(self, cr, uid, ids, context=None):
309 context.update({'button_send_product_owner': True})
310 meeting_id = self.browse(cr, uid, ids, context=context)[0]
311 if meeting_id.sprint_id.product_owner_id.user_email:
312 res = self.email_send(cr,uid,ids,meeting_id.sprint_id.product_owner_id.user_email)
314 raise osv.except_osv(_('Error !'), _('Email notification could not be sent to the product owner %s') % meeting_id.sprint_id.product_owner_id.name)
316 raise osv.except_osv(_('Error !'), _('Please provide email address for product owner defined on sprint.'))
319 def email_send(self, cr, uid, ids, email, context=None):
320 mail_message_obj = self.pool.get('mail.message')
321 meeting_id = self.browse(cr, uid, ids, context=context)[0]
322 user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
323 user_email = user.user_email or tools.config.get('email_from', False)
324 body = _("Hello %s,\n \nI am sending you Daily Meeting Details of date %s for the Sprint %s\n") %(meeting_id.sprint_id.scrum_master_id.name, meeting_id.date, meeting_id.sprint_id.name)
325 body += _('\n* Tasks since yesterday:\n_______________________\n%s\n\n* Task for Today:\n_______________________ \n%s\n\n* Blocks encountered:\n_______________________ \n\n%s') %(meeting_id.question_yesterday,meeting_id.question_today, meeting_id.question_blocks or _('No Blocks'))
326 body += _("\n\nThank you,\n%s") % user.name
327 sub_name = meeting_id.name or _('Scrum Meeting of %s') % meeting_id.date
328 flag = mail_message_obj.schedule_with_attach(cr, uid, user_email , [email], sub_name, body, model='project.scrum.meeting', res_id=meeting_id.id, context=context)
333 project_scrum_meeting()