[ADD] hr_timesheet_attendance report
Provide a timesheet/attendance report independent from hr_timesheet_sheet.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import report
|
||||
@@ -0,0 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': "Timesheets/attendances reporting",
|
||||
'description': """
|
||||
""",
|
||||
'category': 'Hidden',
|
||||
'version': '0.1',
|
||||
|
||||
# any module necessary for this one to work correctly
|
||||
'depends': ['hr_timesheet', 'hr_attendance'],
|
||||
'data': ['report/hr_timesheet_attendance_report_view.xml'],
|
||||
'auto_install': True,
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import hr_timesheet_attendance_report
|
||||
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from openerp import api, fields, models, tools
|
||||
|
||||
class TimesheetAttendance(models.Model):
|
||||
_name = 'hr.timesheet.attendance.report'
|
||||
_auto = False
|
||||
|
||||
user_id = fields.Many2one('res.users')
|
||||
date = fields.Date()
|
||||
total_timesheet = fields.Float()
|
||||
total_attendance = fields.Float()
|
||||
total_difference = fields.Float()
|
||||
|
||||
def init(self, cr):
|
||||
cr.execute("""CREATE OR REPLACE VIEW %s AS (
|
||||
SELECT
|
||||
max(id) AS id,
|
||||
t.user_id,
|
||||
t.date,
|
||||
coalesce(sum(t.attendance), 0) AS total_attendance,
|
||||
coalesce(sum(t.timesheet), 0) AS total_timesheet,
|
||||
coalesce(sum(t.attendance), 0) - coalesce(sum(t.timesheet), 0) as total_difference
|
||||
FROM (
|
||||
SELECT
|
||||
-hr_attendance.id AS id,
|
||||
resource_resource.user_id AS user_id,
|
||||
hr_attendance.worked_hours AS attendance,
|
||||
NULL AS timesheet,
|
||||
date_trunc('day', hr_attendance.name) AS date
|
||||
FROM hr_attendance
|
||||
LEFT JOIN hr_employee ON hr_employee.id = hr_attendance.employee_id
|
||||
LEFT JOIN resource_resource on resource_resource.id = hr_employee.resource_id
|
||||
WHERE hr_attendance.action = 'sign_out'
|
||||
UNION ALL
|
||||
SELECT
|
||||
ts.id AS id,
|
||||
ts.user_id AS user_id,
|
||||
NULL AS attendance,
|
||||
ts.unit_amount AS timesheet,
|
||||
date_trunc('day', ts.date) AS date
|
||||
FROM account_analytic_line AS ts
|
||||
) AS t
|
||||
GROUP BY t.user_id, t.date
|
||||
ORDER BY t.date
|
||||
)
|
||||
""" % self._table)
|
||||
@@ -0,0 +1,48 @@
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="view_hr_timesheet_attendance_report_search" model="ir.ui.view">
|
||||
<field name="name">Search for HR timesheet attendance report</field>
|
||||
<field name="model">hr.timesheet.attendance.report</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="timesheet attendance">
|
||||
<filter name="week" string="This Week"
|
||||
domain="[
|
||||
'&',
|
||||
('date', '>=', (context_today() + relativedelta(weekday=0)).strftime('%Y-%m-%d')),
|
||||
('date', '<=', (context_today() + relativedelta(weekday=6)).strftime('%Y-%m-%d')) ,
|
||||
]"/>
|
||||
<filter name="month" string="This Month"
|
||||
domain="[
|
||||
'&',
|
||||
('date', '>=', (context_today() + relativedelta(day=1)).strftime('%Y-%m-%d')),
|
||||
('date', '<=', (context_today() + relativedelta(months=1, day=1, days=-1)).strftime('%Y-%m-%d')),
|
||||
]"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_hr_timesheet_attendance_report_pivot" model="ir.ui.view">
|
||||
<field name="name">HR timesheet attendance report: Pivot</field>
|
||||
<field name="model">hr.timesheet.attendance.report</field>
|
||||
<field name="arch" type="xml">
|
||||
<pivot string="timesheet attendance">
|
||||
<field name="user_id" type="row"/>
|
||||
<field name="date" interval="day" type="col"/>
|
||||
<field name="total_difference" type="measure" widget="float_time"/>
|
||||
</pivot>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hr_timesheet_attendance_report" model="ir.actions.act_window">
|
||||
<field name="name">HR Timesheet/Attendance Report</field>
|
||||
<field name="res_model">hr.timesheet.attendance.report</field>
|
||||
<field name="view_mode">pivot</field>
|
||||
<field name="context">{'search_default_week': True}</field>
|
||||
</record>
|
||||
|
||||
|
||||
<menuitem id="menu_hr_timesheet_attendance_report"
|
||||
parent="hr_timesheet.menu_timesheets_reports"
|
||||
action="action_hr_timesheet_attendance_report"
|
||||
name="Timesheet / Attendance"/>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user