Launchpad automatic translations update.
[odoo/odoo.git] / addons / project_issue / report / project_issue_report.py
index 26ae525..b550b5c 100644 (file)
@@ -1,3 +1,25 @@
+
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
 from osv import fields,osv
 import tools
 from crm import crm
@@ -13,49 +35,10 @@ class project_issue_report(osv.osv):
     _name = "project.issue.report"
     _auto = False
 
-    def _get_data(self, cr, uid, ids, field_name, arg, context={}):
-        """ @param cr: the current row, from the database cursor,
-            @param uid: the current users ID for security checks,
-            @param ids: List of case and section Datas IDs
-            @param context: A standard dictionary for contextual values """
-
-        res = {}
-        state_perc = 0.0
-        avg_ans = 0.0
-
-        for case in self.browse(cr, uid, ids, context):
-            if field_name != 'avg_answers':
-                state = field_name[5:]
-                cr.execute("select count(*) from crm_opportunity where \
-                    section_id =%s and state='%s'"%(case.section_id.id, state))
-                state_cases = cr.fetchone()[0]
-                perc_state = (state_cases / float(case.nbr)) * 100
-
-                res[case.id] = perc_state
-            else:
-                model_name = self._name.split('report.')
-                if len(model_name) < 2:
-                    res[case.id] = 0.0
-                else:
-                    model_name = model_name[1]
-
-                    cr.execute("select count(*) from crm_case_log l, ir_model m \
-                         where l.model_id=m.id and m.model = '%s'" , model_name)
-                    logs = cr.fetchone()[0]
-
-                    avg_ans = logs / case.nbr
-                    res[case.id] = avg_ans
-
-        return res
-
     _columns = {
         'name': fields.char('Year', size=64, required=False, readonly=True),
-        'user_id':fields.many2one('res.users', 'Responsible', readonly=True),
-        'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
+        'section_id':fields.many2one('crm.case.section', 'Sale Team', readonly=True),
         'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
-        'avg_answers': fields.function(_get_data, string='Avg. Answers', method=True, type="integer"),
-        'perc_done': fields.function(_get_data, string='%Done', method=True, type="float"),
-        'perc_cancel': fields.function(_get_data, string='%Cancel', method=True, type="float"),
         'month':fields.selection([('01', 'January'), ('02', 'February'), \
                                   ('03', 'March'), ('04', 'April'),\
                                   ('05', 'May'), ('06', 'June'), \
@@ -64,34 +47,35 @@ class project_issue_report(osv.osv):
                                   ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
         'company_id': fields.many2one('res.company', 'Company', readonly=True),
         'day': fields.char('Day', size=128, readonly=True),
-        'opening_date': fields.date('Opening Date', readonly=True),
+        'opening_date': fields.date('Date of Opening', readonly=True),
         'creation_date': fields.date('Creation Date', readonly=True),
+        'date_closed': fields.date('Date of Closing', readonly=True),
         'categ_id': fields.many2one('crm.case.categ', 'Category', domain="[('section_id','=',section_id),('object_id.model', '=', 'project.issue')]"),
-        'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('object_id.model', '=', 'project.issue')]"),
+        'type_id': fields.many2one('project.task.type', 'Stage'),
         'nbr': fields.integer('# of Issues', readonly=True),
-        'working_hours_open': fields.float('# Working Open Hours', readonly=True),
-        'working_hours_close': fields.float('# Working Closing Hours', readonly=True),
-        'delay_open': fields.float('Avg opening Delay', digits=(16,2), readonly=True, group_operator="avg",
+        'working_hours_open': fields.float('Avg. Working Hours to Open', readonly=True),
+        'working_hours_close': fields.float('Avg. Working Hours to Close', readonly=True),
+        'delay_open': fields.float('Avg. Delay to Open', digits=(16,2), readonly=True, group_operator="avg",
                                        help="Number of Days to close the project issue"),
-        'delay_close': fields.float('Avg Closing Delay', digits=(16,2), readonly=True, group_operator="avg",
+        'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg",
                                        help="Number of Days to close the project issue"),
         'company_id' : fields.many2one('res.company', 'Company'),
         'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
         'project_id':fields.many2one('project.project', 'Project',readonly=True),
-        'type_id': fields.many2one('crm.case.resource.type', 'Type', domain="[('object_id.model', '=', 'project.issue')]"),
-        'date_closed': fields.date('Close Date', readonly=True),
-        'assigned_to' : fields.many2one('res.users', 'Assigned to',readonly=True),
+        'version_id': fields.many2one('project.issue.version', 'Version'),
+        'user_id' : fields.many2one('res.users', 'Assigned to',readonly=True),
         'partner_id': fields.many2one('res.partner','Partner',domain="[('object_id.model', '=', 'project.issue')]"),
-        'canal_id': fields.many2one('res.partner.canal', 'Channel',readonly=True),
-        'task_id': fields.many2one('project.task', 'Task',domain="[('object_id.model', '=', 'project.issue')]" )
+        'channel_id': fields.many2one('crm.case.channel', 'Channel',readonly=True),
+        'task_id': fields.many2one('project.task', 'Task',domain="[('object_id.model', '=', 'project.issue')]" ),
+        'email': fields.integer('# Emails', size=128, readonly=True),
     }
 
     def init(self, cr):
         tools.drop_view_if_exists(cr, 'project_issue_report')
         cr.execute("""
-            create or replace view project_issue_report as (
-                select
-                    min(c.id) as id,
+            CREATE OR REPLACE VIEW project_issue_report AS (
+                SELECT
+                    c.id as id,
                     to_char(c.create_date, 'YYYY') as name,
                     to_char(c.create_date, 'MM') as month,
                     to_char(c.create_date, 'YYYY-MM-DD') as day,
@@ -103,52 +87,26 @@ class project_issue_report(osv.osv):
                     c.working_hours_close,
                     c.section_id,
                     c.categ_id,
-                    c.stage_id,
+                    c.type_id,
                     to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
                     c.company_id as company_id,
                     c.priority as priority,
                     c.project_id as project_id,
-                    c.type_id as type_id,
-                    (select 1) as nbr,
-                    c.assigned_to,
+                    c.version_id as version_id,
+                    1 as nbr,
                     c.partner_id,
-                    c.canal_id,
+                    c.channel_id,
                     c.task_id,
                     date_trunc('day',c.create_date) as create_date,
-                    avg(extract('epoch' from (c.date_open-c.create_date)))/(3600*24) as  delay_open,
-                    avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as  delay_close
-                from
+                    extract('epoch' from (c.date_open-c.create_date))/(3600*24) as  delay_open,
+                    extract('epoch' from (c.date_closed-c.date_open))/(3600*24) as  delay_close,
+                    (SELECT count(id) FROM mail_message WHERE model='project.issue' AND res_id=c.id) AS email
+
+                FROM
                     project_issue c
-                where c.categ_id in (select res_id from ir_model_data where name='bug_categ')
-                group by
-                    to_char(c.create_date, 'YYYY'),
-                    to_char(c.create_date, 'MM'),
-                    to_char(c.create_date, 'YYYY-MM-DD'),
-                    c.state,
-                    to_char(c.date_open, 'YYYY-MM-DD'),
-                    to_char(c.date_closed, 'YYYY-mm-dd'),
-                    c.user_id,
-                    c.section_id,
-                    c.categ_id,
-                    c.stage_id,
-                    c.company_id,
-                    c.priority,
-                    c.working_hours_open,
-                    c.working_hours_close,
-                    c.project_id,
-                    to_char(c.date_closed, 'YYYY-MM-DD'),
-                    c.type_id,
-                    c.working_hours_open,
-                    c.working_hours_close,
-                    date_trunc('day',c.create_date),
-                    c.assigned_to,
-                    c.partner_id,
-                    c.canal_id,
-                    c.task_id
-            )""") 
+                WHERE c.active= 'true' and c.categ_id IN (select id from crm_case_categ where object_id in (select id from ir_model where model = 'project.issue'))
+            )""")
 
 project_issue_report()
 
-
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: