[ADD]:create SQL report for hr_timesheetline.

bzr revid: apa@tinyerp.com-20100414121543-6ua7o6nbwdpw1l6a
This commit is contained in:
apa-tiny 2010-04-14 17:45:43 +05:30
parent 9da45d3b15
commit 7c55f0c403
2 changed files with 148 additions and 21 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@ -15,13 +15,67 @@
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields,osv
from tools.sql import drop_view_if_exists
class report_timesheet_line(osv.osv):
_name = "report.timesheet.line"
_description = "Timesheet Line"
_auto = False
_columns = {
'name': fields.char('Year',size=64,required=False, readonly=True),
'user_id':fields.many2one('res.users', 'User', readonly=True),
'date' : fields.date('Date', readonly=True),
'quantity': fields.float('Quantity', readonly=True),
'cost': fields.float('Cost', readonly=True),
'product_id' : fields.many2one('product.product', 'Product',readonly=True),
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
'general_account_id' : fields.many2one('account.account', 'General Account', readonly=True),
'invoice_id': fields.many2one('account.invoice', 'Invoiced', 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),
}
_order = 'name desc,user_id desc'
def init(self, cr):
drop_view_if_exists(cr, 'report_timesheet_line')
cr.execute("""
create or replace view report_timesheet_line as (
select
min(l.id) as id,
to_char(l.date,'YYYY') as name,
to_char(l.date,'MM') as month,
l.user_id,
l.date,
l.invoice_id,
l.product_id,
l.account_id,
l.general_account_id,
sum(l.unit_amount) as quantity,
sum(l.amount) as cost
from
account_analytic_line l
where
l.user_id is not null
group by
l.date,
to_char(l.date,'YYYY'),
to_char(l.date,'MM'),
l.user_id,
l.product_id,
l.account_id,
l.general_account_id,
l.invoice_id
)
""")
report_timesheet_line()
class report_timesheet_user(osv.osv):
_name = "report_timesheet.user"
_description = "Timesheet per day"
@ -102,7 +156,7 @@ class report_timesheet_account_date(osv.osv):
('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
}
_order = 'name desc,account_id desc,user_id desc'
def init(self, cr):
drop_view_if_exists(cr, 'report_timesheet_account_date')
cr.execute("""
@ -167,7 +221,7 @@ class report_random_timsheet(osv.osv):
_name = "report.random.timesheet"
_description = "Random Timesheet Report"
_auto = False
_columns = {
'analytic_account_id' : fields.many2one('account.analytic.account','Analytic Account', readonly=True),
'name': fields.char('Description', size=64, readonly=True),
@ -176,34 +230,34 @@ class report_random_timsheet(osv.osv):
'user_id' : fields.many2one('res.users', 'User', readonly=True)
}
_order = "date desc"
def __init__(self, pool, cr):
super(report_random_timsheet, self).__init__(pool, cr)
self.called = False
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
""" To call the init() method timely
"""
if not self.called:
self.init(cr, user)
self.called = True # To make sure that init doesn't get called multiple times
res = super(report_random_timsheet, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
return res
def init(self, cr, uid=1):
drop_view_if_exists(cr, 'report_random_timesheet')
cr.execute("""create or replace view report_random_timesheet as (
select
select
line.id as id, line.account_id as analytic_account_id, line.name as name,
line.unit_amount as quantity, line.date as date, line.user_id as user_id
from
from
account_analytic_line line, hr_department dept,hr_department_user_rel dept_user
where
(dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)
AND (dept.manager_id = """ + str(uid) + """ )
AND (dept.manager_id = """ + str(uid) + """ )
AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))
LIMIT 10
)
@ -215,32 +269,32 @@ class random_timesheet_lines(osv.osv):
_name = "random.timesheet.lines"
_description = "Random Timesheet Lines"
_auto = False
_columns = {
'date': fields.date('Date', readonly=True),
'date': fields.date('Date', readonly=True),
'name': fields.char('Description', size=64, readonly=True),
'user_id' : fields.many2one('res.users', 'User', readonly=True),
'quantity' : fields.float('Quantity', readonly=True),
'product_id' : fields.many2one('product.product', 'Product', readonly=True),
'product_id' : fields.many2one('product.product', 'Product', readonly=True),
'analytic_account_id' : fields.many2one('account.analytic.account','Analytic Account', readonly=True),
'uom_id' : fields.many2one('product.uom', 'UoM', readonly=True),
'amount' : fields.float('Amount', readonly=True),
'to_invoice': fields.many2one('hr_timesheet_invoice.factor', 'Invoicing', readonly=True),
'general_account_id' : fields.many2one('account.account', 'General Account', readonly=True)
}
_order = "date desc"
def init(self, cr):
drop_view_if_exists(cr, 'random_timesheet_lines')
cr.execute("""create or replace view random_timesheet_lines as (
select
select
line.id as id, line.date as date, line.name as name, line.unit_amount as quantity,
line.product_id as product_id, line.account_id as analytic_account_id,
line.product_uom_id as uom_id, line.amount as amount, line.to_invoice as to_invoice,
line.general_account_id as general_account_id, line.user_id as user_id
from
line.general_account_id as general_account_id, line.user_id as user_id
from
account_analytic_line line
where
(line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-15))

View File

@ -6,6 +6,79 @@
name="Reporting"
parent="hr.menu_hr_root"
sequence="40" />
<record id="view_timesheet_line_graph" model="ir.ui.view">
<field name="name">report.timesheet.line.graph</field>
<field name="model">report.timesheet.line</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Timesheet Line" type="bar">
<field name="account_id"/>
<field name="quantity" operator="+"/>
<field group="True" name="user_id"/>
</graph>
</field>
</record>
<record id="view_timesheet_line_tree" model="ir.ui.view">
<field name="name">report.timesheet.line.tree</field>
<field name="model">report.timesheet.line</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Timesheet Line">
<field name="date"/>
<field name="quantity"/>
<field name="cost"/>
<field name="user_id"/>
<field name="name" invisible="1"/>
<field name="month" invisible="1"/>
<field name="account_id" invisible="1"/>
<field name="product_id" invisible="1"/>
<field name="invoice_id" invisible="1"/>
</tree>
</field>
</record>
<record id="view_timesheet_line_search" model="ir.ui.view">
<field name="name">report.timesheet.line.search</field>
<field name="model">report.timesheet.line</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Timesheet by user">
<group col="10" colspan="4">
<filter icon="terp-hr" string="This Year" domain="[('name','=',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 Line"
domain="[('user_id','=',uid)]"/></field>
<field name="account_id"/>
<field name="product_id"/>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="10" col="12">
<filter string="User" icon="terp-hr" context="{'group_by':'user_id'}"/>
<filter string="Account" icon="terp-hr" context="{'group_by':'account_id'}"/>
<filter string="Product" icon="terp-hr" context="{'group_by':'product_id'}"/>
<separator orientation="vertical"/>
<filter string="Month" icon="terp-hr" context="{'group_by':'date'}"/>
<filter string="Year" icon="terp-hr" context="{'group_by':'name'}"/>
</group>
</search>
</field>
</record>
<record id="action_timesheet_line_stat_all" model="ir.actions.act_window">
<field name="name">Timesheet Line</field>
<field name="res_model">report.timesheet.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="search_view_id" ref="view_timesheet_line_search"/>
</record>
<menuitem action="action_timesheet_line_stat_all" id="menu_report_timesheet_line_all" parent="hr.menu_hr_reporting"/>
<!-- Statistics report on timesheet by user -->
<record id="view_timesheet_user_graph" model="ir.ui.view">