[ADD]:Added SQL view report for hr_expense.
bzr revid: apa@tinyerp.com-20100312111446-k4mw36hv3hkqn0ss
This commit is contained in:
parent
71053a2fa9
commit
1ecc1674ab
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -15,7 +15,7 @@
|
|||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
@ -48,7 +48,8 @@
|
|||
'hr_expense_workflow.xml',
|
||||
'hr_expense_view.xml',
|
||||
'hr_expense_report.xml',
|
||||
'process/hr_expense_process.xml'
|
||||
'process/hr_expense_process.xml',
|
||||
'report/hr_expense_report_view.xml'
|
||||
],
|
||||
'demo_xml': ['hr.expense.expense.csv'],
|
||||
'installable': True,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -15,10 +15,11 @@
|
|||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
import expense
|
||||
import hr_expense_report
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import tools
|
||||
from osv import fields,osv
|
||||
|
||||
|
||||
class hr_expense_report(osv.osv):
|
||||
_name = "hr.expense.report"
|
||||
_description = "Expenses Statistics"
|
||||
_auto = False
|
||||
_rec_name = 'date'
|
||||
_columns = {
|
||||
'date': fields.date('Date', readonly=True),
|
||||
'year': fields.char('Year', size=4, 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),
|
||||
'product_id':fields.many2one('product.product', 'Product', readonly=True),
|
||||
'product_qty':fields.float('Qty', readonly=True),
|
||||
'employee_id': fields.many2one('hr.employee', "Employee's Name", readonly=True),
|
||||
'invoice_id': fields.many2one('account.invoice', 'Invoice',readonly=True),
|
||||
'department_id':fields.many2one('hr.department','Department',readonly=True),
|
||||
'company_id':fields.many2one('res.company', 'Company', readonly=True),
|
||||
'user_id':fields.many2one('res.users', 'User', readonly=True),
|
||||
'price_total':fields.float('Total Price', readonly=True),
|
||||
'price_average':fields.float('Average Price', readonly=True),
|
||||
'nbr':fields.integer('# of Lines', readonly=True),
|
||||
'state': fields.selection([
|
||||
('draft', 'Draft'),
|
||||
('confirm', 'Waiting confirmation'),
|
||||
('accepted', 'Accepted'),
|
||||
('invoiced', 'Invoiced'),
|
||||
('paid', 'Reimbursed'),
|
||||
('cancelled', 'Cancelled')],
|
||||
'State', readonly=True),
|
||||
}
|
||||
_order = 'date desc'
|
||||
def init(self, cr):
|
||||
tools.drop_view_if_exists(cr, 'hr_expense_report')
|
||||
cr.execute("""
|
||||
create or replace view hr_expense_report as (
|
||||
select
|
||||
min(l.id) as id,
|
||||
s.date as date,
|
||||
s.employee_id,
|
||||
s.invoice_id,
|
||||
s.department_id,
|
||||
to_char(s.date, 'YYYY') as year,
|
||||
to_char(s.date, 'MM') as month,
|
||||
l.product_id as product_id,
|
||||
sum(l.unit_quantity * u.factor) as product_qty,
|
||||
s.user_id as user_id,
|
||||
s.company_id as company_id,
|
||||
sum(l.unit_quantity*l.unit_amount) as price_total,
|
||||
(sum(l.unit_quantity*l.unit_amount)/sum(l.unit_quantity * u.factor))::decimal(16,2) as price_average,
|
||||
count(*) as nbr,
|
||||
s.state
|
||||
from
|
||||
hr_expense_line l
|
||||
left join
|
||||
hr_expense_expense s on (s.id=l.expense_id)
|
||||
left join product_uom u on (u.id=l.uom_id)
|
||||
group by
|
||||
s.date, l.product_id,s.invoice_id,
|
||||
s.department_id,
|
||||
l.uom_id, s.user_id, s.state,
|
||||
s.company_id,s.employee_id
|
||||
)
|
||||
""")
|
||||
hr_expense_report()
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_hr_expense_report_tree" model="ir.ui.view">
|
||||
<field name="name">hr.expense.report.tree</field>
|
||||
<field name="model">hr.expense.report</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Expenses Statistics">
|
||||
<field name="date"/>
|
||||
<field name="employee_id"/>
|
||||
<field name="user_id"/>
|
||||
<field name="year" invisible="1"/>
|
||||
<field name="month" invisible="1"/>
|
||||
<field name="invoice_id" invisible="1"/>
|
||||
<field name="department_id" invisible="1"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="nbr" sum="# of Lines"/>
|
||||
<field name="price_average" avg="Average Price"/>
|
||||
<field name="price_total" sum="Total Price"/>
|
||||
<field name="state" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_expense_report_graph" model="ir.ui.view">
|
||||
<field name="name">hr.expense.report.graph</field>
|
||||
<field name="model">hr.expense.report</field>
|
||||
<field name="type">graph</field>
|
||||
<field name="arch" type="xml">
|
||||
<graph string="Expenses Statistics" type="bar">
|
||||
<field name="product_id"/>
|
||||
<field name="price_total"/>
|
||||
</graph>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_expense_report_search" model="ir.ui.view">
|
||||
<field name="name">hr.expense.report.search</field>
|
||||
<field name="model">hr.expense.report</field>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Expenses">
|
||||
<filter icon="terp-hr"
|
||||
string="This Year"
|
||||
domain="[('year','=',time.strftime('%%Y'))]"
|
||||
help="Expenses of the year"/>
|
||||
<filter icon="terp-hr"
|
||||
string="This Month"
|
||||
domain="[('month','=',time.strftime('%%m'))]"
|
||||
help="Expenses of this month"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter icon="terp-hr"
|
||||
string="Draft"
|
||||
domain="[('state','=','draft')]"/>
|
||||
<filter icon="terp-hr"
|
||||
string="Expenses"
|
||||
default="1"
|
||||
domain="[('state','<>','draft'),('state','<>','cancelled')]"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="product_id"/>
|
||||
<field name="user_id" widget="selection">
|
||||
<filter icon="terp-hr"
|
||||
string="My Expenses"
|
||||
domain="[('user_id','=',uid)]"/>
|
||||
</field>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
|
||||
<newline/>
|
||||
<group expand="1" string="Group By..." colspan="10" col="12">
|
||||
<filter string="Company" icon="terp-hr" context="{'group_by':'company_id'}"/>
|
||||
<filter string="User" icon="terp-hr" context="{'group_by':'user_id'}" default="1"/>
|
||||
<filter string="Employee" icon="terp-hr" context="{'group_by':'employee_id'}"/>
|
||||
<filter string="Department" icon="terp-hr" context="{'group_by':'department_id'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Product" icon="terp-hr" context="{'group_by':'product_id'}"/>
|
||||
<filter string="State" icon="terp-hr" context="{'group_by':'state'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Month" icon="terp-hr" context="{'group_by':'date'}"/>
|
||||
<filter string="Year" icon="terp-hr" context="{'group_by':'year'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hr_expense_report_all" model="ir.actions.act_window">
|
||||
<field name="name">Expenses</field>
|
||||
<field name="res_model">hr.expense.report</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,graph</field>
|
||||
<field name="search_view_id" ref="view_hr_expense_report_search"/>
|
||||
</record>
|
||||
|
||||
<menuitem id="hr.menu_hr_reporting" name="Reporting" parent="hr.menu_hr_root" sequence="8"/>
|
||||
<menuitem action="action_hr_expense_report_all" id="menu_hr_expense_report_all" parent="hr.menu_hr_reporting" sequence="0"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue