[FIX] rename et_ET.po to et_EE.po
[odoo/odoo.git] / addons / report_document / report_document.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31 #
32 ##############################################################################
33
34 from osv import fields,osv
35 import time
36
37
38 class report_document_user(osv.osv):
39     _name = "report.document.user"
40     _description = "Files details by Users"
41     _auto = False
42     _columns = {
43         'name': fields.date('Month', readonly=True),
44         'month': fields.char('Month', size=24,readonly=True),
45         'user_id':fields.integer('Owner', readonly=True),
46         'user':fields.char('User',size=64,readonly=True),
47         'file_title': fields.char('File Name',size=64,readonly=True),
48         'directory': fields.char('Directory',size=64,readonly=True),
49         'create_date': fields.datetime('Date Created', readonly=True),
50         'change_date': fields.datetime('Modified Date', readonly=True),
51         'file_size': fields.integer('File Size', readonly=True),
52         'nbr':fields.integer('# of Files', readonly=True),
53         'type':fields.char('Directory Type',size=64,readonly=True),
54         'partner':fields.char('Partner',size=64,readonly=True),
55      }
56     def init(self, cr):
57          cr.execute("""
58             create or replace view report_document_user as (
59                  select
60                      min(f.id) as id,
61                      f.user_id as user_id,
62                      u.name as user,
63                      count(*) as nbr,
64                      to_char(f.create_date,'YYYY-MM')||'-'||'01' as name,
65                      d.name as directory,
66                      f.create_date as create_date,
67                      f.file_size as file_size,
68                      min(f.title) as file_title,
69                      min(d.type) as type,
70                      min(EXTRACT(MONTH FROM f.create_date)||'-'||to_char(f.create_date,'Month')) as month,
71                      f.write_date as change_date
72                  from ir_attachment f
73                      left join document_directory d on (f.parent_id=d.id and d.name<>'')
74                      inner join res_users u on (f.user_id=u.id)
75                  group by d.name,f.parent_id,d.type,f.create_date,f.user_id,f.file_size,u.name,d.type,f.write_date
76              )
77          """)
78 report_document_user()
79
80 class report_files_partner(osv.osv):
81     _name = "report.files.partner"
82     _description = "Files details by Partners"
83     _auto = False
84     _columns = {
85         'name': fields.date('Month', readonly=True),
86         'file_title': fields.char('File Name',size=64,readonly=True),
87         'directory': fields.char('Directory',size=64,readonly=True),
88         'create_date': fields.datetime('Date Created', readonly=True),
89         'change_date': fields.datetime('Modified Date', readonly=True),
90         'file_size': fields.integer('File Size', readonly=True),
91         'nbr':fields.integer('# of Files', readonly=True),
92         'type':fields.char('Directory Type',size=64,readonly=True),
93         'partner':fields.char('Partner',size=64,readonly=True),
94      }
95     def init(self, cr):
96          cr.execute("""
97             create or replace view report_files_partner as (
98                 select min(f.id) as id,count(*) as nbr,
99                        min(to_char(f.create_date,'YYYY-MM-01')) as name,
100                        min(f.title) as file_title,
101                        p.name as partner 
102                 from ir_attachment f 
103                 inner join res_partner p 
104                 on (f.partner_id=p.id) 
105                 group by p.name
106              )
107          """)
108 report_files_partner()
109
110 class report_document_file(osv.osv):
111     _name = "report.document.file"
112     _description = "Files details by Directory"
113     _auto = False
114     _columns = {
115         'file_size': fields.integer('File Size', readonly=True),
116         'nbr':fields.integer('# of Files', readonly=True),
117         'month': fields.char('Month', size=24,readonly=True),
118      }
119     _order = "month"
120     def init(self, cr):
121          cr.execute("""
122             create or replace view report_document_file as (
123                 select min(f.id) as id,
124                        count(*) as nbr,
125                        min(EXTRACT(MONTH FROM f.create_date)||'-'||to_char(f.create_date,'Month')) as month,
126                        sum(f.file_size) as file_size  
127                 from ir_attachment f 
128                 group by EXTRACT(MONTH FROM f.create_date) 
129              )
130          """)
131         
132 report_document_file()
133
134 class report_document_wall(osv.osv):
135     _name = "report.document.wall"
136     _description = "Users that did not inserted documents since one month"
137     _auto = False
138     _columns = {
139         'name': fields.date('Month', readonly=True),
140         'user_id':fields.many2one('res.users', 'Owner',readonly=True),
141         'user':fields.char('User',size=64,readonly=True),
142         'month': fields.char('Month', size=24,readonly=True),
143         'file_name':fields.char('Last Posted File Name',size=64,readonly=True),
144         'last':fields.datetime('Last Posted Time', readonly=True),
145              }
146        
147     def init(self, cr):
148          cr.execute("""
149             create or replace view report_document_wall as (
150                select max(f.id) as id,
151                min(title) as file_name,
152                to_char(min(f.create_date),'YYYY-MM-DD HH24:MI:SS') as last,
153                f.user_id as user_id, f.user_id as user,
154                to_char(f.create_date,'Month') as month 
155                from ir_attachment f 
156                where f.create_date in (
157                    select max(i.create_date) 
158                    from ir_attachment i 
159                    inner join res_users u on (i.user_id=u.id) 
160                    group by i.user_id) group by f.user_id,f.create_date 
161                    having (CURRENT_DATE - to_date(to_char(f.create_date,'YYYY-MM-DD'),'YYYY-MM-DD')) > 30
162              )
163          """)
164 report_document_wall()
165 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
166