[FIX] hr_timesheet_sheet: forbid to record an attendance in a submitted timesheet...
authorMartin Trigaux <mat@openerp.com>
Fri, 25 Apr 2014 10:08:56 +0000 (12:08 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 25 Apr 2014 10:08:56 +0000 (12:08 +0200)
bzr revid: mat@openerp.com-20140425100856-lcpgyjdk4u632bws

1  2 
addons/hr_timesheet_sheet/hr_timesheet_sheet.py

@@@ -390,18 -391,21 +391,22 @@@ class hr_attendance(osv.osv)
              attendance_ids.extend([row[0] for row in cr.fetchall()])
          return attendance_ids
  
+     def _get_current_sheet(self, cr, uid, employee_id, date=False, context=None):
+         if not date:
+             date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
++        # ending date with no time to avoid timesheet with early date_to
+         date_to = date[0:10]+' 00:00:00'
+         # limit=1 because only one sheet possible for an employee between 2 dates
+         sheet_ids = self.pool.get('hr_timesheet_sheet.sheet').search(cr, uid, [
+             ('date_to', '>=', date_to), ('date_from', '<=', date),
+             ('employee_id', '=', employee_id)
+         ], limit=1, context=context)
+         return sheet_ids and sheet_ids[0] or False
      def _sheet(self, cursor, user, ids, name, args, context=None):
-         sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
          res = {}.fromkeys(ids, False)
          for attendance in self.browse(cursor, user, ids, context=context):
-             date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S')
-             sheet_ids = sheet_obj.search(cursor, user,
-                 [('date_to', '>=', date_to), ('date_from', '<=', attendance.name),
-                  ('employee_id', '=', attendance.employee_id.id)],
-                 context=context)
-             if sheet_ids:
-                 # [0] because only one sheet possible for an employee between 2 dates
-                 res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
+             res[attendance.id] = self._get_current_sheet(cursor, user, attendance.employee_id.id, attendance.name, context=context)
          return res
  
      _columns = {