[FIX] hr_timesheet: Improved timesheet report (solved confusion between user and...
authorpso <pso@tinyerp.com>
Tue, 2 Nov 2010 13:50:24 +0000 (19:20 +0530)
committerpso <pso@tinyerp.com>
Tue, 2 Nov 2010 13:50:24 +0000 (19:20 +0530)
lp bug: https://launchpad.net/bugs/669533 fixed

bzr revid: pso@tinyerp.com-20101102135024-jiqodh1tkynyxgsh

addons/hr_timesheet/report/user_timesheet.py
addons/hr_timesheet/report/users_timesheet.py

index 93c425a..404876b 100644 (file)
@@ -44,6 +44,12 @@ class report_custom(report_rml):
 
     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))
@@ -63,7 +69,7 @@ class report_custom(report_rml):
             "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 = {}
@@ -84,7 +90,7 @@ class report_custom(report_rml):
         <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():
@@ -96,10 +102,6 @@ class report_custom(report_rml):
             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>
@@ -107,7 +109,7 @@ class report_custom(report_rml):
         <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')
index 5a52e9c..f7f78d7 100644 (file)
@@ -33,7 +33,7 @@ def lengthmonth(year, month):
         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 "\
@@ -58,10 +58,6 @@ def emp_create_xml(cr, id, som, eom):
     '''
     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">
@@ -94,8 +90,9 @@ class report_custom(report_rml):
         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)