[ADD] hr_timesheet: Print Employee Timesheet and Users Timesheet => OSV Memory

bzr revid: mra@tinyerp.com-20100420061138-bpn2ai9nebmdhqh5
This commit is contained in:
mra (Open ERP) 2010-04-20 11:41:38 +05:30
parent 666a5203fe
commit c2bdeba0c2
9 changed files with 155 additions and 121 deletions

View File

@ -45,7 +45,8 @@ to set up a management by affair.
'hr_timesheet_report.xml',
'hr_timesheet_wizard.xml',
'process/hr_timesheet_process.xml',
'wizard/hr_timesheet_print_employee_view.xml'
'wizard/hr_timesheet_print_employee_view.xml',
'wizard/hr_timesheet_print_users_view.xml'
],
'demo_xml': ['hr_timesheet_demo.xml'],
'installable': True,

View File

@ -22,23 +22,23 @@
groups="hr.group_hr_manager"
/>-->
<wizard id="wizard_hr_timesheet_my" menu="False" model="hr.employee" name="hr.analytical.timesheet.my" string="Print My Timesheet"/>
<!-- <wizard id="wizard_hr_timesheet_my" menu="False" model="hr.employee" name="hr.analytical.timesheet.my" string="Print My Timesheet"/>
<menuitem
action="wizard_hr_timesheet_my"
id="menu_wizard_hr_timesheet_my"
parent="menu_hr_reporting_timesheet"
type="wizard"
groups="hr.group_hr_user"
/>
/>-->
<report auto="False" id="report_users_timesheet" menu="False" model="hr.employee" name="hr.analytical.timesheet_users" string="Employees Timesheet" xsl="hr_timesheet/report/users_timesheet.xsl"/>
<wizard id="wizard_hr_timesheet_users" menu="False" model="hr.employee" name="hr.analytical.timesheet_users" string="Employees Timesheet"/>
<menuitem
<!--<menuitem
action="wizard_hr_timesheet_users"
id="menu_wizard_hr_timesheet_users"
groups="hr.group_hr_manager"
parent="menu_hr_reporting_timesheet" type="wizard"/>
-->
</data>
</openerp>

View File

@ -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/>.
#
##############################################################################
@ -42,24 +42,24 @@ def emp_create_xml(cr, id, som, eom):
"and line.user_id=%s and line.date >= %s and line.date < %s "
"order by line.date",
(id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d')))
# Sum by day
month = {}
for presence in cr.dictfetchall():
day = int(presence['date'][-2:])
month[day] = month.get(day, 0.0) + presence['amount']
xml = '''
<time-element date="%s">
<amount>%.2f</amount>
</time-element>
'''
time_xml = ([xml % (day, amount) for day, amount in month.iteritems()])
# Computing the employee
cr.execute("select name from res_users where id=%s", (id,))
emp = cr.fetchone()[0]
# Computing the xml
xml = '''
<employee id="%d" name="%s">
@ -73,13 +73,13 @@ class report_custom(report_rml):
def get_month_name(self, cr, uid, month):
_months = {1:_("January"), 2:_("February"), 3:_("March"), 4:_("April"), 5:_("May"), 6:_("June"), 7:_("July"), 8:_("August"), 9:_("September"), 10:_("October"), 11:_("November"), 12:_("December")}
return _months[month]
def get_weekday_name(self, cr, uid, weekday):
_weekdays = {1:_('Mon'), 2:_('Tue'), 3:_('Wed'), 4:_('Thu'), 5:_('Fri'), 6:_('Sat'), 7:_('Sun')}
return _weekdays[weekday]
def create_xml(self, cr, uid, ids, data, context):
# Computing the dates (start of month: som, and end of month: eom)
som = datetime.date(data['form']['year'], data['form']['month'], 1)
eom = som + datetime.timedelta(lengthmonth(som.year, som.month))
@ -87,9 +87,9 @@ class report_custom(report_rml):
date_xml += ['<day number="%d" name="%s" weekday="%d" />' % (x, self.get_weekday_name(cr, uid, som.replace(day=x).weekday()+1), som.replace(day=x).weekday()+1) for x in range(1, lengthmonth(som.year, som.month)+1)]
date_xml.append('</days>')
date_xml.append('<cols>2.5cm%s,2cm</cols>\n' % (',0.7cm' * lengthmonth(som.year, som.month)))
emp_xml=''
for id in data['form']['user_ids'][0][2]:
for id in data['form']['user_ids']:
emp_xml += emp_create_xml(cr, id, som, eom)
# Computing the xml

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,13 @@
# 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 sign_in_out
import wizard_print_timesheet
import wizard_print_timesheet_users
import hr_timesheet_print_employee
import hr_timesheet_print_users
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,41 +18,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import datetime
import wizard
from osv import osv, fields
import netsvc
dates_form = '''<?xml version="1.0"?>
<form string="Choose your month">
<field name="month" />
<field name="year" />
<field name="user_id" colspan="3" />
</form>'''
dates_form_ro = '''<?xml version="1.0"?>
<form string="Choose your month">
<field name="month" />
<field name="year" />
<field name="user_id" colspan="3" readonly="1"/>
</form>'''
dates_fields = {
'month': dict(string=u'Month', type='selection', required=True, selection=[(x, datetime.date(2000, x, 1).strftime('%B')) for x in range(1, 13)]),
'year': dict(string=u'Year', type=u'integer', required=True),
'user_id' : dict(string=u'User', type='many2one', relation='res.users', required=True),
}
def _get_value(self, cr, uid, data, context):
today = datetime.date.today()
return dict(month=today.month, year=today.year, user_id=uid)
class analytical_timesheet_employee(osv.osv_memory):
_name = 'hr.analytical.timesheet.employee'
_description = 'Print Employee Timesheet'
_description = 'Print Employee Timesheet & Print My Timesheet'
_columns = {
'month': fields.selection([(x, datetime.date(2000, x, 1).strftime('%B')) for x in range(1, 13)],
'Month', required=True),
@ -82,20 +54,4 @@ class analytical_timesheet_employee(osv.osv_memory):
'datas': datas,
}
analytical_timesheet_employee()
class wizard_report_my(wizard.interface):
states = {
'init': {
'actions': [_get_value],
'result': {'type':'form', 'arch':dates_form_ro, 'fields':dates_fields, 'state':[ ('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'hr.analytical.timesheet', 'state':'end'}
}
}
wizard_report_my('hr.analytical.timesheet.my')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2,6 +2,7 @@
<openerp>
<data>
<!-- Print Employee Timesheet -->
<record id="view_hr_timesheet_employee" model="ir.ui.view">
<field name="name">hr.analytical.timesheet.employee.form</field>
<field name="model">hr.analytical.timesheet.employee</field>
@ -35,5 +36,40 @@
parent="menu_hr_reporting_timesheet"
groups="hr.group_hr_manager" />
<!-- Print My Timesheet -->
<record id="view_hr_timesheet_my" model="ir.ui.view">
<field name="name">hr.analytical.timesheet.my.form</field>
<field name="model">hr.analytical.timesheet.employee</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Print My Timesheet">
<group colspan="4" >
<field name="month" />
<field name="year" />
<field name="user_id" colspan="3" readonly="1" />
</group>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-print" string="Print" name="print_report" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_hr_timesheet_my" model="ir.actions.act_window">
<field name="name">Print My Timesheet</field>
<field name="res_model">hr.analytical.timesheet.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_hr_timesheet_my"/>
<field name="target">new</field>
</record>
<menuitem action="action_hr_timesheet_my"
id="menu_hr_timesheet_my"
parent="menu_hr_reporting_timesheet"
groups="hr.group_hr_user" />
</data>
</openerp>

View File

@ -0,0 +1,56 @@
# -*- 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 datetime
from osv import osv, fields
class analytical_timesheet_employees(osv.osv_memory):
_name = 'hr.analytical.timesheet.users'
_description = 'Print Employees Timesheet'
_columns = {
'month': fields.selection([(x, datetime.date(2000, x, 1).strftime('%B')) for x in range(1, 13)],
'Month', required=True),
'year': fields.integer('Year', required=True),
'user_ids': fields.many2many('res.users', 'timesheet_users_rel', 'timesheet_id', 'user_id', 'Users', required=True)
}
_defaults = {
'month': datetime.date.today().month,
'year': datetime.date.today().year,
}
def print_report(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids, context=context)[0]
datas = {
'ids': [],
'model': 'hr.employee',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'hr.analytical.timesheet_users',
'datas': datas,
}
analytical_timesheet_employees()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Print Employees Timesheets -->
<record id="view_hr_timesheet_users" model="ir.ui.view">
<field name="name">hr.analytical.timesheet.users.form</field>
<field name="model">hr.analytical.timesheet.users</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Employees Timesheet">
<group colspan="4" >
<field name="month" />
<field name="year" />
<field name="user_ids" colspan="3" />
</group>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-print" string="Print" name="print_report" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_hr_timesheet_users" model="ir.actions.act_window">
<field name="name">Employees Timesheet</field>
<field name="res_model">hr.analytical.timesheet.users</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_hr_timesheet_users"/>
<field name="target">new</field>
</record>
<menuitem action="action_hr_timesheet_users"
id="menu_hr_timesheet_users"
parent="menu_hr_reporting_timesheet"
groups="hr.group_hr_manager" />
</data>
</openerp>

View File

@ -1,56 +0,0 @@
# -*- 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 wizard
import datetime
form='''<?xml version="1.0"?>
<form string="Choose Users">
<field name="month"/>
<field name="year"/>
<field name="user_ids" colspan="3"/>
</form>'''
fields = {
'month': dict(string=u'Month', type='selection', required=True, selection=[(x, datetime.date(2000, x, 1).strftime('%B')) for x in range(1, 13)]),
'year': dict(string=u'Year', type='integer', required=True),
'user_ids': dict(string=u'Users', type='many2many', relation='res.users', required=True),
}
def _get_value(self, cr, uid, data, context):
today=datetime.date.today()
return dict(month=today.month, year=today.year)
class wizard_report(wizard.interface):
states={
'init':{
'actions':[_get_value],
'result':{'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
},
'report':{
'actions':[],
'result':{'type':'print', 'report':'hr.analytical.timesheet_users', 'state':'end'}
}
}
wizard_report('hr.analytical.timesheet_users')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: