change labels
[odoo/odoo.git] / addons / hr_timesheet_sheet / report / timesheet_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 import tools
23 from osv import fields,osv
24
25 class timesheet_report(osv.osv):
26     _name = "timesheet.report"
27     _description = "Timesheet by month "
28     _auto = False
29     _columns = {
30         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
31             ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
32             ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
33         'no_of_timesheet': fields.integer('Total Timesheet',readonly=True),
34         'total_att': fields.float('Total Timesheet'),
35         'total_ts': fields.float('Total Attendance'),
36         'year': fields.char('Remaining leaves', size=4),
37         'name': fields.char('Name', size=64),
38         'user_id': fields.many2one('res.users','User'),
39         'leave_type': fields.char('Leave Type',size=64),
40         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
41                           ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
42         }
43
44     def init(self, cr):
45         tools.drop_view_if_exists(cr, 'timesheet_report')
46         cr.execute("""
47             create or replace view timesheet_report as (
48                     SELECT sheet.name as name, 
49                            min(sheet.id) as id,
50                            to_char(sheet.date_current, 'YYYY') as year,
51                            to_char(sheet.date_current, 'MM') as month,
52                            sum(day.total_attendance) as total_att,
53                            sum(day.total_timesheet) as total_ts,
54                            sheet.user_id as user_id
55                     FROM hr_timesheet_sheet_sheet AS sheet
56                     LEFT JOIN hr_timesheet_sheet_sheet_day AS day
57                     ON (sheet.id = day.sheet_id)
58                     GROUP BY sheet.name, year, month, user_id
59                     ) """)
60
61 timesheet_report()