~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to report_crm/report_crm.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: project.py 1005 2005-07-25 08:41:42Z nicoe $
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
from osv import fields,osv
 
31
 
 
32
AVAILABLE_STATES = [
 
33
        ('draft','Draft'),
 
34
        ('open','Open'),
 
35
        ('cancel', 'Canceled'),
 
36
        ('done', 'Closed'),
 
37
        ('pending','Pending')
 
38
]
 
39
 
 
40
class report_crm_case_user(osv.osv):
 
41
        _name = "report.crm.case.user"
 
42
        _description = "Cases by user and section"
 
43
        _auto = False
 
44
        _columns = {
 
45
                'name': fields.date('Month', readonly=True),
 
46
                'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
 
47
                'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
 
48
                'amount_revenue': fields.float('Est.Revenue', readonly=True),
 
49
                'amount_costs': fields.float('Est.Cost', readonly=True),
 
50
                'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
 
51
                'nbr': fields.integer('# of Cases', readonly=True),
 
52
                'probability': fields.float('Avg. Probability', readonly=True),
 
53
                'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
 
54
                'delay_close': fields.integer('Delay to close', readonly=True),
 
55
        }
 
56
        _order = 'name desc, user_id, section_id'
 
57
        def init(self, cr):
 
58
                cr.execute("""
 
59
                        create or replace view report_crm_case_user as (
 
60
                                select
 
61
                                        min(c.id) as id,
 
62
                                        substring(c.create_date for 7)||'-01' as name,
 
63
                                        c.state,
 
64
                                        c.user_id,
 
65
                                        c.section_id,
 
66
                                        count(*) as nbr,
 
67
                                        sum(planned_revenue) as amount_revenue,
 
68
                                        sum(planned_cost) as amount_costs,
 
69
                                        sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
 
70
                                        avg(probability)::decimal(16,2) as probability,
 
71
                                        to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
 
72
                                from
 
73
                                        crm_case c
 
74
                                group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
 
75
                        )""")
 
76
report_crm_case_user()
 
77
 
 
78
class report_crm_case_categ(osv.osv):
 
79
        _name = "report.crm.case.categ"
 
80
        _description = "Cases by section and category"
 
81
        _auto = False
 
82
        _columns = {
 
83
                'name': fields.date('Month', readonly=True),
 
84
                'categ_id':fields.many2one('crm.case.categ', 'Category', readonly=True, relate=True),
 
85
                'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
 
86
                'amount_revenue': fields.float('Est.Revenue', readonly=True),
 
87
                'amount_costs': fields.float('Est.Cost', readonly=True),
 
88
                'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
 
89
                'nbr': fields.integer('# of Cases', readonly=True),
 
90
                'probability': fields.float('Avg. Probability', readonly=True),
 
91
                'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
 
92
                'delay_close': fields.integer('Delay Close', readonly=True),
 
93
        }
 
94
        _order = 'name desc, categ_id, section_id'
 
95
        def init(self, cr):
 
96
                cr.execute("""
 
97
                        create or replace view report_crm_case_categ as (
 
98
                                select
 
99
                                        min(c.id) as id,
 
100
                                        substring(c.create_date for 7)||'-01' as name,
 
101
                                        c.state,
 
102
                                        c.categ_id,
 
103
                                        c.section_id,
 
104
                                        count(*) as nbr,
 
105
                                        sum(planned_revenue) as amount_revenue,
 
106
                                        sum(planned_cost) as amount_costs,
 
107
                                        sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
 
108
                                        avg(probability)::decimal(16,2) as probability,
 
109
                                        to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
 
110
                                from
 
111
                                        crm_case c
 
112
                                group by substring(c.create_date for 7), c.state, c.categ_id, c.section_id
 
113
                        )""")
 
114
report_crm_case_categ()