Launchpad automatic translations update.
[odoo/odoo.git] / addons / event / report / report_event_registration.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import fields, osv
23 import tools
24
25 class report_event_registration(osv.osv):
26
27     _name = "report.event.registration"
28     _description = "Events Analysis"
29     _auto = False
30     _rec_name = 'date'
31     _columns = {
32         'date': fields.date('Event Start Date', readonly=True),
33         'year': fields.char('Year', size=4, readonly=True),
34         'month': fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
35             ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
36             ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
37         'event_id': fields.many2one('event.event', 'Event', required=True),
38         'draft_state': fields.integer(' # No of Draft Registrations', size=20),
39         'confirm_state': fields.integer(' # No of Confirmed Registrations', size=20),
40         'register_max': fields.integer('Maximum Registrations'),
41         'nbevent': fields.integer('Number Of Events'),
42         'type': fields.many2one('event.type', 'Event Type'),
43         'state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, required=True),
44         'user_id': fields.many2one('res.users', 'Responsible', readonly=True),
45         'speaker_id': fields.many2one('res.partner', 'Speaker', readonly=True),
46         'company_id': fields.many2one('res.company', 'Company', readonly=True),
47         'product_id': fields.many2one('product.product', 'Product', readonly=True),
48         'total': fields.float('Total'),
49         'section_id': fields.related('event_id', 'section_id', type='many2one', relation='crm.case.section', string='Sale Team', store=True, readonly=True),
50     }
51     _order = 'date desc'
52     def init(self, cr):
53         """
54         initialize the sql view for the event registration
55         cr -- the cursor
56         """
57         tools.drop_view_if_exists(cr, 'report_event_registration')
58         cr.execute("""
59          CREATE OR REPLACE view report_event_registration AS (
60                 SELECT
61                 id,
62                 event_id,
63                 date,
64                 user_id,
65                 section_id,
66                 company_id,
67                 product_id,
68                 speaker_id,
69                 year,
70                 month,
71                 nbevent,
72                 type,
73                 SUM(draft_state) AS draft_state,
74                 SUM(confirm_state) AS confirm_state,
75                 SUM(total) AS total,
76                 register_max,
77                 state
78                 FROM(
79                 SELECT
80                 MIN(e.id) AS id,
81                 e.id AS event_id,
82                 e.date_begin AS date,
83                 e.user_id AS user_id,
84                 e.section_id AS section_id,
85                 e.company_id AS company_id,
86                 e.product_id AS product_id,
87                 e.main_speaker_id AS speaker_id,
88                 to_char(e.date_begin, 'YYYY') AS year,
89                 to_char(e.date_begin, 'MM') AS month,
90                 count(e.id) AS nbevent,
91                 t.id AS type,
92                 CASE WHEN c.state IN ('draft') THEN c.nb_register ELSE 0 END AS draft_state,
93                 CASE WHEN c.state IN ('open','done') THEN c.nb_register ELSE 0 END AS confirm_state,
94                 CASE WHEN c.state IN ('done') THEN c.price_subtotal ELSE 0 END AS total,
95                 e.register_max AS register_max,
96                 e.state AS state
97                 FROM
98                 event_event e
99                 LEFT JOIN
100                     event_registration c ON (e.id=c.event_id)
101                 LEFT JOIN
102                     event_type t ON (e.type=t.id)
103                 WHERE c.active = 'true'
104                GROUP BY
105                     to_char(e.date_begin, 'YYYY'),
106                     to_char(e.date_begin, 'MM'),
107                     c.state,
108                     c.nb_register,
109                     t.id, e.id, e.date_begin, e.main_speaker_id,
110                     e.register_max, e.type, e.state, c.event_id, e.user_id,e.company_id,e.product_id,e.section_id,
111                     to_char(e.date_begin, 'YYYY-MM-DD'), c.id, c.price_subtotal )AS foo
112                 GROUP BY
113                 id,
114                 event_id,
115                 date,
116                 user_id,
117                 section_id,
118                 company_id,
119                 product_id,
120                 speaker_id,
121                 year,
122                 month,
123                 nbevent,
124                 type,
125                 register_max,
126                 state
127               )
128                 """)
129
130 report_event_registration()
131
132 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: