4
# OpenERP, Open Source Management Solution
5
# Copyright (C)2010- OpenERP SA (<http://openerp.com>). All Rights Reserved
8
# Developed by Oscar Alcala <oszckar@gmail.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 3 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
from openerp import pooler, tools
25
from openerp.osv import fields, osv
26
from openerp.tools.translate import _
27
from bzrlib import branch
31
class project_project(osv.Model):
32
_inherit = 'project.project'
34
'sprint_id': fields.many2one('sprint.kanban', 'Sprint',
36
'url_branch': fields.char('Url Branch', 264),
37
'merge_proposal': fields.char('Merge Proposal', 264),
38
'blueprint': fields.char('Blueprint', 264),
39
'res_id': fields.char('Revno', 64),
40
'from_revno': fields.integer('From Revno')
46
def get_works(self, cr, uid, ids, context=None):
47
user_obj = self.pool.get('res.users')
48
task_obj = self.pool.get('project.task')
49
self_obj = self.browse(cr, uid, ids)[0]
50
url = self_obj.url_branch
51
res_id = self_obj.res_id
52
inferior = self_obj.from_revno
53
if url and res_id and inferior and int(res_id) > inferior:
54
project_branch = branch.Branch.open(url)
55
b_revno = project_branch.revno()
57
repo = project_branch.repository
58
revision_map = project_branch.get_revision_id_to_revno_map()
60
for revision_id in revision_map.keys():
61
if revision_map[revision_id][0] in range(inferior, int(res_id) + 1):
63
revision = repo.get_revision(revision_id)
64
date = datetime.datetime.fromtimestamp(int(
65
revision.timestamp)).strftime('%Y-%m-%d %H:%M:%S')
66
splitted_revision_id = revision_id.split('-')
67
email = revision_id[0]
68
user_ids = user_obj.search(
69
cr, uid, [('email', '=', email)])
71
'name': revision.message,
72
'date_deadline': date,
73
'revno': revision_map[revision_id][0],
76
task_data['user_id'] = user_ids[0]
77
task_ids = task_obj.search(cr, uid, [('project_id', '=', ids[
78
0]), ('revno', '=', task_data['revno'])])
80
if inferior and inferior <= task_data['revno'] and int(res_id) >= task_data['revno']:
81
self.write(cr, uid, ids, {
82
'tasks': [(0, 0, task_data)]})
84
raise osv.except_osv(('Error'), ('Fields: URL Branch, From Revno and Revno are required to execute this operation, \
85
also From Revno must be minor than Revno'))
89
class sprint_kanban_tasks(osv.Model):
90
_inherit = 'project.task'
92
'revno': fields.integer('Revno'),
93
'from_revno': fields.integer('From Revno')
99
def set_work_time(self, cr, uid, ids, context=None):
101
task_work_obj = self.pool.get('project.task.work')
102
for task in self.browse(cr, uid, ids):
103
for tw in task.work_ids:
104
rev_date[tw.revno] = tw.date,
105
for tw in task.work_ids:
106
previous = tw.revno - 1
107
if rev_date.get(previous, False):
108
p_date = datetime.datetime.strptime(
109
rev_date[previous][0], '%Y-%m-%d %H:%M:%S')
110
actual = datetime.datetime.strptime(
111
tw.date, '%Y-%m-%d %H:%M:%S')
112
result = actual - p_date
113
if float(result.seconds) / 60 / 60 > 0.16:
114
hours = float(result.seconds) / 60 / 60
117
max_date = max(rev_date.itervalues())[0]
118
deadline = datetime.datetime.strptime(
119
max_date, '%Y-%m-%d %H:%M:%S')
120
deadline = deadline + datetime.timedelta(days=1)
121
task_work_obj.write(cr, uid, [tw.id], {'hours': hours})
125
def get_works(self, cr, uid, ids, context=None):
126
tw_obj = self.pool.get('project.task.work')
127
obj_self = self.browse(cr, uid, ids)[0]
128
user_obj = self.pool.get('res.users')
129
url = obj_self.url_branch
130
res_id = obj_self.res_id
131
inferior = obj_self.from_revno
132
if url and res_id and inferior and int(res_id) > inferior:
133
task_branch = branch.Branch.open(url)
134
b_revno = task_branch.revno()
136
repo = task_branch.repository
137
revision_map = task_branch.get_revision_id_to_revno_map()
139
for k in revision_map.keys():
140
if revision_map[k][0] in range(inferior, int(res_id) + 1):
142
revision = repo.get_revision(k)
143
date = datetime.datetime.fromtimestamp(int(
144
revision.timestamp)).strftime('%Y-%m-%d %H:%M:%S')
145
revision_id = k.split('-')
146
email = revision_id[0]
147
user_ids = user_obj.search(
148
cr, uid, [('email', '=', email)])
150
'name': revision.message,
152
'revno': revision_map[k][0],
155
tw_data['user_id'] = user_ids[0]
156
tw_ids = tw_obj.search(cr, uid, [('task_id', '=', ids[
157
0]), ('revno', '=', tw_data['revno'])])
159
if inferior and inferior <= tw_data['revno'] and int(res_id) >= tw_data['revno']:
160
self.write(cr, uid, ids, {
161
'work_ids': [(0, 0, tw_data), ], })
162
deadline = self.set_work_time(cr, uid, ids, context)
163
self.write(cr, uid, ids, {'date_deadline': deadline})
165
raise osv.except_osv(('Error'), ('Fields: URL Branch, From Revno and Revno are required to execute this operation, \
166
also From Revno must be minor than Revno'))
170
class project_task_work(osv.Model):
171
_inherit = 'project.task.work'
173
'revno': fields.integer('Revno'),