[IMP] remove unnecessary changes.
[odoo/odoo.git] / addons / document / report / document_report.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
23 from osv import fields,osv
24 import tools
25
26 class report_document_user(osv.osv):
27     _name = "report.document.user"
28     _description = "Files details by Users"
29     _auto = False
30     _columns = {
31         'name': fields.char('Year', size=64,readonly=True),
32         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
33                                   ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
34         'user_id':fields.integer('Owner', readonly=True),
35         'user': fields.related('user_id', 'name', type='char', size=64, readonly=True),
36         'directory': fields.char('Directory',size=64,readonly=True),
37         'datas_fname': fields.char('File Name',size=64,readonly=True),
38         'create_date': fields.datetime('Date Created', readonly=True),
39         'change_date': fields.datetime('Modified Date', readonly=True),
40         'file_size': fields.integer('File Size', readonly=True),
41         'nbr':fields.integer('# of Files', readonly=True),
42         'type':fields.char('Directory Type',size=64,readonly=True),
43      }
44     def init(self, cr):
45         tools.drop_view_if_exists(cr, 'report_document_user')
46         cr.execute("""
47             CREATE OR REPLACE VIEW report_document_user as (
48                  SELECT
49                      min(f.id) as id,
50                      to_char(f.create_date, 'YYYY') as name,
51                      to_char(f.create_date, 'MM') as month,
52                      f.user_id as user_id,
53                      count(*) as nbr,
54                      d.name as directory,
55                      f.datas_fname as datas_fname,
56                      f.create_date as create_date,
57                      f.file_size as file_size,
58                      min(d.type) as type,
59                      f.write_date as change_date
60                  FROM ir_attachment f
61                      left join document_directory d on (f.parent_id=d.id and d.name<>'')
62                  group by to_char(f.create_date, 'YYYY'), to_char(f.create_date, 'MM'),d.name,f.parent_id,d.type,f.create_date,f.user_id,f.file_size,d.type,f.write_date,f.datas_fname
63              )
64         """)
65
66
67 class report_document_file(osv.osv):
68     _name = "report.document.file"
69     _description = "Files details by Directory"
70     _auto = False
71     _columns = {
72         'file_size': fields.integer('File Size', readonly=True),
73         'nbr':fields.integer('# of Files', readonly=True),
74         'month': fields.char('Month', size=24,readonly=True),
75      }
76     _order = "month"
77     def init(self, cr):
78         tools.drop_view_if_exists(cr, 'report_document_file')
79         cr.execute("""
80             create or replace view report_document_file as (
81                 select min(f.id) as id,
82                        count(*) as nbr,
83                        min(EXTRACT(MONTH FROM f.create_date)||'-'||to_char(f.create_date,'Month')) as month,
84                        sum(f.file_size) as file_size
85                 from ir_attachment f
86                 group by EXTRACT(MONTH FROM f.create_date)
87              )
88         """)
89
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
91