a81688ba7419f96caecb3f83c7b74da1c10e418c
[odoo/odoo.git] / addons / report_account / report_receivable.py
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 class report_account_receivable(osv.osv):
33         _name = "report.account.receivable"
34         _description = "Receivable accounts"
35         _auto = False
36         _columns = {
37                 'name': fields.date('Month', readonly=True),
38                 'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
39                 'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
40                 'amount_revenue': fields.float('Est.Revenue', readonly=True),
41                 'amount_costs': fields.float('Est.Cost', readonly=True),
42                 'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
43                 'nbr': fields.integer('# of Cases', readonly=True),
44                 'probability': fields.float('Avg. Probability', readonly=True),
45                 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
46                 'delay_close': fields.integer('Delay to close', readonly=True),
47         }
48         _order = 'name desc, user_id, section_id'
49         def init(self, cr):
50                 cr.execute("""
51                         create or replace view report_crm_case_user as (
52                                 select
53                                         min(c.id) as id,
54                                         substring(c.create_date for 7)||'-01' as name,
55                                         c.state,
56                                         c.user_id,
57                                         c.section_id,
58                                         count(*) as nbr,
59                                         sum(planned_revenue) as amount_revenue,
60                                         sum(planned_cost) as amount_costs,
61                                         sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
62                                         avg(probability)::decimal(16,2) as probability,
63                                         to_char(avg(date_closed-c.create_date), 'DD"d" HH12:MI:SS') as delay_close
64                                 from
65                                         crm_case c
66                                 group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
67                         )""")
68 report_crm_case_user()