~jamesj/openobject-addons/c2c_budget_fixes

« back to all changes in this revision

Viewing changes to portal_project/portal_project.py

[IMP] Adding multi_company_stock_module, nto finished

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#
21
21
##############################################################################
22
22
 
23
 
import time
 
23
import datetime
 
24
 
24
25
from osv import fields, osv
25
26
import pooler
26
27
import tools
46
47
class users(osv.osv):
47
48
    _inherit = 'res.users'
48
49
    _columns = {
49
 
        'user_id' : fields.many2one('project.project', 'portal', ondelete='cascade'),
50
 
        'context_project_id': fields.selection(_project_get, 'Project',size=128),
 
50
        'user_id': fields.many2one('project.project', 'portal', ondelete='cascade'),
 
51
        'context_project_id': fields.selection(_project_get, 'Project'),
51
52
        }
52
53
    _defaults = {
53
 
         'context_project_id' : lambda *args: '2',
 
54
         'context_project_id': lambda *args: '1',
54
55
            }
55
56
 
56
57
    def context_get(self, cr, uid, context=None):
62
63
    _inherit = "project.project"
63
64
    _description = "Project"
64
65
 
 
66
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
67
        if context is None:
 
68
            context = {}
 
69
        if context.has_key('action_portal') and context['action_portal']=='project' and context.has_key('project_id') and context['project_id']:
 
70
            return [context['project_id']]
 
71
        return super(project_project, self).search(cr, uid, args, offset, limit, order, context, count)
 
72
 
 
73
 
65
74
    def _get_details(self, cr, uid, ids_project, context={}, *arg):
66
75
        # Todo: 1. Reload button gives error for project
67
76
        #       2. Test/Check
79
88
        ids = ",".join(map(str, ids_project))
80
89
 
81
90
        # Number of tasks
82
 
        cr.execute('select count(t.id), p.id, p.name , sum(t.remaining_hours) as hours from project_project as p left join project_task as t on p.id=t.project_id \
 
91
        cr.execute('select count(t.id), p.id, p.name , sum(t.remaining_hours) as hours \
 
92
                    from project_project as p left join project_task as t on p.id=t.project_id \
83
93
                    where p.id in ('+ids+') and t.state=%s group by p.id, p.name', ('open',))
84
94
        for proj in cr.dictfetchall():
85
 
            result[proj['id']]['tasks'] = str(proj['count']) + ' opens, ' + str(proj['hours']) + ' remaining'
 
95
            result[proj['id']]['tasks'] = str(proj['count']) + ' opens, ' + str(proj['hours']) + ' hours remaining'
86
96
 
87
97
        #======================================Bug, Features ,support request====================================================
88
 
        cr.execute('select p.id, count(c.id), p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_bug_id=c.section_id \
89
 
                    and p.id in ('+ids+') group by p.id,p.name')
90
 
        for bug in cr.dictfetchall():
91
 
            result[bug['id']]['bugs'] = str(bug['count']) + ' Total '
92
 
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_bug_id=c.section_id \
93
 
                    and p.id in ('+ids+') and c.state=%s group by p.id,p.name,c.state', ('open',))
 
98
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, \
 
99
                    crm_case as c, project_task as t where t.case_id=c.id and p.id=t.project_id \
 
100
                    and p.section_bug_id=c.section_id and p.id in ('+ids+') and c.state=%s  \
 
101
                    group by p.id,p.name,c.state', ('open',))
94
102
        res_bug = cr.dictfetchall()
95
103
        for bug in res_bug:
96
 
            result[bug['id']]['bugs'] = result[bug['id']]['bugs'] + str(bug['count']) + ' open'
 
104
            result[bug['id']]['bugs'] = result[bug['id']]['bugs'] + str(bug['count']) + ' Open '
 
105
        cr.execute('select p.id, count(c.id), p.name from project_project as p, \
 
106
                    crm_case as c, project_task as t where t.case_id=c.id \
 
107
                    and p.id=t.project_id and p.section_bug_id=c.section_id \
 
108
                    and p.id in ('+ids+') group by p.id,p.name')
 
109
        for bug in cr.dictfetchall():
 
110
            result[bug['id']]['bugs'] = result[bug['id']]['bugs'] +  str(bug['count'])  +  ' Total'
97
111
 
98
 
        cr.execute('select p.id, count(c.id), p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_feature_id=c.section_id \
99
 
                    and p.id in ('+ids+') group by p.id,p.name')
100
 
        for feature in cr.dictfetchall():
101
 
            result[feature['id']]['features'] = str(feature['count']) + ' Total '
102
 
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_feature_id=c.section_id \
 
112
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, \
 
113
                    crm_case as c, project_task as t where t.case_id=c.id  \
 
114
                    and p.id=t.project_id and p.section_feature_id=c.section_id \
103
115
                    and p.id in ('+ids+') and c.state=%s group by p.id,p.name,c.state', ('open',))
104
116
        res_fet = cr.dictfetchall()
105
117
        for feature in res_fet:
106
 
            result[feature['id']]['features'] = result[feature['id']]['features'] + str(feature['count']) + ' open'
 
118
            result[feature['id']]['features'] = result[feature['id']]['features'] + str(feature['count']) + ' Open '
 
119
        cr.execute('select p.id, count(c.id), p.name from project_project as p, \
 
120
                    crm_case as c, project_task as t where t.case_id=c.id  \
 
121
                    and p.id=t.project_id and p.section_feature_id=c.section_id \
 
122
                    and p.id in ('+ids+') group by p.id,p.name')
 
123
        for feature in cr.dictfetchall():
 
124
            result[feature['id']]['features'] = result[feature['id']]['features'] + str(feature['count']) + ' Total'
107
125
 
108
 
        cr.execute('select p.id, count(c.id), p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_support_id=c.section_id \
109
 
                    and p.id in ('+ids+') group by p.id,p.name')
110
 
        for support in cr.dictfetchall():
111
 
            result[support['id']]['support_req'] = str(support['count']) + ' Total '
112
 
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, crm_case as c where p.id=c.project_id and p.section_support_id=c.section_id \
 
126
        cr.execute('select p.id, count(c.id),c.state,p.name from project_project as  p, \
 
127
                    crm_case as c, project_task as t where t.case_id=c.id \
 
128
                    and p.id=t.project_id and p.section_support_id=c.section_id \
113
129
                    and p.id in ('+ids+') and c.state=%s group by p.id,p.name,c.state', ('open',))
114
130
        res_sup = cr.dictfetchall()
115
131
        for support in res_sup:
116
 
            result[support['id']]['support_req'] = result[support['id']]['support_req'] + str(support['count']) + ' open'
 
132
            result[support['id']]['support_req'] = result[support['id']]['support_req'] + str(support['count']) + ' Open '
 
133
        cr.execute('select p.id, count(c.id), p.name from project_project as p, \
 
134
                    crm_case as c, project_task as t where t.case_id=c.id \
 
135
                    and p.id=t.project_id and p.section_support_id=c.section_id \
 
136
                    and p.id in ('+ids+') group by p.id,p.name')
 
137
        for support in cr.dictfetchall():
 
138
            result[support['id']]['support_req'] = result[support['id']]['support_req'] + str(support['count']) + ' Total'
 
139
 
117
140
        #==========================================================================================
118
141
 
119
142
        # Number of doument attach in project and its tasks
123
146
            result[doc['id']]['doc'] = doc['count']#str(doc['count'])
124
147
        cr.execute('select count(i.id), p.id, p.name, i.file_size as datas from project_project as p left join ir_attachment as i on i.res_id=p.id where p.id in ('+ids+') and i.res_model=%s group by p.id, p.name, i.file_size',(model,))
125
148
        res_size_proj = cr.dictfetchall()
126
 
        cr.execute('select count(i.id) as task_docs, p.id as project from project_task t left join project_project p on p.id=t.project_id \
 
149
        cr.execute('select count(i.id) as task_docs, p.id as project \
 
150
                    from project_task t left join project_project p on p.id=t.project_id \
127
151
                    left join ir_attachment i on i.res_id=t.id where p.id in ('+ids+') and i.res_model=%s \
128
152
                    group by p.id',('project.task',))
129
153
        task_res = cr.dictfetchall()
131
155
            if result[doc['project']]['doc'] == '': result[doc['project']]['doc'] = 0
132
156
            result[doc['project']]['doc'] = str(result[doc['project']]['doc'] +  doc['task_docs'])#str(doc['count'])
133
157
 
134
 
        cr.execute('select t.id as task_id, count(i.id) as task_docs, p.id as project, i.file_size from project_task t left join project_project p on p.id=t.project_id \
 
158
        cr.execute('select t.id as task_id, count(i.id) as task_docs, p.id as project, i.file_size \
 
159
                    from project_task t left join project_project p on p.id=t.project_id \
135
160
                    left join ir_attachment i on i.res_id=t.id where p.id in ('+ids+') and i.res_model=%s \
136
161
                    group by p.id, i.file_size, t.id', ('project.task',))
137
162
        res_size_task = cr.dictfetchall()
173
198
        if not ids:
174
199
            return {}
175
200
        res = {}
 
201
        date_back = datetime.date.today() +  datetime.timedelta(days=-31)
 
202
        date_back = date_back.strftime('%Y-%m-%d')
176
203
        for announce in self.browse(cr, uid, ids, context):
177
204
            cr.execute("""select c.id from crm_case c \
178
 
                        left join project_project p on %s = c.project_id \
179
 
                       where c.section_id = p.section_annouce_id and c.date >= %s """, (announce.id, time.strftime('%Y-%m-01'),))
 
205
                        left join project_task t on t.case_id=c.id left join project_project p on %s = t.project_id \
 
206
                       where c.section_id = p.section_annouce_id and c.date >= %s """, (announce.id, date_back))
180
207
            list_announce = map(lambda x: x[0], cr.fetchall())
181
208
            res[announce.id] = list_announce
182
209
        return res
216
243
    _columns = {
217
244
        'project_id': fields.many2one('project.project', 'Project')
218
245
        }
 
246
 
 
247
    def write(self, cr, uid, ids, vals, context={}):
 
248
        wiki = self.browse(cr, uid, ids[0])
 
249
        res = super(Wiki, self).write(cr, uid, ids, vals, context={})
 
250
        cr.commit()
 
251
        task_data = self.browse(cr, uid, ids[0], context)
 
252
        desc = '''Hello,\n\n  The wiki information is updated for the project: %s\n\nModified Datas are:\n''' %(str(wiki.project_id.name),)
 
253
        for val in vals:
 
254
            if val.endswith('id') or val.endswith('ids'):
 
255
                continue
 
256
            desc += '========\n' +val + ':' + str(vals[val]) + "\n"
 
257
        desc += '\nThanks,\n' + 'Project Manager\n' + (task_data.project_id.manager and task_data.project_id.manager.name) or ''
 
258
        self.pool.get('project.project')._log_event(cr, uid, wiki.project_id.id, {
 
259
                                                                'res_id' : ids[0],
 
260
                                                                'name' : wiki.name or '',
 
261
                                                                'description' : desc,
 
262
                                                                'user_id': uid,
 
263
                                                                'action' : 'write',
 
264
                                                                'type' : 'task'})
 
265
        return res
 
266
 
219
267
Wiki()
220
268
 
221
269
class crm_case(osv.osv):
222
270
    _inherit = 'crm.case'
223
 
    
224
 
    def _get_latest_cases(self, cr, uid, ids_cases, context={}, *arg):
 
271
 
 
272
    def _get_latest_cases(self, cr, uid, ids_cases, name, args, context={}):
225
273
        if not ids_cases:
226
274
            return {}
227
275
        result = {}
233
281
                  'announce_ids': '',
234
282
                          }
235
283
 
 
284
        date_back = datetime.date.today() +  datetime.timedelta(days=-31)
 
285
        date_back = date_back.strftime('%Y-%m-%d')
 
286
 
 
287
        if context.has_key('project_id') and context['project_id']:
 
288
            project_id = context['project_id']
 
289
        else:
 
290
            project_ids = self.pool.get('project.project').search(cr, uid, [('manager', '=', uid)])
 
291
            project_id = project_ids and project_ids[0]
 
292
 
236
293
        for case in self.browse(cr, uid, ids_cases, context):
237
294
            cr.execute("""select c.id from crm_case c \
238
 
                        left join project_project p on p.id = c.project_id \
239
 
                        where c.section_id = p.section_bug_id and c.date >= %s """, (time.strftime('%Y-%m-01'),))
 
295
                        left join  project_task t on c.id=t.case_id left join project_project p on p.id = t.project_id \
 
296
                        where c.section_id = p.section_bug_id and c.date >= %s and p.id=%s """, (date_back,project_id,))
240
297
            list_case = map(lambda x: x[0], cr.fetchall())
241
298
            result[case.id]['bug_ids'] = list_case
242
299
 
243
300
            cr.execute("""select c.id from crm_case c \
244
 
                        left join project_project p on p.id = c.project_id \
245
 
                        where c.section_id = p.section_feature_id and c.date >= %s """, (time.strftime('%Y-%m-01'),))
 
301
                        left join  project_task t on c.id=t.case_id left join project_project p on p.id = t.project_id \
 
302
                        where c.section_id = p.section_feature_id and c.date >= %s and p.id=%s """, (date_back, project_id,))
246
303
            list_case = map(lambda x: x[0], cr.fetchall())
247
304
            result[case.id]['feature_ids'] = list_case
248
305
 
249
306
            cr.execute("""select c.id from crm_case c \
250
 
                        left join project_project p on p.id = c.project_id \
251
 
                        where c.section_id = p.section_support_id and c.date >= %s """, (time.strftime('%Y-%m-01'),))
 
307
                        left join  project_task t on c.id=t.case_id left join project_project p on p.id = t.project_id \
 
308
                        where c.section_id = p.section_support_id and c.date >= %s and p.id=%s """, (date_back, project_id,))
252
309
            list_case = map(lambda x: x[0], cr.fetchall())
253
310
            result[case.id]['support_ids'] = list_case
254
311
 
255
312
            cr.execute("""select c.id from crm_case c \
256
 
                        left join project_project p on p.id = c.project_id \
257
 
                        where c.section_id = p.section_annouce_id and c.date >= %s """, (time.strftime('%Y-%m-01'),))
 
313
                        left join  project_task t on c.id=t.case_id left join project_project p on p.id = t.project_id \
 
314
                        where c.section_id = p.section_annouce_id and c.date >= %s and p.id=%s """, (date_back, project_id,))
258
315
            list_case = map(lambda x: x[0], cr.fetchall())
259
316
            result[case.id]['announce_ids'] = list_case
260
317
        return result
261
 
   
 
318
 
262
319
    _columns = {
263
 
        'project_id' : fields.many2one('project.project', 'Project'),
264
320
        'bug_ids' : fields.function(_get_latest_cases,type='one2many', relation='crm.case', method=True , string= 'Latest Bugs', multi='case'),
265
321
        'feature_ids' : fields.function(_get_latest_cases,type='one2many', relation='crm.case', method=True , string='Latest Features', multi='case'),
266
322
        'support_ids' : fields.function(_get_latest_cases,type='one2many', relation='crm.case', method=True , string='Latest Supports', multi='case'),
270
326
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
271
327
        if context is None:
272
328
            context = {}
 
329
        if context.has_key('project_id') and context['project_id']:
 
330
            project_id = context['project_id']
 
331
        else:
 
332
            project_ids = self.pool.get('project.project').search(cr, uid, [('manager', '=', uid)])
 
333
            project_id = project_ids and project_ids[0]
 
334
 
273
335
        if context.has_key('section') and context['section']=='Bug Tracking' or context.has_key('case_search') and context['case_search']=='bug':
274
 
            cr.execute('select c.id from crm_case c left join project_project p on p.id=c.project_id where c.section_id=p.section_bug_id')
 
336
            cr.execute('select c.id from crm_case c left join project_task t on c.id=t.case_id left join project_project p on p.id=t.project_id where c.section_id=p.section_bug_id and p.id=%s',(project_id,))
275
337
            return map(lambda x: x[0], cr.fetchall())
276
338
        elif context.has_key('section') and context['section']=='Feature' or context.has_key('case_search') and context['case_search']=='feature':
277
 
            cr.execute('select c.id from crm_case c left join project_project p on p.id=c.project_id where c.section_id=p.section_feature_id')
 
339
            cr.execute('select c.id from crm_case c left join project_task t on c.id=t.case_id left join project_project p on p.id=t.project_id where c.section_id=p.section_feature_id and p.id=%s',(project_id,))
278
340
            return map(lambda x: x[0], cr.fetchall())
279
341
        elif context.has_key('section') and context['section']=='Support' or context.has_key('case_search') and context['case_search']=='support':
280
 
            cr.execute('select c.id from crm_case c left join project_project p on p.id=c.project_id where c.section_id=p.section_support_id')
 
342
            cr.execute('select c.id from crm_case c left join project_task t on c.id=t.case_id left join project_project p on p.id=t.project_id where c.section_id=p.section_support_id and p.id=%s',(project_id,))
281
343
            return map(lambda x: x[0], cr.fetchall())
282
344
        elif context.has_key('section') and context['section']=='Announce' or context.has_key('case_search') and context['case_search']=='announce':
283
 
            cr.execute('select c.id from crm_case c left join project_project p on p.id=c.project_id where c.section_id=p.section_annouce_id')
 
345
            cr.execute('select c.id from crm_case c left join project_task t on c.id=t.case_id left join project_project p on p.id=t.project_id where c.section_id=p.section_annouce_id and p.id=%s',(project_id,))
284
346
            return map(lambda x: x[0], cr.fetchall())
285
347
        return super(crm_case, self).search(cr, uid, args, offset, limit, order, context, count)
286
348
 
287
 
    def create(self, cr, uid, values, *args, **kwargs):
 
349
    def create(self, cr, uid, values, *args, **kwargs): # to be check
288
350
        case_id = super(crm_case, self).create(cr, uid, values, *args, **kwargs)
289
 
        cr.commit()
290
 
        case = self.browse(cr, uid, case_id)
291
 
        if case.project_id:
292
 
            self.pool.get('project.project')._log_event(cr, uid, case.project_id.id, {
293
 
                                'res_id' : case.id,
294
 
                                'name' : case.name,
295
 
                                'description' : case.description,
296
 
                                'user_id': uid,
297
 
                                'action' : 'create',
298
 
                                'type'   : 'case'})
 
351
#        cr.commit()
 
352
#        case = self.browse(cr, uid, case_id)
 
353
#        if case.project_id:
 
354
#            self.pool.get('project.project')._log_event(cr, uid, case.project_id.id, {
 
355
#                                'res_id' : case.id,
 
356
#                                'name' : case.name,
 
357
#                                'description' : case.description,
 
358
#                                'user_id': uid,
 
359
#                                'action' : 'create',
 
360
#                                'type'   : 'case'})
299
361
        return case_id
300
362
 
301
 
    def write(self, cr, uid, ids, vals, context={}):
 
363
    def write(self, cr, uid, ids, vals, context={}): # to be check
302
364
        res = super(crm_case, self).write(cr, uid, ids, vals, context={})
303
 
        cr.commit()
304
 
        cases = self.browse(cr, uid, ids)
305
 
        for case in cases:
306
 
            if case.project_id:
307
 
                self.pool.get('project.project')._log_event(cr, uid, case.project_id.id, {
308
 
                                    'res_id' : case.id,
309
 
                                    'name' : case.name,
310
 
                                    'description' : case.description,
311
 
                                    'user_id': uid,
312
 
                                    'action' : 'write',
313
 
                                    'type' : 'case'})
 
365
#        cr.commit()
 
366
#        cases = self.browse(cr, uid, ids)
 
367
#        for case in cases:
 
368
#            if case.project_id:
 
369
#                self.pool.get('project.project')._log_event(cr, uid, case.project_id.id, {
 
370
#                                    'res_id' : case.id,
 
371
#                                    'name' : case.name,
 
372
#                                    'description' : case.description,
 
373
#                                    'user_id': uid,
 
374
#                                    'action' : 'write',
 
375
#                                    'type' : 'case'})
314
376
        return res
315
377
 
316
378
crm_case()
364
426
 
365
427
class report_crm_case_bugs(osv.osv):
366
428
    _name = "report.crm.case.bugs"
367
 
    _description = "Bugs by State"
 
429
    _description = "Bugs by state & user"
368
430
    _auto = False
369
431
    _rec_name = 'user_id'
370
432
    _columns = {
375
437
        'section_id' : fields.many2one('crm.case.section', 'Section', required=False)
376
438
    }
377
439
 
 
440
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
441
        if context is None:
 
442
            context = {}
 
443
        if context.has_key('bugs_user') and context['bugs_user']=='bug_form' and context.has_key('project_id') and context['project_id']:
 
444
            cr.execute('select id from report_crm_case_bugs where project_id=%s',(context['project_id']))
 
445
            return map(lambda x: x[0], cr.fetchall())
 
446
        return super(report_crm_case_bugs, self).search(cr, uid, args, offset, limit, order, context, count)
 
447
 
378
448
    def init(self, cr):
379
449
        cr.execute("""
380
450
            create or replace view report_crm_case_bugs as (
381
451
                select
382
452
                    min(c.id) as id,
383
453
                    c.user_id,
384
 
                    c.project_id as project_id,
 
454
                    t.project_id as project_id,
385
455
                    c.section_id as section_id,
386
456
                    count(*) as nbr,
387
457
                    c.state
388
458
                from
389
 
                    crm_case c left join project_project p on p.id = c.project_id
 
459
                    crm_case c left join project_task t on t.case_id = c.id
 
460
                    left join project_project p on p.id = t.project_id
390
461
                where c.section_id = p.section_bug_id
391
 
                group by c.user_id, c.project_id, c.section_id, c.state
 
462
                group by c.user_id, t.project_id, c.section_id, c.state
392
463
            )""")
393
464
 
 
465
 
394
466
report_crm_case_bugs()
395
467
 
396
468
class report_crm_case_features_user(osv.osv):
401
473
    _columns = {
402
474
        'nbr': fields.integer('# of Cases', readonly=True),
403
475
        'user_id': fields.many2one('res.users', 'User', size=16, readonly=True),
 
476
        'project_id': fields.many2one('project.project', 'Project')
404
477
    }
 
478
 
 
479
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
480
        if context is None:
 
481
            context = {}
 
482
        if context.has_key('project_id') and context['project_id']:
 
483
            cr.execute('select id from report_crm_case_features_user where project_id=%s',(context['project_id']))
 
484
            return map(lambda x: x[0], cr.fetchall())
 
485
        return super(report_crm_case_features_user, self).search(cr, uid, args, offset, limit, order, context, count)
 
486
 
 
487
 
405
488
    def init(self, cr):
406
489
        cr.execute("""
407
490
            create or replace view report_crm_case_features_user as (
408
491
                select
409
492
                    min(c.id) as id,
410
493
                    c.user_id,
411
 
                    count(*) as nbr
 
494
                    count(*) as nbr,
 
495
                    p.id as project_id
412
496
                from
413
 
                    crm_case c left join project_project p on p.id = c.project_id
 
497
                    crm_case c left join project_task t on  t.case_id=c.id
 
498
                    left join project_project p on p.id = t.project_id
414
499
                where c.section_id = p.section_feature_id
415
 
                group by c.user_id, c.name
 
500
                group by c.user_id, c.name, p.id
416
501
            )""")
417
502
 
 
503
 
418
504
report_crm_case_features_user()
419
505
 
420
506
class report_crm_case_support_user(osv.osv):
425
511
    _columns = {
426
512
        'nbr': fields.integer('# of Cases', readonly=True),
427
513
        'user_id': fields.many2one('res.users', 'User', size=16, readonly=True),
 
514
        'project_id': fields.many2one('project.project', 'Project')
428
515
    }
 
516
 
 
517
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
518
        if context is None:
 
519
            context = {}
 
520
        if context.has_key('project_id') and context['project_id']:
 
521
            cr.execute('select id from report_crm_case_support_user where project_id=%s',(context['project_id']))
 
522
            return map(lambda x: x[0], cr.fetchall())
 
523
        return super(report_crm_case_support_user, self).search(cr, uid, args, offset, limit, order, context, count)
 
524
 
429
525
    def init(self, cr):
430
526
        cr.execute("""
431
527
            create or replace view report_crm_case_support_user as (
432
528
                select
433
529
                    min(c.id) as id,
434
530
                    c.user_id,
435
 
                    count(*) as nbr
 
531
                    count(*) as nbr,
 
532
                    p.id as project_id
436
533
                from
437
 
                    crm_case c left join project_project p on p.id = c.project_id
 
534
                    crm_case c left join project_task t on c.id=t.case_id
 
535
                    left join project_project p on p.id = t.project_id
438
536
                where c.section_id = p.section_support_id
439
 
                group by c.user_id, c.name
 
537
                group by c.user_id, c.name, p.id
440
538
            )""")
441
539
 
 
540
 
442
541
report_crm_case_support_user()
443
542
 
444
543
class report_crm_case_announce_user(osv.osv):
450
549
        'name': fields.char('Description',size=64,required=True),
451
550
        'nbr': fields.integer('# of Cases', readonly=True),
452
551
        'user_id': fields.many2one('res.users', 'User', size=16, readonly=True),
 
552
        'project_id': fields.many2one('project.project', 'Project')
453
553
    }
 
554
 
 
555
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
556
        if context is None:
 
557
            context = {}
 
558
        if context.has_key('project_id') and context['project_id']:
 
559
            cr.execute('select id from report_crm_case_announce_user where project_id=%s',(context['project_id']))
 
560
            return map(lambda x: x[0], cr.fetchall())
 
561
        return super(report_crm_case_announce_user, self).search(cr, uid, args, offset, limit, order, context, count)
 
562
 
454
563
    def init(self, cr):
455
564
        cr.execute("""
456
565
            create or replace view report_crm_case_announce_user as (
458
567
                    min(c.id) as id,
459
568
                    c.user_id,
460
569
                    c.name as name,
461
 
                    count(*) as nbr
 
570
                    count(*) as nbr,
 
571
                    p.id as project_id
462
572
                from
463
 
                    crm_case c left join project_project p on p.id = c.project_id
 
573
                    crm_case c left join project_task t on t.case_id = c.id
 
574
                    left join project_project p on p.id = t.project_id
464
575
                where c.section_id = p.section_annouce_id
465
 
                group by c.user_id, c.name
 
576
                group by c.user_id, c.name, p.id
466
577
            )""")
467
578
 
 
579
 
468
580
report_crm_case_announce_user()
469
581
 
470
582
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: