1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
32 from osv import fields
36 from mx import DateTime
37 from tools.translate import _
40 class one2many_mod2(fields.one2many):
41 def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
46 res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context)
49 res6[r['id']] = (r['date_current'], r['user_id'][0])
55 dom = [('name', '>=', res6[id][0] + ' 00:00:00'),
56 ('name', '<=', res6[id][0] + ' 23:59:59'),
57 ('employee_id.user_id', '=', res6[id][1])]
58 ids2.extend(obj.pool.get(self._obj).search(cr, user,
59 dom, limit=self._limit))
61 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2,
62 [self._fields_id], context=context, load='_classic_write'):
63 if r[self._fields_id]:
64 res.setdefault(r[self._fields_id][0], []).append(r['id'])
68 def set(self, cr, obj, id, field, values, user=None, context=None):
71 context = context.copy()
72 context['sheet_id'] = id
73 return super(one2many_mod2, self).set(cr, obj, id, field, values, user=user,
77 class one2many_mod(fields.one2many):
78 def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
83 res5 = obj.read(cr, user, ids, ['date_current', 'user_id'], context)
86 res6[r['id']] = (r['date_current'], r['user_id'][0])
92 dom = [('date', '=', res6[id][0]), ('user_id', '=', res6[id][1])]
93 ids2.extend(obj.pool.get(self._obj).search(cr, user,
94 dom, limit=self._limit))
96 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2,
97 [self._fields_id], context=context, load='_classic_write'):
98 if r[self._fields_id]:
99 res.setdefault(r[self._fields_id][0], []).append(r['id'])
103 class hr_timesheet_sheet(osv.osv):
104 _name = "hr_timesheet_sheet.sheet"
105 _table = 'hr_timesheet_sheet_sheet'
108 def _total_day(self, cr, uid, ids, name, args, context):
109 field_name = name.strip('_day')
110 cr.execute('SELECT sheet.id, day.' + field_name +' \
111 FROM hr_timesheet_sheet_sheet AS sheet \
112 LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
113 ON (sheet.id = day.sheet_id \
114 AND day.name = sheet.date_current) \
115 WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')')
116 return dict(cr.fetchall())
118 def _total(self, cr, uid, ids, name, args, context):
119 cr.execute('SELECT s.id, COALESCE(SUM(d.' + name + '),0) \
120 FROM hr_timesheet_sheet_sheet s \
121 LEFT JOIN hr_timesheet_sheet_sheet_day d \
122 ON (s.id = d.sheet_id) \
123 WHERE s.id in ('+ ','.join(map(str, ids)) + ') \
125 return dict(cr.fetchall())
127 def _state_attendance(self, cr, uid, ids, name, args, context):
131 emp_obj = self.pool.get('hr.employee')
133 for sheet in self.browse(cr, uid, ids, context):
134 result[sheet.id] = 'none'
135 emp_ids2 = emp_obj.search(cr, uid,
136 [('user_id', '=', sheet.user_id.id)])
138 link_emp[emp_ids2[0]] = sheet.id
139 emp_ids.append(emp_ids2[0])
140 for emp in emp_obj.browse(cr, uid, emp_ids, context=context):
141 if emp.id in link_emp:
142 sheet_id = link_emp[emp.id]
143 result[sheet_id] = emp.state
146 def button_confirm(self, cr, uid, ids, context):
147 for sheet in self.browse(cr, uid, ids, context):
148 di = sheet.user_id.company_id.timesheet_max_difference
149 if (abs(sheet.total_difference) < di) or not di:
150 wf_service = netsvc.LocalService("workflow")
151 wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'confirm', cr)
153 raise osv.except_osv(_('Warning !'), _('Please verify that the total difference of the sheet is lower than %.2f !') %(di,))
156 def date_today(self, cr, uid, ids, context):
157 for sheet in self.browse(cr, uid, ids, context):
158 if DateTime.now() <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
159 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
160 elif DateTime.now() >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
161 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
163 self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')})
166 def date_previous(self, cr, uid, ids, context):
167 for sheet in self.browse(cr, uid, ids, context):
168 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
169 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
171 self.write(cr, uid, [sheet.id], {
172 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=-1)).strftime('%Y-%m-%d'),
176 def date_next(self, cr, uid, ids, context):
177 for sheet in self.browse(cr, uid, ids, context):
178 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
179 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
181 self.write(cr, uid, [sheet.id], {
182 'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d'),
186 def button_dummy(self, cr, uid, ids, context):
187 for sheet in self.browse(cr, uid, ids, context):
188 if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
189 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
190 elif DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
191 self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
194 def sign_in(self, cr, uid, ids, context):
195 if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'):
196 raise osv.except_osv(_('Error !'), _('You can not sign in from an other date than today'))
197 emp_obj = self.pool.get('hr.employee')
198 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
199 context['sheet_id']=ids[0]
200 success = emp_obj.sign_in(cr, uid, emp_id, context=context)
203 def sign_out(self, cr, uid, ids, context):
204 if not self.browse(cr, uid, ids, context)[0].date_current == time.strftime('%Y-%m-%d'):
205 raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today'))
206 emp_obj = self.pool.get('hr.employee')
207 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
208 context['sheet_id']=ids[0]
209 success = emp_obj.sign_out(cr, uid, emp_id, context=context)
213 'name': fields.char('Description', size=64, select=1),
214 'user_id': fields.many2one('res.users', 'User', required=True, select=1),
215 'date_from': fields.date('Date from', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
216 'date_to': fields.date('Date to', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
217 'date_current': fields.date('Current date', required=True),
218 'timesheet_ids' : one2many_mod('hr.analytic.timesheet', 'sheet_id',
219 'Timesheet lines', domain=[('date', '=', time.strftime('%Y-%m-%d'))],
220 readonly=True, states={
221 'draft': [('readonly', False)],
222 'new': [('readonly', False)]}
224 'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
225 'state' : fields.selection([('new', 'New'),('draft','Draft'),('confirm','Confirmed'),('done','Done')], 'Status', select=True, required=True, readonly=True),
226 'state_attendance' : fields.function(_state_attendance, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present'),('none','No employee defined')], string='Current Status'),
227 'total_attendance_day': fields.function(_total_day, method=True, string='Total Attendance'),
228 'total_timesheet_day': fields.function(_total_day, method=True, string='Total Timesheet'),
229 'total_difference_day': fields.function(_total_day, method=True, string='Difference'),
230 'total_attendance': fields.function(_total, method=True, string='Total Attendance'),
231 'total_timesheet': fields.function(_total, method=True, string='Total Timesheet'),
232 'total_difference': fields.function(_total, method=True, string='Difference'),
233 'period_ids': fields.one2many('hr_timesheet_sheet.sheet.day', 'sheet_id', 'Period', readonly=True),
234 'account_ids': fields.one2many('hr_timesheet_sheet.sheet.account', 'sheet_id', 'Analytic accounts', readonly=True),
237 def _default_date_from(self,cr, uid, context={}):
238 user = self.pool.get('res.users').browse(cr, uid, uid, context)
239 r = user.company_id and user.company_id.timesheet_range or 'month'
241 return time.strftime('%Y-%m-01')
243 return (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Monday,0))).strftime('%Y-%m-%d')
245 return time.strftime('%Y-01-01')
246 return time.strftime('%Y-%m-%d')
248 def _default_date_to(self,cr, uid, context={}):
249 user = self.pool.get('res.users').browse(cr, uid, uid, context)
250 r = user.company_id and user.company_id.timesheet_range or 'month'
252 return (DateTime.now() + DateTime.RelativeDateTime(months=+1,day=1,days=-1)).strftime('%Y-%m-%d')
254 return (DateTime.now() + DateTime.RelativeDateTime(weekday=(DateTime.Sunday,0))).strftime('%Y-%m-%d')
256 return time.strftime('%Y-12-31')
257 return time.strftime('%Y-%m-%d')
260 'user_id': lambda self,cr,uid,c: uid,
261 'date_from' : _default_date_from,
262 'date_current' : lambda *a: time.strftime('%Y-%m-%d'),
263 'date_to' : _default_date_to,
264 'state': lambda *a: 'new',
267 def _sheet_date(self, cr, uid, ids):
268 for sheet in self.browse(cr, uid, ids):
269 cr.execute('SELECT id \
270 FROM hr_timesheet_sheet_sheet \
271 WHERE (date_from < %s and %s < date_to) \
273 AND id <> %d', (sheet.date_to, sheet.date_from,
274 sheet.user_id.id, sheet.id))
279 def _date_current_check(self, cr, uid, ids):
280 for sheet in self.browse(cr, uid, ids):
281 if sheet.date_current < sheet.date_from or sheet.date_current > sheet.date_to:
287 (_sheet_date, 'You can not have 2 timesheets that overlaps !', ['date_from','date_to']),
288 (_date_current_check, 'You must select a Current date wich is in the timesheet dates !', ['date_current']),
291 def action_set_to_draft(self, cr, uid, ids, *args):
292 self.write(cr, uid, ids, {'state': 'draft'})
293 wf_service = netsvc.LocalService('workflow')
295 wf_service.trg_create(uid, self._name, id, cr)
298 def name_get(self, cr, uid, ids, context={}):
301 return [(r['id'], r['date_from'] + ' - ' + r['date_to']) \
302 for r in self.read(cr, uid, ids, ['date_from', 'date_to'],
303 context, load='_classic_write')]
308 class hr_timesheet_line(osv.osv):
309 _inherit = "hr.analytic.timesheet"
311 def _get_default_date(self, cr, uid, context={}):
312 if 'date' in context:
313 return context['date']
314 return time.strftime('%Y-%m-%d')
316 def _sheet(self, cursor, user, ids, name, args, context):
317 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
319 cursor.execute('SELECT l.id, COALESCE(MAX(s.id), 0) \
320 FROM hr_timesheet_sheet_sheet s \
321 LEFT JOIN (hr_analytic_timesheet l \
322 LEFT JOIN account_analytic_line al \
323 ON (l.line_id = al.id)) \
324 ON (s.date_to >= al.date \
325 AND s.date_from <= al.date \
326 AND s.user_id = al.user_id) \
327 WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \
329 res = dict(cursor.fetchall())
331 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
333 sheet_names[sheet_id] = name
335 for line_id in {}.fromkeys(ids):
336 sheet_id = res.get(line_id, False)
338 res[line_id] = (sheet_id, sheet_names[sheet_id])
343 def _sheet_search(self, cursor, user, obj, name, args):
346 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
350 fargs = args[i][0].split('.', 1)
352 args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user,
353 [(fargs[1], args[i][1], args[i][2])]))
356 if isinstance(args[i][2], basestring):
357 res_ids = sheet_obj.name_search(cursor, user, args[i][2], [],
359 args[i] = (args[i][0], 'in', [x[0] for x in res_ids])
364 if (x[2] is False) and (x[1] == '='):
365 qu1.append('(s.id IS NULL)')
366 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
367 qu1.append('(s.id IS NOT NULL)')
369 qu1.append('(s.id %s %s)' % (x[1], '%d'))
373 qu1.append('(s.id in (%s))' % (','.join(['%d'] * len(x[2]))))
376 qu1.append('(False)')
378 qu1 = ' WHERE ' + ' AND '.join(qu1)
381 cursor.execute('SELECT l.id \
382 FROM hr_timesheet_sheet_sheet s \
383 LEFT JOIN (hr_analytic_timesheet l \
384 LEFT JOIN account_analytic_line al \
385 ON (l.line_id = al.id)) \
386 ON (s.date_to >= al.date \
387 AND s.date_from <= al.date \
388 AND s.user_id = al.user_id)' + \
390 res = cursor.fetchall()
392 return [('id', '=', '0')]
393 return [('id', 'in', [x[0] for x in res])]
396 'sheet_id': fields.function(_sheet, method=True, string='Sheet',
397 type='many2one', relation='hr_timesheet_sheet.sheet',
398 fnct_search=_sheet_search),
401 'date': _get_default_date,
404 def create(self, cr, uid, vals, *args, **kwargs):
405 if 'sheet_id' in vals:
406 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, vals['sheet_id'])
407 if not ts.state in ('draft', 'new'):
408 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
409 return super(hr_timesheet_line,self).create(cr, uid, vals, *args, **kwargs)
411 def unlink(self, cr, uid, ids, *args, **kwargs):
412 self._check(cr, uid, ids)
413 return super(hr_timesheet_line,self).unlink(cr, uid, ids,*args, **kwargs)
415 def write(self, cr, uid, ids, *args, **kwargs):
416 self._check(cr, uid, ids)
417 return super(hr_timesheet_line,self).write(cr, uid, ids,*args, **kwargs)
419 def _check(self, cr, uid, ids):
420 for att in self.browse(cr, uid, ids):
421 if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
422 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
427 class hr_attendance(osv.osv):
428 _inherit = "hr.attendance"
430 def _get_default_date(self, cr, uid, context={}):
431 if 'name' in context:
432 return context['name'] + time.strftime(' %H:%M:%S')
433 return time.strftime('%Y-%m-%d %H:%M:%S')
435 def _sheet(self, cursor, user, ids, name, args, context):
436 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
438 cursor.execute('SELECT a.id, COALESCE(MAX(s.id), 0) \
439 FROM hr_timesheet_sheet_sheet s \
440 LEFT JOIN (hr_attendance a \
441 LEFT JOIN hr_employee e \
442 ON (a.employee_id = e.id)) \
443 ON (s.date_to >= a.name \
444 AND s.date_from <= a.name \
445 AND s.user_id = e.user_id) \
446 WHERE a.id in (' + ','.join([str(x) for x in ids]) + ') \
448 res = dict(cursor.fetchall())
450 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
452 sheet_names[sheet_id] = name
454 for line_id in {}.fromkeys(ids):
455 sheet_id = res.get(line_id, False)
457 res[line_id] = (sheet_id, sheet_names[sheet_id])
462 def _sheet_search(self, cursor, user, obj, name, args):
465 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
469 fargs = args[i][0].split('.', 1)
471 args[i] = (fargs[0], 'in', sheet_obj.search(cursor, user,
472 [(fargs[1], args[i][1], args[i][2])]))
475 if isinstance(args[i][2], basestring):
476 res_ids = sheet_obj.name_search(cursor, user, args[i][2], [],
478 args[i] = (args[i][0], 'in', [x[0] for x in res_ids])
483 if (x[2] is False) and (x[1] == '='):
484 qu1.append('(s.id IS NULL)')
485 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
486 qu1.append('(s.id IS NOT NULL)')
488 qu1.append('(s.id %s %s)' % (x[1], '%d'))
492 qu1.append('(s.id in (%s))' % (','.join(['%d'] * len(x[2]))))
495 qu1.append('(False)')
497 qu1 = ' WHERE ' + ' AND '.join(qu1)
500 cursor.execute('SELECT a.id\
501 FROM hr_timesheet_sheet_sheet s \
502 LEFT JOIN (hr_attendance a \
503 LEFT JOIN hr_employee e \
504 ON (a.employee_id = e.id)) \
505 ON (s.date_to >= a.name \
506 AND s.date_from <= a.name \
507 AND s.user_id = e.user_id) ' + \
509 res = cursor.fetchall()
511 return [('id', '=', '0')]
512 return [('id', 'in', [x[0] for x in res])]
515 'sheet_id': fields.function(_sheet, method=True, string='Sheet',
516 type='many2one', relation='hr_timesheet_sheet.sheet',
517 fnct_search=_sheet_search),
520 'name': _get_default_date,
523 def create(self, cr, uid, vals, context={}):
524 if 'sheet_id' in context:
525 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'])
526 if ts.state not in ('draft', 'new'):
527 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
528 res = super(hr_attendance,self).create(cr, uid, vals, context=context)
529 if 'sheet_id' in context:
530 if context['sheet_id'] != self.browse(cr, uid, res, context=context).sheet_id.id:
531 raise osv.except_osv(_('UserError'), _('You can not enter an attendance ' \
532 'date outside the current timesheet dates!'))
535 def unlink(self, cr, uid, ids, *args, **kwargs):
536 self._check(cr, uid, ids)
537 return super(hr_attendance,self).unlink(cr, uid, ids,*args, **kwargs)
539 def write(self, cr, uid, ids, vals, context={}):
540 self._check(cr, uid, ids)
541 res = super(hr_attendance,self).write(cr, uid, ids, vals, context=context)
542 if 'sheet_id' in context:
543 for attendance in self.browse(cr, uid, ids, context=context):
544 if context['sheet_id'] != attendance.sheet_id.id:
545 raise osv.except_osv(_('UserError'), _('You can not enter an attendance ' \
546 'date outside the current timesheet dates!'))
549 def _check(self, cr, uid, ids):
550 for att in self.browse(cr, uid, ids):
551 if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
552 raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
557 class hr_timesheet_sheet_sheet_day(osv.osv):
558 _name = "hr_timesheet_sheet.sheet.day"
559 _description = "Timesheets by period"
563 'name': fields.date('Date', readonly=True),
564 'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', readonly=True, select="1"),
565 'total_timesheet': fields.float('Project Timesheet', readonly=True),
566 'total_attendance': fields.float('Attendance', readonly=True),
567 'total_difference': fields.float('Difference', readonly=True),
571 cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as
578 (total_attendance - total_timesheet) AS total_difference
585 SUM(total_timesheet) as total_timesheet,
586 CASE WHEN SUM(total_attendance) < 0
587 THEN (SUM(total_attendance) +
588 CASE WHEN current_date <> name
590 ELSE (EXTRACT(hour FROM current_time) * 60) + EXTRACT(minute FROM current_time)
593 ELSE SUM(total_attendance)
594 END /60 as total_attendance
599 l.date::date as name,
601 sum(l.unit_amount) as total_timesheet,
602 0.0 as total_attendance
604 hr_analytic_timesheet hrt
605 left join (account_analytic_line l
606 LEFT JOIN hr_timesheet_sheet_sheet s
607 ON (s.date_to >= l.date
608 AND s.date_from <= l.date
609 AND s.user_id = l.user_id))
610 on (l.id = hrt.line_id)
611 group by l.date::date, s.id
615 a.name::date as name,
617 0.0 as total_timesheet,
618 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
621 LEFT JOIN (hr_timesheet_sheet_sheet s
622 LEFT JOIN hr_employee e
623 ON (s.user_id = e.user_id))
624 ON (a.employee_id = e.id
625 AND s.date_to >= a.name
626 AND s.date_from <= a.name)
627 WHERE action in ('sign_in', 'sign_out')
628 group by a.name::date, s.id
630 GROUP BY name, sheet_id
633 hr_timesheet_sheet_sheet_day()
636 class hr_timesheet_sheet_sheet_account(osv.osv):
637 _name = "hr_timesheet_sheet.sheet.account"
638 _description = "Timesheets by period"
642 'name': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
643 'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', readonly=True),
644 'total': fields.float('Total Time', digits=(16,2), readonly=True),
645 'invoice_rate': fields.many2one('hr_timesheet_invoice.factor', 'Invoice rate', readonly=True),
649 cr.execute("""create or replace view hr_timesheet_sheet_sheet_account as (
652 l.account_id as name,
654 sum(l.unit_amount) as total,
655 l.to_invoice as invoice_rate
657 hr_analytic_timesheet hrt
658 left join (account_analytic_line l
659 LEFT JOIN hr_timesheet_sheet_sheet s
660 ON (s.date_to >= l.date
661 AND s.date_from <= l.date
662 AND s.user_id = l.user_id))
663 on (l.id = hrt.line_id)
664 group by l.account_id, s.id, l.to_invoice
667 hr_timesheet_sheet_sheet_account()
671 class res_company(osv.osv):
672 _inherit = 'res.company'
674 'timesheet_range': fields.selection(
675 [('day','Day'),('week','Week'),('month','Month'),('year','Year')], 'Timeshet range',
677 'timesheet_max_difference': fields.float('Timesheet allowed difference',
678 help="Allowed difference between the sign in/out and the timesheet " \
679 "computation for one sheet. Set this to 0 if you do not want any control."),
682 'timesheet_range': lambda *args: 'month',
683 'timesheet_max_difference': lambda *args: 0.0
688 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: