def create_xml(self, cr, uid, ids, data, context):
+ # Get the user id from the selected employee record
+ emp_id = data['form']['employee_id']
+ emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
+ user_id = emp_obj.browse(cr, uid, emp_id).user_id.id
+ empl_name = emp_obj.browse(cr, uid, emp_id).name
+
# 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))
"and product_uom_id = unit.id "\
"and line.user_id=%s and line.date >= %s and line.date < %s "
"order by line.date",
- (uid, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d')))
+ (user_id, som.strftime('%Y-%m-%d'), eom.strftime('%Y-%m-%d')))
# Sum attendence by account, then by day
accounts = {}
<date>%s</date>
<company>%s</company>
</header>
- ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),pooler.get_pool(cr.dbname).get('res.users').browse(cr,uid,uid).company_id.name)
+ ''' % (str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")),pooler.get_pool(cr.dbname).get('res.users').browse(cr,uid,user_id).company_id.name)
account_xml = []
for account, telems in accounts.iteritems():
account_xml.append('\n'.join([xml % (day, amount) for day, amount in telems.iteritems()]))
account_xml.append('</account>')
- # Computing the employee
- cr.execute("select name from res_users where id=%s", (str(uid)))
- emp = cr.fetchone()[0]
-
# Computing the xml
xml = '''<?xml version="1.0" encoding="UTF-8" ?>
<report>
<employee>%s</employee>
%s
</report>
- ''' % (header_xml,toxml(emp), '\n'.join(date_xml) + '\n'.join(account_xml))
+ ''' % (header_xml,toxml(empl_name), '\n'.join(date_xml) + '\n'.join(account_xml))
return xml
report_custom('report.hr.analytical.timesheet', 'hr.employee', '', 'addons/hr_timesheet/report/user_timesheet.xsl')
return 29
return [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
-def emp_create_xml(cr, id, som, eom):
+def emp_create_xml(cr, id, som, eom, emp):
# Computing the attendence by analytical account
cr.execute(
"select line.date, (unit_amount * unit.factor) as amount "\
'''
time_xml = ([xml % (day, amount) for day, amount in month.iteritems()])
- # Computing the employee
- cr.execute("select name from resource_resource where id=%s", (id,))
- emp = cr.fetchone()[0]
-
# Computing the xml
xml = '''
<employee id="%d" name="%s">
emp_obj = pooler.get_pool(cr.dbname).get('hr.employee')
for id in data['form']['employee_ids']:
user = emp_obj.browse(cr, uid, id).user_id.id
+ empl_name = emp_obj.browse(cr, uid, id).name
if user:
- emp_xml += emp_create_xml(cr, id, som, eom)
+ emp_xml += emp_create_xml(cr, user, som, eom, empl_name)
# Computing the xml
#Without this, report don't show non-ascii characters (TO CHECK)
date_xml = '\n'.join(date_xml)