[IMP]:hr_timesheet_sheet:Improved SQL report.(Timesheet).

bzr revid: apa@tinyerp.com-20100415053153-0tfauo2dz99bmcfu
This commit is contained in:
apa-tiny 2010-04-15 11:01:53 +05:30
parent 5529a6496e
commit c1e9307136
2 changed files with 149 additions and 58 deletions

View File

@ -24,38 +24,68 @@ from osv import fields,osv
class timesheet_report(osv.osv):
_name = "timesheet.report"
_description = "Timesheet by month "
_description = "Timesheet"
_auto = False
_columns = {
'year': fields.char('Year',size=64,required=False, readonly=True),
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
'no_of_timesheet': fields.integer('Total Timesheet',readonly=True),
'total_att': fields.float('Total Timesheet'),
'total_ts': fields.float('Total Attendance'),
'year': fields.char('Remaining leaves', size=4),
'name': fields.char('Name', size=64),
'user_id': fields.many2one('res.users','User'),
'leave_type': fields.char('Leave Type',size=64),
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
'name': fields.char('Description', size=64,readonly=True),
'user_id': fields.many2one('res.users', 'User',readonly=True),
'nbr': fields.integer('#Nbr',readonly=True),
'company_id': fields.many2one('res.company', 'Company',readonly=True),
'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),
'date_current': fields.date('Current date', required=True),
'state' : fields.selection([
('new', 'New'),
('draft','Draft'),
('confirm','Confirmed'),
('done','Done')], 'State', readonly=True),
'total_att': fields.float('Total Timesheet',readonly=True),
'total_ts': fields.float('Total Attendance',readonly=True),
'total_diff': fields.float('Difference', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'timesheet_report')
cr.execute("""
create or replace view timesheet_report as (
SELECT sheet.name as name,
min(sheet.id) as id,
to_char(sheet.date_current, 'YYYY') as year,
to_char(sheet.date_current, 'MM') as month,
sum(day.total_attendance) as total_att,
sum(day.total_timesheet) as total_ts,
sheet.user_id as user_id
FROM hr_timesheet_sheet_sheet AS sheet
LEFT JOIN hr_timesheet_sheet_sheet_day AS day
ON (sheet.id = day.sheet_id)
GROUP BY sheet.name, year, month, user_id
) """)
timesheet_report()
select
min(aal.id) as id,
htss.date_current,
htss.name,
htss.date_from,
htss.date_to,
to_char(htss.date_current,'YYYY') as year,
to_char(htss.date_current,'MM') as month,
count(*) as nbr,
sum(day.total_attendance) as total_att,
sum(day.total_timesheet) as total_ts,
sum(day.total_difference) as total_diff,
aal.account_id,
htss.user_id,
htss.company_id,
htss.department_id,
htss.state
from account_analytic_line as aal
left join hr_analytic_timesheet as hat ON (hat.line_id=aal.id)
left join hr_timesheet_sheet_sheet as htss ON (hat.line_id=htss.id)
left join hr_timesheet_sheet_sheet_day AS day ON (htss.id = day.sheet_id)
group by
to_char(htss.date_current,'YYYY'),
to_char(htss.date_current,'MM'),
aal.account_id,
htss.date_from,
htss.date_to,
htss.date_current,
htss.name,
htss.company_id,
htss.state,
htss.department_id,
htss.user_id
)
""")
timesheet_report()

View File

@ -1,38 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<data>
<record id="view_timesheet_report_graph" model="ir.ui.view">
<field name="name">timesheet.report.graph</field>
<field name="model">timesheet.report</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Timesheet" type="bar">
<field name="name" />
<field name="total_att" operator = "+"/>
<field name="total_ts" operator = "+"/>
<field name="user_id" group = "True"/>
</graph>
</field>
</record>
<record id="view_timesheet_report_tree" model="ir.ui.view">
<field name="name">timesheet.report.tree</field>
<field name="model">timesheet.report</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Timesheet">
<field name="date_current"/>
<field name="name"/>
<field name="user_id"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="total_att"/>
<field name="total_diff"/>
<field name="total_ts"/>
<field name="state"/>
<field name="department_id" invisible="1"/>
<field name="company_id" invisible="1"/>
<field name="name" invisible="1"/>
<field name="month" invisible="1"/>
</tree>
</field>
</record>
<record id="view_timesheet_report_search" model="ir.ui.view">
<field name="name">timesheet.report.search</field>
<field name="model">timesheet.report</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Timesheet">
<group col="10" colspan="4">
<filter icon="terp-hr" string="This Year" domain="[('year','=',time.strftime('%%Y'))]" help="Timesheet by user in this year"/>
<filter icon="terp-hr" string="This Month" domain="[('month','=',time.strftime('%%m'))]" help="Timesheet by user in this month"/>
<separator orientation="vertical"/>
<field name="user_id" widget="selection">
<filter icon="terp-hr"
string="My Timesheet"
domain="[('user_id','=',uid)]"/></field>
<field name="name"/>
<field name="department_id"/>
</group>
<newline/>
<group expand="1" string="Extended options..." colspan="10" col="12">
<filter icon="terp-hr"
string="New"
domain="[('state','=','new')]"/>
<filter icon="terp-hr"
string="Draft"
domain="[('state','=','draft')]"/>
<filter icon="terp-hr"
string="Confirmed"
domain="[('state','=','confirm')]"/>
<filter icon="terp-hr"
string="Done"
domain="[('state','=','done')]"/>
<newline/>
<field name="date_from"/>
<field name="date_to"/>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="10" col="12">
<filter string="User" name="User" icon="terp-hr" context="{'group_by':'user_id'}"/>
<filter string="Company" icon="terp-hr" context="{'group_by':'company_id'}"/>
<filter string="Department" icon="terp-hr" context="{'group_by':'department_id'}"/>
<separator orientation="vertical"/>
<filter string="State" icon="terp-hr" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<filter string="Month" icon="terp-hr" context="{'group_by':'date_current'}"/>
<filter string="Year" icon="terp-hr" context="{'group_by':'year'}"/>
</group>
</search>
</field>
</record>
<record id="view_timesheet_report_tree" model="ir.ui.view">
<field name="name">timesheet.report.tree</field>
<field name="model">timesheet.report</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="TimeSheet">
<field name="name"/>
<field name="total_att"/>
<field name="total_ts"/>
<field name="user_id" />
<field name="month" />
</tree>
</field>
</record>
<record id="view_timesheet_report_graph" model="ir.ui.view">
<field name="name">timesheet.report.graph</field>
<field name="model">timesheet.report</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="TimeSheet" type="bar">
<field name="name" />
<field name="total_att" operator = "+"/>
<field name="total_ts" operator = "+"/>
<field name="user_id" group = "True"/>
</graph>
</field>
</record>
</data>
<record id="action_timesheet_report_stat_all" model="ir.actions.act_window">
<field name="name">Timesheet</field>
<field name="res_model">timesheet.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="context">{'search_default_User': 1}</field>
<field name="search_view_id" ref="view_timesheet_report_search"/>
</record>
<menuitem action="action_timesheet_report_stat_all" id="menu_timesheet_report_all" parent="hr.menu_hr_reporting"/>
</data>
</openerp>