1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from osv import fields
28 from mx import DateTime
29 from tools.translate import _
32 class one2many_mod2(fields.one2many):
33 def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
38 res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context)
41 res6[r['id']] = (r['date_current'], r['user_id'][0])
47 dom = [('name', '>=', res6[id][0] + ' 00:00:00'),
48 ('name', '<=', res6[id][0] + ' 23:59:59'),
49 ('employee_id.user_id', '=', res6[id][1])]
50 ids2.extend(obj.pool.get(self._obj).search(cr, user,
51 dom, limit=self._limit))
53 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2,
54 [self._fields_id], context=context, load='_classic_write'):
55 if r[self._fields_id]:
56 res.setdefault(r[self._fields_id][0], []).append(r['id'])
60 def set(self, cr, obj, id, field, values, user=None, context=None):
63 context = context.copy()
64 context['sheet_id'] = id
65 return super(one2many_mod2, self).set(cr, obj, id, field, values, user=user,
69 class one2many_mod(fields.one2many):
70 def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
75 res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context)
78 res6[r['id']] = (r['date_current'], r['user_id'][0])
84 dom = [('date', '=', res6[id][0]), ('user_id', '=', res6[id][1])]
85 ids2.extend(obj.pool.get(self._obj).search(cr, user,
86 dom, limit=self._limit))
88 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2,
89 [self._fields_id], context=context, load='_classic_write'):
90 if r[self._fields_id]:
91 res.setdefault(r[self._fields_id][0], []).append(r['id'])
95 class hr_timesheet_sheet(osv.osv):
96 _name = "hr_timesheet_sheet.sheet"
97 _table = 'hr_timesheet_sheet_sheet'
100 def _total_day(self, cr, uid, ids, name, args, context):
101 field_name = name.strip('_day')
102 cr.execute('SELECT sheet.id, day.' + field_name +' \
103 FROM hr_timesheet_sheet_sheet AS sheet \
104 LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
105 ON (sheet.id = day.sheet_id \
106 AND day.name = sheet.date_current) \
107 WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')')
108 return dict(cr.fetchall())
110 def _total(self, cr, uid, ids, name, args, context):
111 cr.execute('SELECT s.id, COALESCE(SUM(d.' + name + '),0) \
112 FROM hr_timesheet_sheet_sheet s \
113 LEFT JOIN hr_timesheet_sheet_sheet_day d \
114 ON (s.id = d.sheet_id) \
115 WHERE s.id in ('+ ','.join(map(str, ids)) + ') \
117 return dict(cr.fetchall())
119 def _state_attendance(self, cr, uid, ids, name, args, context):
123 emp_obj = self.pool.get('hr.employee')
125 for sheet in self.browse(cr, uid, ids, context):
126 result[sheet.id] = 'none'
127 emp_ids2 = emp_obj.search(cr, uid,
128 [('user_id', '=', sheet.user_id.id)])
130 link_emp[emp_ids2[0]] = sheet.id
131 emp_ids.append(emp_ids2[0])
132 for emp in emp_obj.browse(cr, uid, emp_ids, context=context):
133 if emp.id in link_emp:
134 sheet_id = link_emp[emp.id]
135 result[sheet_id] = emp.state
138 def copy(self, cr, uid, ids, *args, **argv):
139 raise osv.except_osv(_('Error !'), _('You can not duplicate a timesheet !'))
141 def button_confirm(self, cr, uid, ids, context):
142 for sheet in self.browse(cr, uid, ids, context):
143 di = sheet.user_id.company_id.timesheet_max_difference
144 if (abs(sheet.total_difference) < di) or not di:
145 wf_service = netsvc.LocalService("workflow")
146 wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'confirm', cr)
148 raise osv.except_osv(_('Warning !'), _('Please verify that the total difference of the sheet is lower than %.2f !') %(di,))
151 def date_today(self, cr, uid, ids, context):
152 for sheet in self.browse(cr, uid, ids, context):
153 if DateTime.now() <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
154 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
155 elif DateTime.now() >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
156 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
158 self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')})
161 def date_previous(self, cr, uid, ids, context):
162 for sheet in self.browse(cr, uid, ids, context):
163 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
164 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
166 self.write(cr, uid, [sheet.id], {
167 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=-1)).strftime('%Y-%m-%d'),
171 def date_next(self, cr, uid, ids, context):
172 for sheet in self.browse(cr, uid, ids, context):
173 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
174 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
176 self.write(cr, uid, [sheet.id], {
177 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d'),
181 def button_dummy(self, cr, uid, ids, context):
182 for sheet in self.browse(cr, uid, ids, context):
183 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
184 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
185 elif DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
186 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
189 def sign_in(self, cr, uid, ids, context):
190 if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'):
191 raise osv.except_osv(_('Error !'), _('You can not sign in from an other date than today'))
192 emp_obj = self.pool.get('hr.employee')
193 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
194 context['sheet_id']=ids[0]
195 success = emp_obj.sign_in(cr, uid, emp_id, context=context)
198 def sign_out(self, cr, uid, ids, context):
199 if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'):
200 raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today'))
201 emp_obj = self.pool.get('hr.employee')
202 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
203 context['sheet_id']=ids[0]
204 success = emp_obj.sign_out(cr, uid, emp_id, context=context)
208 'name': fields.char('Description', size=64, select=1,
209 states={'confirm':[('readonly', True)], 'done':[('readonly', True)]}),
210 'user_id': fields.many2one('res.users', 'User', required=True, select=1,
211 states={'confirm':[('readonly', True)], 'done':[('readonly', True)]}),
212 'date_from': fields.date('Date from', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
213 'date_to': fields.date('Date to', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
214 'date_current': fields.date('Current date', required=True),
215 'timesheet_ids' : one2many_mod('hr.analytic.timesheet', 'sheet_id',
216 'Timesheet lines', domain=[('date', '=', time.strftime('%Y-%m-%d'))],
217 readonly=True, states={
218 'draft': [('readonly', False)],
219 'new': [('readonly', False)]}
221 'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
222 'state' : fields.selection([('new', 'New'),('draft','Draft'),('confirm','Confirmed'),('done','Done')], 'Status', select=True, required=True, readonly=True),
223 'state_attendance' : fields.function(_state_attendance, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present'),('none','No employee defined')], string='Current Status'),
224 'total_attendance_day': fields.function(_total_day, method=True, string='Total Attendance'),
225 'total_timesheet_day': fields.function(_total_day, method=True, string='Total Timesheet'),
226 'total_difference_day': fields.function(_total_day, method=True, string='Difference'),
227 'total_attendance': fields.function(_total, method=True, string='Total Attendance'),
228 'total_timesheet': fields.function(_total, method=True, string='Total Timesheet'),
229 'total_difference': fields.function(_total, method=True, string='Difference'),
230 'period_ids': fields.one2many('hr_timesheet_sheet.sheet.day', 'sheet_id', 'Period', readonly=True),
231 'account_ids': fields.one2many('hr_timesheet_sheet.sheet.account', 'sheet_id', 'Analytic accounts', readonly=True),
234 def _default_date_from(self,cr, uid, context={}):
235 user = self.pool.get('res.users').browse(cr, uid, uid, context)
236 r = user.company_id and user.company_id.timesheet_range or 'month'
238 return time.strftime('%Y-%m-01')
240 return (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
242 return time.strftime('%Y-01-01')
243 return time.strftime('%Y-%m-%d')
245 def _default_date_to(self,cr, uid, context={}):
246 user = self.pool.get('res.users').browse(cr, uid, uid, context)
247 r = user.company_id and user.company_id.timesheet_range or 'month'
249 return (DateTime.now() + DateTime.RelativeDateTime(months=+1,day=1,days=-1)).strftime('%Y-%m-%d')
251 return (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
253 return time.strftime('%Y-12-31')
254 return time.strftime('%Y-%m-%d')
257 'user_id': lambda self,cr,uid,c: uid,
258 'date_from' : _default_date_from,
259 'date_current' : lambda *a: time.strftime('%Y-%m-%d'),
260 'date_to' : _default_date_to,
261 'state': lambda *a: 'new',
264 def _sheet_date(self, cr, uid, ids):
265 for sheet in self.browse(cr, uid, ids):
266 cr.execute('SELECT id \
267 FROM hr_timesheet_sheet_sheet \
268 WHERE (date_from < %s and %s < date_to) \
270 AND id <> %s', (sheet.date_to, sheet.date_from,
271 sheet.user_id.id, sheet.id))
276 def _date_current_check(self, cr, uid, ids):
277 for sheet in self.browse(cr, uid, ids):
278 if sheet.date_current < sheet.date_from or sheet.date_current > sheet.date_to:
284 (_sheet_date, 'You can not have 2 timesheets that overlaps !\nPlease use the menu \'My Current Timesheet\' to avoid this problem.', ['date_from','date_to']),
285 (_date_current_check, 'You must select a Current date wich is in the timesheet dates !', ['date_current']),
288 def action_set_to_draft(self, cr, uid, ids, *args):
289 self.write(cr, uid, ids, {'state': 'draft'})
290 wf_service = netsvc.LocalService('workflow')
292 wf_service.trg_create(uid, self._name, id, cr)
295 def name_get(self, cr, uid, ids, context={}):
298 return [(r['id'], r['date_from'] + ' - ' + r['date_to']) \
299 for r in self.read(cr, uid, ids, ['date_from', 'date_to'],
300 context, load='_classic_write')]
302 def unlink(self, cr, uid, ids, context=None):
303 sheets = self.read(cr, uid, ids, ['state','total_attendance'])
305 if sheet['state'] in ('confirm', 'done'):
306 raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which are already confirmed !'))
307 elif sheet['total_attendance'] <> 0.00:
308 raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which have attendance entries encoded !'))
309 return super(hr_timesheet_sheet, self).unlink(cr, uid, ids, context=context)
314 class hr_timesheet_line(osv.osv):
315 _inherit = "hr.analytic.timesheet"
317 def _get_default_date(self, cr, uid, context={}):
318 if 'date' in context:
319 return context['date']
320 return time.strftime('%Y-%m-%d')
322 def _sheet(self, cursor, user, ids, name, args, context):
323 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
325 cursor.execute('SELECT l.id, COALESCE(MAX(s.id), 0) \
326 FROM hr_timesheet_sheet_sheet s \
327 LEFT JOIN (hr_analytic_timesheet l \
328 LEFT JOIN account_analytic_line al \
329 ON (l.line_id = al.id)) \
330 ON (s.date_to >= al.date \
331 AND s.date_from <= al.date \
332 AND s.user_id = al.user_id) \
333 WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \
335 res = dict(cursor.fetchall())
337 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
339 sheet_names[sheet_id] = name
341 for line_id in {}.fromkeys(ids):
342 sheet_id = res.get(line_id, False)
344 res[line_id] = (sheet_id, sheet_names[sheet_id])
349 def _sheet_search(self, cursor, user, obj, name, args):
352 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
356 fargs = args[i][0].split('.', 1)
358 args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user,
359 [(fargs[1], args[i][1], args[i][2])]))
362 if isinstance(args[i][2], basestring):
363 res_ids = sheet_obj.name_search(cursor, user, args[i][2], [],
365 args[i] = (args[i][0], 'in', [x[0] for x in res_ids])
370 if (x[2] is False) and (x[1] == '='):
371 qu1.append('(s.id IS NULL)')
372 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
373 qu1.append('(s.id IS NOT NULL)')
375 qu1.append('(s.id %s %s)' % (x[1], '%s'))
379 qu1.append('(s.id in (%s))' % (','.join(['%d'] * len(x[2]))))
382 qu1.append('(False)')
384 qu1 = ' WHERE ' + ' AND '.join(qu1)
387 cursor.execute('SELECT l.id \
388 FROM hr_timesheet_sheet_sheet s \
389 LEFT JOIN (hr_analytic_timesheet l \
390 LEFT JOIN account_analytic_line al \
391 ON (l.line_id = al.id)) \
392 ON (s.date_to >= al.date \
393 AND s.date_from <= al.date \
394 AND s.user_id = al.user_id)' + \
396 res = cursor.fetchall()
398 return [('id', '=', '0')]
399 return [('id', 'in', [x[0] for x in res])]
402 'sheet_id': fields.function(_sheet, method=True, string='Sheet',
403 type='many2one', relation='hr_timesheet_sheet.sheet',
404 fnct_search=_sheet_search),
407 'date': _get_default_date,
410 def create(self, cr, uid, vals, *args, **kwargs):
411 if vals.get('sheet_id', False):
412 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, vals['sheet_id'])
413 if not ts.state in ('draft', 'new'):
414 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
415 return super(hr_timesheet_line,self).create(cr, uid, vals, *args, **kwargs)
417 def unlink(self, cr, uid, ids, *args, **kwargs):
418 self._check(cr, uid, ids)
419 return super(hr_timesheet_line,self).unlink(cr, uid, ids,*args, **kwargs)
421 def write(self, cr, uid, ids, *args, **kwargs):
422 self._check(cr, uid, ids)
423 return super(hr_timesheet_line,self).write(cr, uid, ids,*args, **kwargs)
425 def _check(self, cr, uid, ids):
426 for att in self.browse(cr, uid, ids):
427 if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
428 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
433 class hr_attendance(osv.osv):
434 _inherit = "hr.attendance"
436 def _get_default_date(self, cr, uid, context={}):
437 if 'name' in context:
438 return context['name'] + time.strftime(' %H:%M:%S')
439 return time.strftime('%Y-%m-%d %H:%M:%S')
441 def _sheet(self, cursor, user, ids, name, args, context):
442 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
443 cursor.execute("SELECT a.id, COALESCE(MAX(s.id), 0) \
444 FROM hr_timesheet_sheet_sheet s \
445 LEFT JOIN (hr_attendance a \
446 LEFT JOIN hr_employee e \
447 ON (a.employee_id = e.id)) \
448 ON (s.date_to >= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
449 AND s.date_from <= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
450 AND s.user_id = e.user_id) \
451 WHERE a.id in (" + ",".join([str(x) for x in ids]) + ") \
453 res = dict(cursor.fetchall())
455 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
457 sheet_names[sheet_id] = name
458 for line_id in {}.fromkeys(ids):
459 sheet_id = res.get(line_id, False)
461 res[line_id] = (sheet_id, sheet_names[sheet_id])
466 def _sheet_search(self, cursor, user, obj, name, args):
469 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
473 fargs = args[i][0].split('.', 1)
475 args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user,
476 [(fargs[1], args[i][1], args[i][2])]))
479 if isinstance(args[i][2], basestring):
480 res_ids = sheet_obj.name_search(cursor, user, args[i][2], [],
482 args[i] = (args[i][0], 'in', [x[0] for x in res_ids])
487 if (x[2] is False) and (x[1] == '='):
488 qu1.append('(s.id IS NULL)')
489 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
490 qu1.append('(s.id IS NOT NULL)')
492 qu1.append('(s.id %s %s)' % (x[1], '%s'))
496 qu1.append('(s.id in (%s))' % (','.join(['%d'] * len(x[2]))))
499 qu1.append('(False)')
501 qu1 = ' WHERE ' + ' AND '.join(qu1)
504 cursor.execute('SELECT a.id\
505 FROM hr_timesheet_sheet_sheet s \
506 LEFT JOIN (hr_attendance a \
507 LEFT JOIN hr_employee e \
508 ON (a.employee_id = e.id)) \
509 ON (s.date_to >= a.name::date \
510 AND s.date_from <= a.name::date \
511 AND s.user_id = e.user_id) ' + \
513 res = cursor.fetchall()
515 return [('id', '=', '0')]
516 return [('id', 'in', [x[0] for x in res])]
519 'sheet_id': fields.function(_sheet, method=True, string='Sheet',
520 type='many2one', relation='hr_timesheet_sheet.sheet',
521 fnct_search=_sheet_search),
524 'name': _get_default_date,
527 def create(self, cr, uid, vals, context={}):
528 if 'sheet_id' in context:
529 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'])
530 if ts.state not in ('draft', 'new'):
531 raise osv.except_osv(_('Error !'), _('You cannot modify an entry in a confirmed timesheet !'))
532 res = super(hr_attendance,self).create(cr, uid, vals, context=context)
533 if 'sheet_id' in context:
534 if context['sheet_id'] != self.browse(cr, uid, res, context=context).sheet_id.id:
535 raise osv.except_osv(_('UserError'), _('You cannot enter an attendance ' \
536 'date outside the current timesheet dates!'))
539 def unlink(self, cr, uid, ids, *args, **kwargs):
540 self._check(cr, uid, ids)
541 return super(hr_attendance,self).unlink(cr, uid, ids,*args, **kwargs)
543 def write(self, cr, uid, ids, vals, context={}):
544 self._check(cr, uid, ids)
545 res = super(hr_attendance,self).write(cr, uid, ids, vals, context=context)
546 if 'sheet_id' in context:
547 for attendance in self.browse(cr, uid, ids, context=context):
548 if context['sheet_id'] != attendance.sheet_id.id:
549 raise osv.except_osv(_('UserError'), _('You cannot enter an attendance ' \
550 'date outside the current timesheet dates!'))
553 def _check(self, cr, uid, ids):
554 for att in self.browse(cr, uid, ids):
555 if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
556 raise osv.except_osv(_('Error !'), _('You cannot modify an entry in a confirmed timesheet !'))
561 class hr_timesheet_sheet_sheet_day(osv.osv):
562 _name = "hr_timesheet_sheet.sheet.day"
563 _description = "Timesheets by period"
567 'name': fields.date('Date', readonly=True),
568 'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', readonly=True, select="1"),
569 'total_timesheet': fields.float('Project Timesheet', readonly=True),
570 'total_attendance': fields.float('Attendance', readonly=True),
571 'total_difference': fields.float('Difference', readonly=True),
575 cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as
582 cast(round(cast(total_attendance - total_timesheet as Numeric),2) as Double Precision) AS total_difference
589 SUM(total_timesheet) as total_timesheet,
590 CASE WHEN SUM(total_attendance) < 0
591 THEN (SUM(total_attendance) +
592 CASE WHEN current_date <> name
594 ELSE (EXTRACT(hour FROM current_time) * 60) + EXTRACT(minute FROM current_time)
597 ELSE SUM(total_attendance)
598 END /60 as total_attendance
603 l.date::date as name,
605 sum(l.unit_amount) as total_timesheet,
606 0.0 as total_attendance
608 hr_analytic_timesheet hrt
609 left join (account_analytic_line l
610 LEFT JOIN hr_timesheet_sheet_sheet s
611 ON (s.date_to >= l.date
612 AND s.date_from <= l.date
613 AND s.user_id = l.user_id))
614 on (l.id = hrt.line_id)
615 group by l.date::date, s.id
619 a.name::date as name,
621 0.0 as total_timesheet,
622 SUM(((EXTRACT(hour FROM a.name) * 60) + EXTRACT(minute FROM a.name)) * (CASE WHEN a.action = 'sign_in' THEN -1 ELSE 1 END)) as total_attendance
625 LEFT JOIN (hr_timesheet_sheet_sheet s
626 LEFT JOIN hr_employee e
627 ON (s.user_id = e.user_id))
628 ON (a.employee_id = e.id
629 AND s.date_to >= a.name::date
630 AND s.date_from <= a.name::date)
631 WHERE action in ('sign_in', 'sign_out')
632 group by a.name::date, s.id
634 GROUP BY name, sheet_id
637 hr_timesheet_sheet_sheet_day()
640 class hr_timesheet_sheet_sheet_account(osv.osv):
641 _name = "hr_timesheet_sheet.sheet.account"
642 _description = "Timesheets by period"
646 'name': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
647 'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', readonly=True),
648 'total': fields.float('Total Time', digits=(16,2), readonly=True),
649 'invoice_rate': fields.many2one('hr_timesheet_invoice.factor', 'Invoice rate', readonly=True),
653 cr.execute("""create or replace view hr_timesheet_sheet_sheet_account as (
656 l.account_id as name,
658 sum(l.unit_amount) as total,
659 l.to_invoice as invoice_rate
661 hr_analytic_timesheet hrt
662 left join (account_analytic_line l
663 LEFT JOIN hr_timesheet_sheet_sheet s
664 ON (s.date_to >= l.date
665 AND s.date_from <= l.date
666 AND s.user_id = l.user_id))
667 on (l.id = hrt.line_id)
668 group by l.account_id, s.id, l.to_invoice
671 hr_timesheet_sheet_sheet_account()
675 class res_company(osv.osv):
676 _inherit = 'res.company'
678 'timesheet_range': fields.selection(
679 [('day','Day'),('week','Week'),('month','Month'),('year','Year')], 'Timeshet range'),
680 'timesheet_max_difference': fields.float('Timesheet allowed difference',
681 help="Allowed difference between the sign in/out and the timesheet " \
682 "computation for one sheet. Set this to 0 if you do not want any control."),
685 'timesheet_range': lambda *args: 'month',
686 'timesheet_max_difference': lambda *args: 0.0
691 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: