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()
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')
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()
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
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