[FIX] Functional fields should have context as an argument when we use fnct_searc...
[odoo/odoo.git] / addons / hr_timesheet_sheet / hr_timesheet_sheet.py
index 1aa4673..0426b24 100644 (file)
@@ -300,9 +300,12 @@ class hr_timesheet_sheet(osv.osv):
                     context, load='_classic_write')]
 
     def unlink(self, cr, uid, ids, context=None):
-        sheets = self.read(cr, uid, ids, ['state'])
-        if any(s['state'] in ('confirm', 'done') for s in sheets):
-            raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which are already confirmed !'))
+        sheets = self.read(cr, uid, ids, ['state','total_attendance'])
+        for sheet in sheets:
+            if sheet['state'] in ('confirm', 'done'):
+                raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which are already confirmed !'))
+            elif sheet['total_attendance'] <> 0.00:
+                raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which have attendance entries encoded !'))
         return super(hr_timesheet_sheet, self).unlink(cr, uid, ids, context=context)
 
 hr_timesheet_sheet()
@@ -343,7 +346,7 @@ class hr_timesheet_line(osv.osv):
                 res[line_id] = False
         return res
 
-    def _sheet_search(self, cursor, user, obj, name, args):
+    def _sheet_search(self, cursor, user, obj, name, args, context):
         if not len(args):
             return []
         sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
@@ -369,7 +372,7 @@ class hr_timesheet_line(osv.osv):
                 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
                     qu1.append('(s.id IS NOT NULL)')
                 else:
-                    qu1.append('(s.id %s %s)' % (x[1], '%d'))
+                    qu1.append('(s.id %s %s)' % (x[1], '%s'))
                     qu2.append(x[2])
             elif x[1] == 'in':
                 if len(x[2]) > 0:
@@ -486,7 +489,7 @@ class hr_attendance(osv.osv):
                 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
                     qu1.append('(s.id IS NOT NULL)')
                 else:
-                    qu1.append('(s.id %s %s)' % (x[1], '%d'))
+                    qu1.append('(s.id %s %s)' % (x[1], '%s'))
                     qu2.append(x[2])
             elif x[1] == 'in':
                 if len(x[2]) > 0:
@@ -503,8 +506,8 @@ class hr_attendance(osv.osv):
                     LEFT JOIN (hr_attendance a \
                         LEFT JOIN hr_employee e \
                             ON (a.employee_id = e.id)) \
-                        ON (s.date_to >= a.name \
-                            AND s.date_from <= a.name \
+                        ON (s.date_to >= a.name::date \
+                            AND s.date_from <= a.name::date \
                             AND s.user_id = e.user_id) ' + \
                 qu1, qu2)
         res = cursor.fetchall()
@@ -576,7 +579,7 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
                 sheet_id,
                 total_timesheet,
                 total_attendance,
-                (total_attendance - total_timesheet) AS total_difference
+                cast(round(cast(total_attendance - total_timesheet as Numeric),2) as Double Precision) AS total_difference
             FROM
                 ((
                     SELECT
@@ -623,8 +626,8 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
                                     LEFT JOIN hr_employee e
                                     ON (s.user_id = e.user_id))
                                 ON (a.employee_id = e.id
-                                    AND s.date_to >= a.name
-                                    AND s.date_from <= a.name)
+                                    AND s.date_to >= a.name::date
+                                    AND s.date_from <= a.name::date)
                             WHERE action in ('sign_in', 'sign_out')
                             group by a.name::date, s.id
                         )) AS foo