2010-06-25 10:07:43 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp import tools
from openerp . osv import fields , osv
2010-06-25 10:07:43 +00:00
class hr_timesheet_report ( osv . osv ) :
2014-06-16 10:08:26 +00:00
_inherit = " hr.timesheet.report "
2010-06-25 10:07:43 +00:00
_columns = {
2014-06-16 10:08:26 +00:00
' to_invoice ' : fields . many2one ( ' hr_timesheet_invoice.factor ' , ' Type of Invoicing ' , readonly = True ) ,
2014-08-21 10:53:47 +00:00
' nbr ' : fields . integer ( ' # Nbr Timesheet ' , readonly = True ) ,
' total_diff ' : fields . float ( ' # Total Diff ' , readonly = True ) ,
' total_timesheet ' : fields . float ( ' # Total Timesheet ' , readonly = True ) ,
' total_attendance ' : fields . float ( ' # Total Attendance ' , readonly = True ) ,
2014-06-16 10:08:26 +00:00
' department_id ' : fields . many2one ( ' hr.department ' , ' Department ' , readonly = True ) ,
' date_from ' : fields . date ( ' Date from ' , readonly = True , ) ,
' date_to ' : fields . date ( ' Date to ' , readonly = True ) ,
' state ' : fields . selection ( [
( ' new ' , ' New ' ) ,
( ' draft ' , ' Draft ' ) ,
( ' confirm ' , ' Confirmed ' ) ,
( ' done ' , ' Done ' ) ] , ' Status ' , readonly = True ) ,
}
def _select ( self ) :
2015-04-01 09:07:44 +00:00
return """
WITH
totals AS (
SELECT
d . sheet_id ,
d . name as date ,
sum ( total_difference ) / coalesce ( sum ( j . count ) , 1 ) as total_diff ,
sum ( total_timesheet ) / coalesce ( sum ( j . count ) , 1 ) as total_timesheet ,
sum ( total_attendance ) / coalesce ( sum ( j . count ) , 1 ) as total_attendance
FROM hr_timesheet_sheet_sheet_day d left join (
SELECT
h . sheet_id ,
a . date ,
count ( * )
FROM account_analytic_line a inner join hr_analytic_timesheet h ON ( h . line_id = a . id )
GROUP BY h . sheet_id , a . date
) j ON ( d . sheet_id = j . sheet_id AND d . name = j . date )
GROUP BY d . sheet_id , d . name
)
""" + super(hr_timesheet_report, self)._select() + """ ,
2014-06-16 10:08:26 +00:00
htss . name ,
htss . date_from ,
htss . date_to ,
count ( * ) as nbr ,
2015-04-01 09:07:44 +00:00
sum ( t . total_diff ) as total_diff ,
sum ( t . total_timesheet ) as total_timesheet ,
sum ( t . total_attendance ) as total_attendance ,
2014-06-16 10:08:26 +00:00
aal . to_invoice ,
htss . department_id ,
htss . state """
def _from ( self ) :
2015-04-01 09:07:44 +00:00
return super ( hr_timesheet_report , self ) . _from ( ) + " left join hr_timesheet_sheet_sheet as htss ON (hat.sheet_id=htss.id) join totals as t on (t.sheet_id = hat.sheet_id and t.date = aal.date) "
2014-06-16 10:08:26 +00:00
def _group_by ( self ) :
return super ( hr_timesheet_report , self ) . _group_by ( ) + """ ,
htss . date_from ,
htss . date_to ,
aal . unit_amount ,
aal . amount ,
aal . to_invoice ,
htss . name ,
htss . state ,
htss . id ,
htss . department_id """
2010-06-25 10:07:43 +00:00
2011-11-22 08:51:38 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: